Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2016-01-20 09:33:37 +0000
committerAlexander Kurtakov2016-01-20 09:33:37 +0000
commitb547e21f83e9f04b505610dc82daa2c8fba54f02 (patch)
tree0daa7a3546da408147a4587c8a3c8ce68c88f242 /org.eclipse.ua.tests
parentde8dbf0d20b614778383733388ea8623b5259064 (diff)
downloadeclipse.platform.ua-b547e21f83e9f04b505610dc82daa2c8fba54f02.tar.gz
eclipse.platform.ua-b547e21f83e9f04b505610dc82daa2c8fba54f02.tar.xz
eclipse.platform.ua-b547e21f83e9f04b505610dc82daa2c8fba54f02.zip
Bug 485918 - Convert org.eclipse.ua.tests to JUnit 4
Migrate remaining tests in cheatsheet source folder. Change-Id: Ie3978323739823e1749bdada78ae70a8b16bf7b9 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'org.eclipse.ua.tests')
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestActionExecution.java56
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java76
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java33
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCategories.java37
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCollection.java32
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java36
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestEscape.java19
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestStatePersistence.java40
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/InvalidCheatsheet.java73
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/NoError.java34
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ParseFromString.java32
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java19
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java24
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/util/CheatSheetModelSerializerTest.java17
14 files changed, 337 insertions, 191 deletions
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestActionExecution.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestActionExecution.java
index 7a50bf735..c5f8a59f5 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestActionExecution.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestActionExecution.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 IBM Corporation and others.
+ * Copyright (c) 2005, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,35 +11,41 @@
package org.eclipse.ua.tests.cheatsheet.execution;
-/**
- * Tests which exercise the ActionRunner class
- */
-
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.eclipse.ui.internal.cheatsheets.ActionRunner;
import org.eclipse.ui.internal.cheatsheets.data.Action;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestActionExecution {
-public class TestActionExecution extends TestCase {
-
- private static final String ACTION_PACKAGE =
+ private static final String ACTION_PACKAGE =
"org.eclipse.ua.tests.cheatsheet.execution"; //$NON-NLS-1$
- private static final String SIMPLE_ACTION_CLASS =
+ private static final String SIMPLE_ACTION_CLASS =
ACTION_PACKAGE + ".SimpleAction"; //$NON-NLS-1$
private static final String FAILING_ACTION_CLASS =
ACTION_PACKAGE + ".FailingAction"; //$NON-NLS-1$
private static final String ACTION_WITH_PARAMETERS_CLASS =
ACTION_PACKAGE + ".ActionWithParameters"; //$NON-NLS-1$
-
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
+ ActionEnvironment.reset();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
ActionEnvironment.reset();
}
-
+
+ @Test
public void testSimpleAction() {
- Action action = new Action();
+ Action action = new Action();
action.setClass(SIMPLE_ACTION_CLASS);
action.setParams(new String[0]);
action.setPluginID(getPluginId());
@@ -47,9 +53,10 @@ public class TestActionExecution extends TestCase {
assertTrue(status.isOK());
assertEquals(1, ActionEnvironment.getTimesCompleted());
}
-
+
+ @Test
public void testInvalidAction() {
- Action action = new Action();
+ Action action = new Action();
action.setClass(SIMPLE_ACTION_CLASS + "invalid"); //$NON-NLS-1$
action.setParams(new String[0]);
action.setPluginID(getPluginId());
@@ -57,9 +64,10 @@ public class TestActionExecution extends TestCase {
assertEquals(IStatus.ERROR, status.getSeverity());
assertEquals(0, ActionEnvironment.getTimesCompleted());
}
-
+
+ @Test
public void testSimpleActionWithException() {
- Action action = new Action();
+ Action action = new Action();
action.setClass(SIMPLE_ACTION_CLASS);
action.setParams(new String[0]);
action.setPluginID(getPluginId());
@@ -68,18 +76,20 @@ public class TestActionExecution extends TestCase {
assertEquals(IStatus.ERROR, status.getSeverity());
assertEquals(RuntimeException.class, status.getException().getClass());
}
-
+
+ @Test
public void testFailingAction() {
- Action action = new Action();
+ Action action = new Action();
action.setClass(FAILING_ACTION_CLASS);
action.setParams(new String[0]);
action.setPluginID(getPluginId());
IStatus status = new ActionRunner().runAction(action, null);
assertEquals(IStatus.WARNING, status.getSeverity());
}
-
+
+ @Test
public void testActionWithParameters() {
- Action action = new Action();
+ Action action = new Action();
action.setClass(ACTION_WITH_PARAMETERS_CLASS);
String value0 = "abc"; //$NON-NLS-1$
String value1 = "defg"; //$NON-NLS-1$
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java
index a65dd6f6b..0ef592973 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 IBM Corporation and others.
+ * Copyright (c) 2005, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,9 +11,14 @@
package org.eclipse.ua.tests.cheatsheet.execution;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import java.util.Map;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
@@ -31,28 +36,30 @@ import org.eclipse.ui.internal.cheatsheets.CommandRunner;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetCommand;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests which exercise the CommandRunner class
*/
-public class TestCommandExecution extends TestCase {
+public class TestCommandExecution {
private static final String PARAM2_VALUE = "bar"; //$NON-NLS-1$
private static final String PARAM1_VALUE = "foo"; //$NON-NLS-1$
-
+
private static final String PARAM1_ID = "param1_id"; //$NON-NLS-1$
private static final String PARAM2_ID = "param2_id"; //$NON-NLS-1$
- private static final String COMMAND_ID =
+ private static final String COMMAND_ID =
"org.eclipse.ui.cheatsheets.tests.command1"; //$NON-NLS-1$
- private static final String SERIALIZED_COMMAND = COMMAND_ID + '('
- + PARAM1_ID + '=' + PARAM1_VALUE + ','
- + PARAM2_ID + '=' + PARAM2_VALUE + ')';
+ private static final String SERIALIZED_COMMAND = COMMAND_ID + '('
+ + PARAM1_ID + '=' + PARAM1_VALUE + ','
+ + PARAM2_ID + '=' + PARAM2_VALUE + ')';
private static final String RETURN_STORE = "retData";
private static final String PARENT_RETURN_STORE = "parent.retData";
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
CommandHandler.reset();
}
@@ -61,7 +68,7 @@ public class TestCommandExecution extends TestCase {
element.setID("TestCommandExecutionId");
return new CheatSheetManager(element);
}
-
+
private ICommandService getService() {
IWorkbench wb =UserAssistanceTestPlugin.getDefault().getWorkbench(); //.getCommandSupport();
Object serviceObject = wb.getAdapter(ICommandService.class);
@@ -71,9 +78,9 @@ public class TestCommandExecution extends TestCase {
}
return null;
}
-
+
private IHandlerService getHandlerService() {
- IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbench wb = PlatformUI.getWorkbench();
if (wb != null) {
Object serviceObject = wb.getAdapter(IHandlerService.class);
if (serviceObject != null) {
@@ -83,10 +90,11 @@ public class TestCommandExecution extends TestCase {
}
return null;
}
-
+
/**
* Execute a command without using the command runner class
*/
+ @Test
public void testExecuteCommand() {
ParameterizedCommand selectedCommand;
try {
@@ -103,10 +111,10 @@ public class TestCommandExecution extends TestCase {
} catch (NotHandledException e) {
fail("Not handled exception");
}
-
+
checkCommandExecution();
}
-
+
private void checkCommandExecution() {
assertTrue(CommandHandler.getTimesCompleted() == 1);
Map<?, ?> params = CommandHandler.getParams();
@@ -116,24 +124,26 @@ public class TestCommandExecution extends TestCase {
assertTrue(params.containsKey(PARAM2_ID));
assertEquals(PARAM2_VALUE, params.get(PARAM2_ID));
}
-
+
+ @Test
public void testCommandRunner() {
CheatSheetCommand command = new CheatSheetCommand();
CheatSheetManager csm = createManager();
command.setSerialization(SERIALIZED_COMMAND);
-
+
IStatus status = new CommandRunner().executeCommand(command, csm);
assertTrue(status.isOK());
-
+
checkCommandExecution();
}
+ @Test
public void testCommandWithResult() {
CheatSheetCommand command = new CheatSheetCommand();
CheatSheetManager csm = createManager();
command.setSerialization(SERIALIZED_COMMAND);
command.setReturns(RETURN_STORE);
-
+
IStatus status = new CommandRunner().executeCommand(command, csm);
assertTrue(status.isOK());
String result = csm.getData(RETURN_STORE);
@@ -141,11 +151,12 @@ public class TestCommandExecution extends TestCase {
assertEquals(CommandHandler.RESULT_TO_STRING, result);
checkCommandExecution();
}
-
+
/**
* Test that if the return is set to parent.retData the
* return value is written to the parent cheat sheet manager.
*/
+ @Test
public void testCommandWithQualifiedResult() {
CheatSheetCommand command = new CheatSheetCommand();
CheatSheetManager csm = createManager();
@@ -153,40 +164,43 @@ public class TestCommandExecution extends TestCase {
csm.setParent(parentManager);
command.setSerialization(SERIALIZED_COMMAND);
command.setReturns(PARENT_RETURN_STORE);
-
+
IStatus status = new CommandRunner().executeCommand(command, csm);
assertTrue(status.isOK());
assertNull(csm.getData(RETURN_STORE));
assertNotNull(parentManager.getData(RETURN_STORE));
}
-
+
+ @Test
public void testInvalidCommandId() {
CheatSheetCommand command = new CheatSheetCommand();
CheatSheetManager csm = createManager();
command.setSerialization(COMMAND_ID + ".invalid"); //$NON-NLS-1$
IStatus status = new CommandRunner().executeCommand(command, csm);
- assertFalse(status.isOK());
+ assertFalse(status.isOK());
}
-
+
+ @Test
public void testCommandException() {
CheatSheetCommand command = new CheatSheetCommand();
CheatSheetManager csm = createManager();
command.setSerialization(SERIALIZED_COMMAND);
CommandHandler.setThrowException(true);
-
+
IStatus status = new CommandRunner().executeCommand(command, csm);
- assertFalse(status.isOK());
+ assertFalse(status.isOK());
}
-
+
private static final String NEGATE_INTEGER_COMMAND_ID = "org.eclipse.ui.cheatsheets.tests.NegateIntegerCommand(number=123)";
private static final String INT_RETURN_STORE = "intData";
-
+
+ @Test
public void testCommandWithIntegerValues() {
CheatSheetCommand command = new CheatSheetCommand();
CheatSheetManager csm = createManager();
command.setSerialization(NEGATE_INTEGER_COMMAND_ID);
command.setReturns(INT_RETURN_STORE);
-
+
IStatus status = new CommandRunner().executeCommand(command, csm);
assertTrue(status.isOK());
String result = csm.getData(INT_RETURN_STORE);
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java
index 19694c96d..4a68ed665 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 IBM Corporation and others.
+ * Copyright (c) 2005, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,57 +11,66 @@
package org.eclipse.ua.tests.cheatsheet.execution;
+import static org.junit.Assert.assertEquals;
+
/**
- * Test variable substitution in cheatsheets. This functionality is used by
+ * Test variable substitution in cheatsheets. This functionality is used by
* command execution
*/
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
+import org.junit.Before;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class TestVariableSubstitution extends TestCase {
+public class TestVariableSubstitution {
private CheatSheetManager manager;
-
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
manager = new CheatSheetManager(new CheatSheetElement("name"));
manager.setData("p1", "one");
manager.setData("p2", "two");
}
-
+
private String substitute(String input) {
return manager.performVariableSubstitution(input);
}
+ @Test
public void testNoSubstitution() {
assertEquals("abcdefg", substitute("abcdefg"));
}
+ @Test
public void testFullString() {
assertEquals("one", substitute("${p1}"));
}
+ @Test
public void testEmbeddedString() {
assertEquals("AoneB", substitute("A${p1}B"));
}
+ @Test
public void testRepeatedSubstitution() {
assertEquals("oneXone", substitute("${p1}X${p1}"));
}
+ @Test
public void testMultipleSubstitution() {
assertEquals("onetwo", substitute("${p1}${p2}"));
}
-
+
+ @Test
public void testNonexistentParameter() {
assertEquals("one", substitute("${p1}${p3}"));
}
-
+
+ @Test
public void testUnterminatedParameter() {
assertEquals("${p1", "${p1");
}
-
+
}
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCategories.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCategories.java
index a69b0c91b..bf6581d3b 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCategories.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCategories.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,60 +11,67 @@
package org.eclipse.ua.tests.cheatsheet.other;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetCollectionElement;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetRegistryReader;
+import org.junit.Test;
-public class TestCheatSheetCategories extends TestCase {
+public class TestCheatSheetCategories {
private static final String TEST_CATEGORY = "org.eclipse.ua.tests.cheatsheet.cheatSheetsTestCat";
+ @Test
public void testForCollection() {
- CheatSheetCollectionElement cheatSheets =
+ CheatSheetCollectionElement cheatSheets =
CheatSheetRegistryReader.getInstance().getCheatSheets();
Object[] subCategories = cheatSheets.getChildren();
for (Object subCategorie : subCategories) {
assertTrue(subCategorie instanceof CheatSheetCollectionElement);
}
}
-
+
+ @Test
public void testFindTestCategory() {
- CheatSheetCollectionElement cheatSheets =
+ CheatSheetCollectionElement cheatSheets =
CheatSheetRegistryReader.getInstance().getCheatSheets();
CheatSheetCollectionElement testCat = findChildCategory(cheatSheets, TEST_CATEGORY);
assertNotNull("Cannot find category org.eclipse.ua.tests.cheatsheet.cheatSheetsTestCat",
testCat);
}
+ @Test
public void testFindQualifiedSubcategory() {
- CheatSheetCollectionElement cheatSheets =
+ CheatSheetCollectionElement cheatSheets =
CheatSheetRegistryReader.getInstance().getCheatSheets();
CheatSheetCollectionElement testCat = findChildCategory(cheatSheets, TEST_CATEGORY);
- CheatSheetCollectionElement subCat = findChildCategory(testCat,
+ CheatSheetCollectionElement subCat = findChildCategory(testCat,
"org.eclipse.ua.tests.subcategory");
assertNotNull(subCat);
}
+ @Test
public void testFindCsInUnqualifiedSubcategory() {
- CheatSheetCollectionElement cheatSheets =
+ CheatSheetCollectionElement cheatSheets =
CheatSheetRegistryReader.getInstance().getCheatSheets();
CheatSheetCollectionElement testCat = findChildCategory(cheatSheets, TEST_CATEGORY);
- CheatSheetCollectionElement subCat = findChildCategory(testCat,
+ CheatSheetCollectionElement subCat = findChildCategory(testCat,
"org.eclipse.ua.tests.subcategory");
- CheatSheetElement unqual = findCheatsheet(subCat,
+ CheatSheetElement unqual = findCheatsheet(subCat,
"org.eclipse.ua.tests.cheatsheet.subcategory.simple");
assertNotNull(unqual);
}
-
+
+ @Test
public void testFindCsInQualifiedSubcategory() {
- CheatSheetCollectionElement cheatSheets =
+ CheatSheetCollectionElement cheatSheets =
CheatSheetRegistryReader.getInstance().getCheatSheets();
CheatSheetCollectionElement testCat = findChildCategory(cheatSheets, TEST_CATEGORY);
- CheatSheetCollectionElement subCat = findChildCategory(testCat,
+ CheatSheetCollectionElement subCat = findChildCategory(testCat,
"org.eclipse.ua.tests.subcategory");
- CheatSheetElement qual = findCheatsheet(subCat,
+ CheatSheetElement qual = findCheatsheet(subCat,
"org.eclipse.ua.tests.cheatsheet.subcategory.qualified");
assertNotNull(qual);
}
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCollection.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCollection.java
index 661443edb..9c39a8e1c 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCollection.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetCollection.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
+ * Copyright (c) 2008, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,13 +11,18 @@
package org.eclipse.ua.tests.cheatsheet.other;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetCollectionElement;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestCheatSheetCollection {
-public class TestCheatSheetCollection extends TestCase {
-
private CheatSheetCollectionElement root;
private CheatSheetElement csA;
private CheatSheetElement csB;
@@ -27,9 +32,9 @@ public class TestCheatSheetCollection extends TestCase {
private CheatSheetCollectionElement c2;
private CheatSheetCollectionElement c11;
private CheatSheetCollectionElement c12;
-
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
root = new CheatSheetCollectionElement("rootPlugin", "rootId", "rootName", root);
csA = new CheatSheetElement("A");
csA.setID("idA");
@@ -42,7 +47,7 @@ public class TestCheatSheetCollection extends TestCase {
c1 = new CheatSheetCollectionElement("p1", "c1Id", "c1", root);
c2 = new CheatSheetCollectionElement("p2", "c2Id", "c2", root);
c11 = new CheatSheetCollectionElement("p11", "c11Id", "c11", c1);
- c12 = new CheatSheetCollectionElement("p12", "c12Id", "c12", c1);
+ c12 = new CheatSheetCollectionElement("p12", "c12Id", "c12", c1);
root.add(c1);
root.add(csA);
root.add(csB);
@@ -53,6 +58,7 @@ public class TestCheatSheetCollection extends TestCase {
c12.add(cs12A);
}
+ @Test
public void testRoot() {
assertEquals(2, root.getChildren().length);
assertEquals(2, root.getCheatSheets().length);
@@ -62,6 +68,7 @@ public class TestCheatSheetCollection extends TestCase {
assertEquals("rootPlugin", root.getPluginId());
}
+ @Test
public void testTopLevelChildCategories() {
Object[] children = root.getChildren();
assertEquals(c1, children[0]);
@@ -73,13 +80,15 @@ public class TestCheatSheetCollection extends TestCase {
assertEquals(1, c2.getCheatSheets().length);
assertFalse(c2.isEmpty());
}
-
+
+ @Test
public void testTopLevelCheatsheets() {
Object[] cheatsheets = root.getCheatSheets();
assertEquals(csA, cheatsheets[0]);
assertEquals(csB, cheatsheets[1]);
}
-
+
+ @Test
public void testSecondLevelChildCategories() {
Object[] children = c1.getChildren();
assertEquals(c11, children[0]);
@@ -91,7 +100,8 @@ public class TestCheatSheetCollection extends TestCase {
assertEquals(1, c12.getCheatSheets().length);
assertFalse(c12.isEmpty());
}
-
+
+ @Test
public void testFind() {
assertEquals(csA, root.findCheatSheet("idA", true));
assertEquals(csA, root.findCheatSheet("idA", false));
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java
index ec1d7d854..fc9c1ae1a 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2015 IBM Corporation and others.
+ * Copyright (c) 2006, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,43 +11,50 @@
package org.eclipse.ua.tests.cheatsheet.other;
-import java.util.Set;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.util.Set;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
+import org.junit.Test;
-public class TestCheatSheetManager extends TestCase {
+public class TestCheatSheetManager {
- private static final String CHEATSHEET_ID = "RandomId0234";
- private static final String CHEATSHEET_NAME = "Name";
+ private static final String CHEATSHEET_ID = "RandomId0234";
+ private static final String CHEATSHEET_NAME = "Name";
private static final String KEY1 = "key1";
private static final String PARENT_KEY1 = "parent.key1";
private static final String PARENT_KEY2 = "parent.key2";
private static final String VALUE_A = "A";
private static final String VALUE_B = "B";
private static final String VALUE_C = "C";
-
+
public CheatSheetManager createManager() {
CheatSheetElement element = new CheatSheetElement(CHEATSHEET_NAME);
element.setID(CHEATSHEET_ID);
return new CheatSheetManager(element);
}
-
+
/**
- * Test for correct initialization
+ * Test for correct initialization
*/
+ @Test
public void testNewManager() {
CheatSheetManager manager = createManager();
assertNotNull(manager.getKeySet());
assertTrue(manager.getKeySet().isEmpty());
assertEquals(CHEATSHEET_ID, manager.getCheatSheetID());
}
-
+
/**
* Test that if there is no parent all references are local.
*/
+ @Test
public void testNoParent() {
CheatSheetManager manager = createManager();
manager.setDataQualified(KEY1, VALUE_A);
@@ -61,11 +68,12 @@ public class TestCheatSheetManager extends TestCase {
assertTrue(keys.contains(KEY1));
assertTrue(keys.contains(PARENT_KEY1));
}
-
+
/**
* Test that if there is a parent getDataQualified and setDataQualified
* can reference the parent but getData is always local
*/
+ @Test
public void testParentAccess() {
CheatSheetManager manager = createManager();
CheatSheetManager parentManager = createManager();
@@ -86,10 +94,11 @@ public class TestCheatSheetManager extends TestCase {
assertTrue(parentKeys.contains(KEY1));
assertFalse(parentKeys.contains(PARENT_KEY1));
}
-
+
/**
* Test that setData always writes locally
*/
+ @Test
public void testSetDataWithParent() {
CheatSheetManager manager = createManager();
CheatSheetManager parentManager = createManager();
@@ -108,7 +117,8 @@ public class TestCheatSheetManager extends TestCase {
Set<?> parentKeys = parentManager.getKeySet();
assertEquals(parentKeys.size(), 0);
}
-
+
+ @Test
public void testSubstitution() {
CheatSheetManager manager = createManager();
CheatSheetManager parentManager = createManager();
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestEscape.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestEscape.java
index f8d1ee275..0f4de568f 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestEscape.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestEscape.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,36 +11,43 @@
package org.eclipse.ua.tests.cheatsheet.other;
-import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities;
-
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class TestEscape extends TestCase {
+import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities;
+import org.junit.Test;
+public class TestEscape {
+ @Test
public void testEscapeLabelEmpty() {
assertEquals("", ViewUtilities.escapeForLabel(""));
}
+ @Test
public void testEscapeLabelNonEmpty() {
assertEquals("abc", ViewUtilities.escapeForLabel("abc"));
}
+ @Test
public void testEscapeLabelWithAmpersand() {
assertEquals("ab&&c", ViewUtilities.escapeForLabel("ab&c"));
}
+ @Test
public void testEscapeLabelMultipleAmpersand() {
assertEquals("a&&b&&cd&&e", ViewUtilities.escapeForLabel("a&b&cd&e"));
}
+ @Test
public void testEscapeLabelRepeatedAmpersand() {
assertEquals("ab&&&&c", ViewUtilities.escapeForLabel("ab&&c"));
}
+ @Test
public void testEscapeLabelStartsWithAmpersand() {
assertEquals("&&abc", ViewUtilities.escapeForLabel("&abc"));
}
-
+
+ @Test
public void testEscapeLabelEndsWithAmpersand() {
assertEquals("abc&&", ViewUtilities.escapeForLabel("abc&"));
}
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestStatePersistence.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestStatePersistence.java
index cd71999f7..4fe36345b 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestStatePersistence.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestStatePersistence.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2015 IBM Corporation and others.
+ * Copyright (c) 2006, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,10 @@
package org.eclipse.ua.tests.cheatsheet.other;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
/**
* Tests for the saving and restoring of the state of a simple cheat sheet in a memento
*/
@@ -20,22 +24,22 @@ import java.util.Hashtable;
import java.util.List;
import java.util.Properties;
-import junit.framework.TestCase;
-
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetSaveHelper;
import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestStatePersistence {
-public class TestStatePersistence extends TestCase {
-
private static final String VALUE2 = "value2";
private static final String KEY2 = "key2";
private static final String VALUE1 = "value1";
private static final String KEY1 = "key1";
private static final String TEST_ID = "TestId";
private static final String PATH = "ContentPath";
-
+
private class PropertySet {
public String id;
public int currentItem;
@@ -48,17 +52,17 @@ public class TestStatePersistence extends TestCase {
public Hashtable<String, String> subItemSkipped;
public CheatSheetManager manager;
}
-
+
private PropertySet propsToSave;
private CheatSheetSaveHelper helper = new CheatSheetSaveHelper();
private PropertySet restored;
-
+
/*
* Initialize the properties that will be saved. Individual tests will modify
* the properties which apply to a particular test.
*/
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
propsToSave = new PropertySet();
propsToSave.button = 1;
propsToSave.currentItem = 2;
@@ -72,7 +76,7 @@ public class TestStatePersistence extends TestCase {
CheatSheetElement csElement = new CheatSheetElement(TEST_ID);
propsToSave.manager = new CheatSheetManager(csElement);
}
-
+
private void save() {
Properties propertiesToSave = new Properties();
propertiesToSave.put(IParserTags.ID, propsToSave.id);
@@ -92,7 +96,7 @@ public class TestStatePersistence extends TestCase {
}
helper.saveState(propertiesToSave, propsToSave.manager);
}
-
+
@SuppressWarnings("unchecked")
private PropertySet restore(String id) {
PropertySet result = new PropertySet();
@@ -121,19 +125,21 @@ public class TestStatePersistence extends TestCase {
* Test save and restore of id, name
*
*/
+ @Test
public void testBasicProperties() {
save();
restore();
// Check the restored properties
- assertEquals(TEST_ID, restored.id);
+ assertEquals(TEST_ID, restored.id);
assertEquals(2, restored.currentItem);
assertEquals(1, restored.button);
assertEquals(PATH, restored.contentPath);
}
-
+
/**
* Test save and restore of CheatSheetManager
*/
+ @Test
public void testCheatSheetManagerPersistence() {
propsToSave.manager.setData(KEY1, VALUE1);
propsToSave.manager.setData(KEY2, VALUE2);
@@ -142,10 +148,11 @@ public class TestStatePersistence extends TestCase {
assertEquals(VALUE1, restored.manager.getData(KEY1));
assertEquals(VALUE2, restored.manager.getData(KEY2));
}
-
+
/**
* Test save and restore of completed, expanded, expandRestore
*/
+ @Test
public void testItemPropertyPersistence() {
propsToSave.completed.add("2");
propsToSave.completed.add("5");
@@ -168,10 +175,11 @@ public class TestStatePersistence extends TestCase {
assertTrue(restored.expandRestore.contains("99"));
assertTrue(restored.expandRestore.contains("999"));
}
-
+
/**
* Test save and restore of subitem completed and skipped
*/
+ @Test
public void testSubItemPropertyPersistence() {
propsToSave.subItemCompleted.put("1", "3,5");
propsToSave.subItemCompleted.put("2", "4,6");
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/InvalidCheatsheet.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/InvalidCheatsheet.java
index eed9c05da..d55abab9f 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/InvalidCheatsheet.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/InvalidCheatsheet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2015 IBM Corporation and others.
+ * Copyright (c) 2006, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,33 +11,38 @@
package org.eclipse.ua.tests.cheatsheet.parser;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
import java.net.MalformedURLException;
import java.net.URL;
-import junit.framework.TestCase;
-
import org.eclipse.core.runtime.IStatus;
import org.eclipse.ua.tests.cheatsheet.util.StatusCheck;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.eclipse.ua.tests.util.ResourceFinder;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetParser;
import org.eclipse.ui.internal.cheatsheets.data.ICheatSheet;
+import org.junit.Before;
+import org.junit.Test;
-public class InvalidCheatsheet extends TestCase {
+public class InvalidCheatsheet {
private static final String INVALID_CHEATSHEET_FOLDER = "data/cheatsheet/invalid/";
private CheatSheetParser parser;
-
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
parser = new CheatSheetParser();
}
-
+
private ICheatSheet parseTestFile(String path) {
- URL testURL = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(),
+ URL testURL = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(),
INVALID_CHEATSHEET_FOLDER + path);
return parser.parse(testURL, UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.SIMPLE_ONLY);
}
-
+
+ @Test
public void testBadURL() {
try {
assertNull(parser.parse(new URL("file:/nonexistent"), UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.SIMPLE_ONLY));
@@ -48,6 +53,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "Could not open");
}
+ @Test
public void testActionMissingClass() {
ICheatSheet model = parseTestFile("ActionElement_MissingClass.xml");
assertNull(model);
@@ -55,13 +61,15 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a class");
}
+ @Test
public void testActionMissingPluginId() {
ICheatSheet model = parseTestFile("ActionElement_MissingPluginId.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a pluginId");
}
-
+
+ @Test
public void testCommandMissingSerialization() {
ICheatSheet model = parseTestFile("Command_MissingSerialization.xml");
assertNull(model);
@@ -69,6 +77,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a serialization");
}
+ @Test
public void testInvalidParamNumber() {
ICheatSheet model = parseTestFile("ActionElement_ParamInvalidNumber.xml");
assertNull(model);
@@ -76,6 +85,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "invalid parameter number");
}
+ @Test
public void testInvalidParamRange() {
ICheatSheet model = parseTestFile("ActionElement_ParamInvalidRange.xml");
assertNull(model);
@@ -83,6 +93,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "invalid range");
}
+ @Test
public void testMissingTitle() {
ICheatSheet model = parseTestFile("CheatSheetElement_MissingTitle.xml");
assertNull(model);
@@ -90,6 +101,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a title");
}
+ @Test
public void testNotDefined() {
ICheatSheet model = parseTestFile("CheatSheetElement_NotDefined.xml");
assertNull(model);
@@ -97,6 +109,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "The <cheatsheet> element must be the root");
}
+ @Test
public void testConditionalSubitemMissingCondition() {
ICheatSheet model = parseTestFile("CondSubItem_MissingCondition.xml");
assertNull(model);
@@ -104,6 +117,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a condition");
}
+ @Test
public void testConditionalSubitemMissingSubitem() {
ICheatSheet model = parseTestFile("CondSubItem_MissingSubItem.xml");
assertNull(model);
@@ -111,6 +125,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a subitem");
}
+ @Test
public void testIntroElementManyDefined() {
ICheatSheet model = parseTestFile("IntroElement_ManyDefined.xml");
assertNull(model);
@@ -118,20 +133,23 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "can only contain one <intro> element");
}
+ @Test
public void testIntroElementMissingDescription() {
ICheatSheet model = parseTestFile("IntroElement_MissingDescription.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "The description for element 'intro' was not defined");
}
-
+
+ @Test
public void testIntroElementManyDescriptions() {
ICheatSheet model = parseTestFile("IntroElement_ManyDescriptions.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "more than one description");
}
-
+
+ @Test
public void testIntroElementNotDefined() {
ICheatSheet model = parseTestFile("IntroElement_NotDefined.xml");
assertNull(model);
@@ -139,27 +157,31 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must contain an <intro>");
}
+ @Test
public void testItemElementMissingTitle() {
ICheatSheet model = parseTestFile("ItemElement_MissingTitle.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a title");
}
-
+
+ @Test
public void testItemElementMissingDescription() {
ICheatSheet model = parseTestFile("ItemElement_MissingDescription.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "The description for element 'item' was not defined");
}
-
+
+ @Test
public void testItemElementManyDescriptions() {
ICheatSheet model = parseTestFile("ItemElement_ManyDescriptions.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "more than one description");
}
-
+
+ @Test
public void testItemElementNotDefined() {
ICheatSheet model = parseTestFile("ItemElement_NotDefined.xml");
assertNull(model);
@@ -167,6 +189,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "at least one <item>");
}
+ @Test
public void testPerformWhenMissingAction() {
ICheatSheet model = parseTestFile("PerformWhen_MissingAction.xml");
assertNull(model);
@@ -174,20 +197,23 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must specify an action");
}
+ @Test
public void testPerformWhenMissingCondition() {
ICheatSheet model = parseTestFile("PerformWhen_MissingCondition.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a condition");
}
-
+
+ @Test
public void testSubitemElementMissingLabel() {
ICheatSheet model = parseTestFile("SubItem_MissingLabel.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a label");
}
-
+
+ @Test
public void testRepeatedSubitemMissingSubitem() {
ICheatSheet model = parseTestFile("RepSubItem_MissingSubItem.xml");
assertNull(model);
@@ -195,6 +221,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a subitem");
}
+ @Test
public void testRepeatedSubitemMissingValues() {
ICheatSheet model = parseTestFile("RepSubItem_MissingValues.xml");
assertNull(model);
@@ -202,6 +229,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "must specify a values");
}
+ @Test
public void testActionAndPerformWhen() {
ICheatSheet model = parseTestFile("ActionAndPerformWhen.xml");
assertNull(model);
@@ -209,6 +237,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "incompatible");
}
+ @Test
public void testCommandAndAction() {
ICheatSheet model = parseTestFile("CommandAndAction.xml");
assertNull(model);
@@ -216,6 +245,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "incompatible");
}
+ @Test
public void testCommandAndSubitem() {
ICheatSheet model = parseTestFile("CommandAndSubitem.xml");
assertNull(model);
@@ -223,6 +253,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "incompatible");
}
+ @Test
public void testSubitemAndPerformWhen() {
ICheatSheet model = parseTestFile("SubitemAndPerformWhen.xml");
assertNull(model);
@@ -230,6 +261,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "incompatible");
}
+ @Test
public void testTwoActions() {
ICheatSheet model = parseTestFile("TwoActions.xml");
assertNull(model);
@@ -237,6 +269,7 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "more than one");
}
+ @Test
public void testTwoCommands() {
ICheatSheet model = parseTestFile("TwoCommands.xml");
assertNull(model);
@@ -244,13 +277,15 @@ public class InvalidCheatsheet extends TestCase {
StatusCheck.assertStatusContains(parser.getStatus(), "more than one");
}
+ @Test
public void testTwoPerformWhen() {
ICheatSheet model = parseTestFile("TwoPerformWhen.xml");
assertNull(model);
assertEquals(IStatus.ERROR, parser.getStatus().getSeverity());
StatusCheck.assertStatusContains(parser.getStatus(), "more than one");
}
-
+
+ @Test
public void testConfirmTrueRequiredFalse() {
ICheatSheet model = parseTestFile("ConfirmTrueRequiredFalse.xml");
assertNull(model);
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/NoError.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/NoError.java
index d8c1bbd9a..dad4f6121 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/NoError.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/NoError.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 IBM Corporation and others.
+ * Copyright (c) 2007, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,39 +15,45 @@
package org.eclipse.ua.tests.cheatsheet.parser;
-import java.net.URL;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.net.URL;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.eclipse.ua.tests.util.ResourceFinder;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheet;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetParser;
import org.eclipse.ui.internal.cheatsheets.data.ICheatSheet;
+import org.junit.Before;
+import org.junit.Test;
-public class NoError extends TestCase {
+public class NoError {
private static final String NO_ERROR_FOLDER = "data/cheatsheet/no_error/";
private static final String OTHER_FOLDER = "data/cheatsheet/other/";
private CheatSheetParser parser;
-
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
parser = new CheatSheetParser();
}
-
+
private ICheatSheet parseTestFile(String path) {
- URL testURL = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(),
+ URL testURL = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(),
path);
return parser.parse(testURL, UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.SIMPLE_ONLY);
}
-
+
+ @Test
public void testConfirmRequiredCombinations() {
ICheatSheet model = parseTestFile(NO_ERROR_FOLDER + "ConfirmRequired.xml");
assertNotNull(model);
assertTrue(parser.getStatus().isOK());
}
+ @Test
public void testRestrictedAction() {
ICheatSheet model = parseTestFile(OTHER_FOLDER + "TestActions.xml");
assertNotNull(model);
@@ -56,6 +62,7 @@ public class NoError extends TestCase {
assertTrue(((CheatSheet)model).isContainsCommandOrAction());
}
+ @Test
public void testRestrictedCommand() {
ICheatSheet model = parseTestFile(OTHER_FOLDER + "TestCommand.xml");
assertNotNull(model);
@@ -63,7 +70,8 @@ public class NoError extends TestCase {
assertTrue(model instanceof CheatSheet);
assertTrue(((CheatSheet)model).isContainsCommandOrAction());
}
-
+
+ @Test
public void testNoRestriction() {
ICheatSheet model = parseTestFile(OTHER_FOLDER + "NoActions.xml");
assertNotNull(model);
@@ -71,6 +79,6 @@ public class NoError extends TestCase {
assertTrue(model instanceof CheatSheet);
assertFalse(((CheatSheet)model).isContainsCommandOrAction());
}
-
-
+
+
}
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ParseFromString.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ParseFromString.java
index e40b385f9..4603231eb 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ParseFromString.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ParseFromString.java
@@ -1,10 +1,10 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -12,6 +12,11 @@
package org.eclipse.ua.tests.cheatsheet.parser;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.net.URL;
import org.eclipse.core.runtime.Status;
@@ -21,53 +26,57 @@ import org.eclipse.ui.internal.cheatsheets.data.CheatSheetParser;
import org.eclipse.ui.internal.cheatsheets.data.ICheatSheet;
import org.eclipse.ui.internal.cheatsheets.data.ParserInput;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class ParseFromString extends TestCase {
+public class ParseFromString {
- private static final String VALID_CONTENT =
+ private static final String VALID_CONTENT =
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?> "
+ "<cheatsheet title=\"Title\">"
+ "<intro><description>Simple test</description></intro>"
+ "<item title=\"Item\">"
+ "<description>description</description>"
+ "</item></cheatsheet>";
-
+
// INVALID_CONTENT has no items
- private static final String INVALID_CONTENT =
+ private static final String INVALID_CONTENT =
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?> "
+ "<cheatsheet title=\"Title\">"
+ "<intro><description>Simple test</description></intro>"
+ "</cheatsheet>";
// Test that the default value for getContentXml is null
+ @Test
public void testElementXml() {
CheatSheetElement element = new CheatSheetElement("name");
assertNull(element.getContentXml());
element.setContentXml(VALID_CONTENT);
}
+ @Test
public void testDefaultParserInput() {
ParserInput input = new ParserInput();
assertNull(input.getUrl());
assertNull(input.getXml());
}
+ @Test
public void testXmlParserInput() {
ParserInput input = new ParserInput(VALID_CONTENT, null);
assertNull(input.getUrl());
assertEquals(VALID_CONTENT, input.getXml());
}
-
+
+ @Test
public void testUrlParserInput() {
- URL testURL = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(),
+ URL testURL = ResourceFinder.findFile(UserAssistanceTestPlugin.getDefault(),
"data/cheatsheet/valid/HelloWorld.xml");
ParserInput input = new ParserInput(testURL, UserAssistanceTestPlugin.getPluginId(), null);
assertNull(input.getXml());
assertTrue(testURL.equals(input.getUrl()));
}
+ @Test
public void testValidCheatsheet() {
ParserInput input = new ParserInput(VALID_CONTENT, null);
CheatSheetParser parser = new CheatSheetParser();
@@ -75,7 +84,8 @@ public class ParseFromString extends TestCase {
assertNotNull(cheatSheet);
assertEquals(Status.OK, parser.getStatus().getSeverity());
}
-
+
+ @Test
public void testInvalidCheatsheet() {
ParserInput input = new ParserInput(INVALID_CONTENT, null);
CheatSheetParser parser = new CheatSheetParser();
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java
index 9101a9456..9c8edb0f8 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,15 +19,14 @@ import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheet;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetParser;
import org.junit.Assert;
-
-import junit.framework.TestCase;
+import org.junit.Test;
/*
* Tests the cheat sheets parser on tolerable cheat sheets. This means they're not strictly correct,
* but the parser will tolerate them.
*/
-public class TolerateTest extends TestCase {
-
+public class TolerateTest {
+
private void parseCheatsheet(String file) {
Path path = new Path("data/cheatsheet/valid/tolerate/" + file);
URL url = FileLocator.find(UserAssistanceTestPlugin.getDefault().getBundle(), path, null);
@@ -37,42 +36,52 @@ public class TolerateTest extends TestCase {
Assert.assertNotNull("Tried parsing a tolerable cheat sheet but parser returned null: " + url, sheet);
}
+ @Test
public void testItemExtraAttr() {
parseCheatsheet("ItemElement_ExtraAttr.xml");
}
+ @Test
public void testIntroExtraElement() {
parseCheatsheet("IntroElement_ExtraElement.xml");
}
+ @Test
public void testIntroExtraAttr() {
parseCheatsheet("IntroElement_ExtraAttr.xml");
}
+ @Test
public void testDescExtraElement() {
parseCheatsheet("DescriptionElement_ExtraElements.xml");
}
+ @Test
public void testConditionalExtraElement() {
parseCheatsheet("ConditionalSubItem_ExtraElement.xml");
}
+ @Test
public void testConditionalExtraAttr() {
parseCheatsheet("ConditionalSubItem_ExtraAttr.xml");
}
+ @Test
public void testElementExtraElement() {
parseCheatsheet("CheatSheetElement_ExtraElement.xml");
}
+ @Test
public void testElementExtraAttr() {
parseCheatsheet("CheatSheetElement_ExtraAttr.xml");
}
+ @Test
public void testExtraElement() {
parseCheatsheet("ActionElement_ExtraElement.xml");
}
+ @Test
public void testExtraAttr() {
parseCheatsheet("ActionElement_ExtraAttr.xml");
}
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java
index b1717535e..94452d61a 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 IBM Corporation and others.
+ * Copyright (c) 2005, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,22 +21,21 @@ import org.eclipse.ua.tests.util.FileUtil;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheet;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetParser;
import org.junit.Assert;
+import org.junit.Test;
import org.osgi.framework.Bundle;
-import junit.framework.TestCase;
-
/*
* Tests the cheat sheets parser on valid cheat sheets.
*/
-public class ValidTest extends TestCase {
-
+public class ValidTest {
+
private void parseCheatsheet(String file) throws IOException {
Path path = new Path("data/cheatsheet/valid/" + file);
Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle();
URL url = FileLocator.find(bundle, path, null);
CheatSheetParser parser = new CheatSheetParser();
CheatSheet sheet = (CheatSheet)parser.parse(url, UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.ANY);
- Assert.assertNotNull("Tried parsing a valid cheat sheet but parser returned null: " + url, sheet);
+ Assert.assertNotNull("Tried parsing a valid cheat sheet but parser returned null: " + url, sheet);
String expectedPath = "data/cheatsheet/valid/" + getExpected(file);
String expected = FileUtil.getContents(bundle, expectedPath);
String actual = CheatSheetModelSerializer.serialize(sheet);
@@ -48,48 +47,59 @@ public class ValidTest extends TestCase {
return file.substring(0, suffix) + "_expected.txt";
}
+ @Test
public void testSubItems() throws IOException {
parseCheatsheet("TestSubItems.xml");
}
+ @Test
public void testParameters() throws IOException {
parseCheatsheet("TestParameters.xml");
}
+ @Test
public void testOpeningURL() throws IOException {
parseCheatsheet("TestOpeningURL.xml");
}
+ @Test
public void testDynamicSubitems() throws IOException {
parseCheatsheet("TestDynamicSubItems.xml");
}
+ @Test
public void testDescriptionFormatting() throws IOException {
parseCheatsheet("TestDescriptionFormatting.xml");
}
+ @Test
public void testCSActions() throws IOException {
parseCheatsheet("TestCSActions.xml");
}
+ @Test
public void testContextHelp() throws IOException {
parseCheatsheet("TestContext_Help.xml");
}
+ @Test
public void testActions() throws IOException {
parseCheatsheet("TestActions.xml");
}
+ @Test
public void testHelloWorldWithSubitems() throws IOException {
parseCheatsheet("HelloWorldWithSubitems.xml");
}
+ @Test
public void testHelloWorldWithExtensions() throws IOException {
parseCheatsheet("HelloWorldWithExtensions.xml");
}
+ @Test
public void testHelloWorld() throws IOException {
parseCheatsheet("HelloWorld.xml");
}
-
+
}
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/util/CheatSheetModelSerializerTest.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/util/CheatSheetModelSerializerTest.java
index f24017b26..1d6de2db9 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/util/CheatSheetModelSerializerTest.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/util/CheatSheetModelSerializerTest.java
@@ -21,8 +21,7 @@ import org.eclipse.ua.tests.util.ResourceFinder;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheet;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetParser;
import org.junit.Assert;
-
-import junit.framework.TestCase;
+import org.junit.Test;
/*
* A utility for regenerating the _expected.txt files that contain the expected
@@ -30,19 +29,19 @@ import junit.framework.TestCase;
* sheet content in the /data/cheatsheet/valid folder, constructs the cheat sheet
* model, then serializes the model to a text file, which is stored in the same
* directory as the xml file, as <original_name>_expected.txt.
- *
+ *
* These files are used by the JUnit tests to compare the result with the expected
* result.
- *
+ *
* Usage:
- *
+ *
* 1. Run the "org.eclipse.ua.tests.cheatsheet.util.CheatSheetModelSerializerTest" eclipse application.
* 2. Right-click in "Package Explorer -> Refresh".
- *
+ *
* The new files should appear.
*/
-public class CheatSheetModelSerializerTest extends TestCase {
-
+public class CheatSheetModelSerializerTest {
+ @Test
public void testRunSerializer() throws IOException {
URL[] urls = ResourceFinder.findFiles(UserAssistanceTestPlugin.getDefault(), "data/cheatsheet/valid", ".xml", true);
Assert.assertTrue("Unable to find sample cheat sheets to test parser", urls.length > 0);
@@ -50,7 +49,7 @@ public class CheatSheetModelSerializerTest extends TestCase {
CheatSheetParser parser = new CheatSheetParser();
CheatSheet sheet = (CheatSheet)parser.parse(url, UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.ANY);
Assert.assertNotNull("Tried parsing a valid cheat sheet but parser returned null: " + url, sheet);
-
+
PrintWriter out = new PrintWriter(new FileOutputStream(FileUtil.getResultFile(url.toString().substring("file:/".length()))));
out.print(CheatSheetModelSerializer.serialize(sheet));
out.close();

Back to the top