diff options
author | Alexander Kurtakov | 2016-01-20 09:06:40 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2016-01-20 09:06:40 +0000 |
commit | de8dbf0d20b614778383733388ea8623b5259064 (patch) | |
tree | 4ef6c08f6963a4f62a2e8cf37d41ad2a7b585b45 /org.eclipse.ua.tests/intro/org/eclipse | |
parent | b420615420019ccb714716263223371dac432691 (diff) | |
download | eclipse.platform.ua-de8dbf0d20b614778383733388ea8623b5259064.tar.gz eclipse.platform.ua-de8dbf0d20b614778383733388ea8623b5259064.tar.xz eclipse.platform.ua-de8dbf0d20b614778383733388ea8623b5259064.zip |
Bug 485918 - Convert org.eclipse.ua.tests to JUnit 4
Everything left in intro source folder.
Change-Id: I6715a49ac40ffaa4e220d0ff350fca24b4b8b999
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'org.eclipse.ua.tests/intro/org/eclipse')
6 files changed, 125 insertions, 96 deletions
diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/anchors/ExtensionReorderingTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/anchors/ExtensionReorderingTest.java index 9adbc1418..ace09e0c0 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/anchors/ExtensionReorderingTest.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/anchors/ExtensionReorderingTest.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 @@ -11,6 +11,12 @@ package org.eclipse.ua.tests.intro.anchors; +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 static org.junit.Assert.fail; + /** * Test that the order in which extensions are processed does not matter * In the test case extn1 and extn2 contribute to the root @@ -22,7 +28,6 @@ package org.eclipse.ua.tests.intro.anchors; import java.util.Vector; -import junit.framework.TestCase; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; @@ -31,40 +36,41 @@ import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage; import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; import org.eclipse.ui.internal.intro.impl.model.IntroPage; import org.eclipse.ui.internal.intro.impl.model.loader.ModelLoaderUtil; +import org.junit.Test; + +public class ExtensionReorderingTest { -public class ExtensionReorderingTest extends TestCase { - private IConfigurationElement config; private IConfigurationElement[] introConfigExtensions; - + private class Permutations { private int numContributions; private int[] order; private int cycle = 1; private int count = 0; - + public void testAll(int numContributions) { this.numContributions = numContributions; order = new int[numContributions]; tryAll(0); } - + public Permutations(int testCycle) { this.cycle = testCycle; } - + public Permutations() { - + } - + /* * Recursive test to test all permutations of integers 0-4 with no - * repeats. + * repeats. * @param next the next element that has not been filled in yet */ private void tryAll(int next) { for (int value = 0; value < numContributions; value++) { - tryValue(next, value); + tryValue(next, value); } } @@ -87,7 +93,7 @@ public class ExtensionReorderingTest extends TestCase { tryAll(next + 1); } } - + private String toString(int[] order) { String result = ""; for (int element : order) { @@ -104,7 +110,7 @@ public class ExtensionReorderingTest extends TestCase { extensions[i] = introConfigExtensions[order[i]]; } IntroModelRoot model = new IntroModelRoot(config, extensions); - + try { model.loadModel(); assertTrue("Order = " + toString(order), model.hasValidConfig()); @@ -113,7 +119,7 @@ public class ExtensionReorderingTest extends TestCase { e.printStackTrace(); fail("Exception thrown when order was " + toString(order)); } - } + } } public void readIntroConfig() { @@ -129,7 +135,7 @@ public class ExtensionReorderingTest extends TestCase { introConfigExtensions = getIntroConfigExtensions( "configId", "org.eclipse.ua.tests.intro.config.anchors"); } - + private IConfigurationElement getConfigurationFromAttribute( IConfigurationElement[] configElements, String attributeName, String attributeValue) { @@ -142,7 +148,7 @@ public class ExtensionReorderingTest extends TestCase { .validateSingleContribution(filteredConfigElements, attributeName); return config; } - + protected IConfigurationElement[] getConfigurationsFromAttribute( IConfigurationElement[] configElements, String attributeName, String attributeValue) { @@ -164,14 +170,14 @@ public class ExtensionReorderingTest extends TestCase { return filteredConfigElements; } - + protected IConfigurationElement[] getIntroConfigExtensions( String attrributeName, String attributeValue) { IExtensionRegistry registry= Platform.getExtensionRegistry(); IConfigurationElement[] configExtensionElements = registry .getConfigurationElementsFor("org.eclipse.ui.intro.configExtension"); - + IConfigurationElement[] configExtensions = getConfigurationsFromAttribute( configExtensionElements, attrributeName, attributeValue); @@ -179,6 +185,7 @@ public class ExtensionReorderingTest extends TestCase { return configExtensions; } + @Test public void testOrder123456() { readIntroConfig(); assertNotNull(config); @@ -189,7 +196,7 @@ public class ExtensionReorderingTest extends TestCase { } private void checkModel(IntroModelRoot model, int elements) { - assertTrue(model.hasValidConfig()); + assertTrue(model.hasValidConfig()); Object[] pages = model.getChildrenOfType(AbstractIntroElement.ABSTRACT_PAGE); AbstractIntroPage root = (AbstractIntroPage) model.findChild("root"); assertEquals(elements + 2, pages.length); @@ -235,26 +242,30 @@ public class ExtensionReorderingTest extends TestCase { } } + @Test public void testAllOrdersOf3Contributions() { new Permutations().testAll(3); } - + + @Test public void testAllOrdersOf4Contributions() { new Permutations().testAll(4); } + @Test public void testAllOrdersOf5Contributions() { readIntroConfig(); new Permutations().testAll(5); - } - + } + /* * Testing all permutations is slow and unnecessary, just test every 7th permutation */ + @Test public void testManyOrdersOf6Contributions() { readIntroConfig(); new Permutations(7).testAll(6); - } + } + - } diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/contentdetect/ContentDetectorTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/contentdetect/ContentDetectorTest.java index 1c99fcd17..8692eafcd 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/contentdetect/ContentDetectorTest.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/contentdetect/ContentDetectorTest.java @@ -1,43 +1,35 @@ /******************************************************************************* - * 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 * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.ua.tests.intro.contentdetect; +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 java.util.HashSet; import java.util.Set; -import junit.framework.Test; -import junit.framework.TestCase; - -import org.eclipse.test.OrderedTestSuite; import org.eclipse.ui.internal.intro.impl.model.ExtensionMap; import org.eclipse.ui.internal.intro.universal.contentdetect.ContentDetectHelper; import org.eclipse.ui.internal.intro.universal.contentdetect.ContentDetector; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; -public class ContentDetectorTest extends TestCase { - - public static Test suite() { - return new OrderedTestSuite(ContentDetectorTest.class, new String[] { - "testContributorCount", - "testContributorSaveNoNames", - "testContributorSaveThreeContributors", - "testExtensionMapping", - "testExtensionMapSingleton", - "testForNewContent", - "testNoSavedState", - "testStartPage", - "testStateChanges" - }); - } - +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ContentDetectorTest { + + @Test public void testContributorCount() { ContentDetectHelper helper = new ContentDetectHelper(); helper.saveExtensionCount(4); @@ -48,12 +40,14 @@ public class ContentDetectorTest extends TestCase { assertEquals(6, helper.getExtensionCount()); } + @Test public void testContributorSaveNoNames() { ContentDetectHelper helper = new ContentDetectHelper(); helper.saveContributors(new HashSet<String>()); assertTrue(helper.getContributors().size() == 0); } + @Test public void testContributorSaveThreeContributors() { ContentDetectHelper helper = new ContentDetectHelper(); HashSet<String> contributors = new HashSet<String>(); @@ -67,7 +61,8 @@ public class ContentDetectorTest extends TestCase { assertTrue(savedContributors.contains("two")); assertTrue(savedContributors.contains("three")); } - + + @Test public void testForNewContent() { ContentDetectHelper helper = new ContentDetectHelper(); HashSet<String> contributors = new HashSet<String>(); @@ -85,11 +80,12 @@ public class ContentDetectorTest extends TestCase { assertTrue(newContributors.contains("three")); } + @Test public void testNoSavedState() { ContentDetectHelper helper = new ContentDetectHelper(); helper.deleteStateFiles(); assertTrue(helper.getContributors().isEmpty()); - assertEquals(ContentDetectHelper.NO_STATE, helper.getExtensionCount()); + assertEquals(ContentDetectHelper.NO_STATE, helper.getExtensionCount()); ContentDetector detector = new ContentDetector(); assertFalse(detector.isNewContentAvailable()); Set<?> newContent = ContentDetector.getNewContributors(); @@ -97,7 +93,8 @@ public class ContentDetectorTest extends TestCase { String firstContribution = (String) helper.getContributors().iterator().next(); assertFalse(ContentDetector.isNew(firstContribution)); } - + + @Test public void testStateChanges() { ContentDetectHelper helper = new ContentDetectHelper(); helper.deleteStateFiles(); @@ -127,13 +124,15 @@ public class ContentDetectorTest extends TestCase { assertTrue(ContentDetector.isNew(firstContribution)); assertTrue(ContentDetector.isNew(copyOfFirstContribution)); } - + + @Test public void testExtensionMapSingleton() { ExtensionMap map1 = ExtensionMap.getInstance(); ExtensionMap map2 = ExtensionMap.getInstance(); assertEquals(map1, map2); } - + + @Test public void testExtensionMapping() { ExtensionMap map = ExtensionMap.getInstance(); map.clear(); @@ -146,7 +145,8 @@ public class ContentDetectorTest extends TestCase { map.clear(); assertNull(map.getPluginId("anchor1")); } - + + @Test public void testStartPage() { ExtensionMap map = ExtensionMap.getInstance(); map.setStartPage("tutorials"); diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/other/NormalizeWhitespaceTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/other/NormalizeWhitespaceTest.java index 2d7c8fa87..cecd3a204 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/other/NormalizeWhitespaceTest.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/other/NormalizeWhitespaceTest.java @@ -10,47 +10,55 @@ *******************************************************************************/ package org.eclipse.ua.tests.intro.other; -import org.eclipse.ui.internal.intro.impl.util.StringUtil; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -import junit.framework.TestCase; +import org.eclipse.ui.internal.intro.impl.util.StringUtil; +import org.junit.Test; /* * Tests whitespace normalization used by SWT presentation. */ -public class NormalizeWhitespaceTest extends TestCase { - +public class NormalizeWhitespaceTest { + @Test public void testNullString() { assertNull(StringUtil.normalizeWhiteSpace(null)); } + @Test public void testEmptyString() { String result = StringUtil.normalizeWhiteSpace(""); assertEquals("", result); } + @Test public void testSimpleString() { String result = StringUtil.normalizeWhiteSpace("Hello World"); assertEquals("Hello World", result); } + @Test public void testRepeatedSpace() { String result = StringUtil.normalizeWhiteSpace("Hello World"); assertEquals("Hello World", result); } - + + @Test public void testOtherWhitespace() { String result = StringUtil.normalizeWhiteSpace("Hello\n\r\t World"); assertEquals("Hello World", result); } + @Test public void testLeadingSpace() { String result = StringUtil.normalizeWhiteSpace(" Hello World"); assertEquals("Hello World", result); } - + + @Test public void testTrailingSpace() { String result = StringUtil.normalizeWhiteSpace("Hello World "); assertEquals("Hello World", result); } - + } diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/other/ReopenStateTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/other/ReopenStateTest.java index 791fb0191..b2a607074 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/other/ReopenStateTest.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/other/ReopenStateTest.java @@ -4,21 +4,23 @@ * 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 *******************************************************************************/ package org.eclipse.ua.tests.intro.other; -import org.eclipse.ui.internal.intro.impl.util.ReopenUtil; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.eclipse.ui.internal.intro.impl.util.ReopenUtil; +import org.junit.Test; /* * Tests the intro parser on valid intro content. */ -public class ReopenStateTest extends TestCase { - +public class ReopenStateTest { + @Test public void testReopenState() { ReopenUtil.setReopenPreference(true); assertTrue(ReopenUtil.isReopenPreference()); @@ -31,6 +33,6 @@ public class ReopenStateTest extends TestCase { ReopenUtil.setReopenPreference(false); assertFalse(ReopenUtil.isReopenPreference()); } - - + + } diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/ValidTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/ValidTest.java index db67da739..8b50f2059 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/ValidTest.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/parser/ValidTest.java @@ -1,15 +1,17 @@ /******************************************************************************* - * 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 * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.ua.tests.intro.parser; +import static org.junit.Assert.fail; + import java.io.IOException; import java.util.Iterator; import java.util.Map; @@ -25,44 +27,49 @@ import org.eclipse.ua.tests.util.FileUtil; import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager; import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.osgi.framework.Bundle; -import junit.framework.TestCase; - /* * Tests the intro parser on valid intro content. */ -public class ValidTest extends TestCase { - +public class ValidTest { + /* * Ensure that org.eclipse.help.ui is started. It contributes extra content * filtering that is used by this test. See UIContentFilterProcessor. */ - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { HelpUIPlugin.getDefault(); } + @Test public void testDynamicXHTML() throws IOException { singleConfigTest("org.eclipse.ua.tests.intro.config.dynamicXHTML"); } + @Test public void testDynamicXML() throws IOException { singleConfigTest("org.eclipse.ua.tests.intro.config.dynamicXML"); } + @Test public void testAnchors() throws IOException { singleConfigTest("org.eclipse.ua.tests.intro.config.anchors"); } + @Test public void testMixed() throws IOException { singleConfigTest("org.eclipse.ua.tests.intro.config.mixed"); } - + + @Test public void testStatic() throws IOException { singleConfigTest("org.eclipse.ua.tests.intro.config.static"); } - + /* * Test valid intro content. This goes through the test intro content * (xml files and xhtml files) and serializes it using the @@ -82,27 +89,27 @@ public class ValidTest extends TestCase { for (int x = 0; x < 10; x++) { // Perform 10 times to better detect intermittent ordering bugs Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle(); - + IntroModelRoot model = ExtensionPointManager.getInst().getModel(id); IntroModelSerializer serializer = new IntroModelSerializer(model); - + String expected = FileUtil.getContents(bundle, FileUtil.getResultFile(content)); String actual = serializer.toString(); Assert.assertEquals("The model parsed for intro did not match the expected result for: " + id, expected, actual); - + Map<String, String> map = IntroModelSerializerTest.getXHTMLFiles(model); Iterator<Entry<String, String>> iter = map.entrySet().iterator(); while (iter.hasNext()) { Entry<String, String> entry = iter.next(); String relativePath = entry.getKey(); - + expected = FileUtil.getContents(bundle, FileUtil.getResultFile(relativePath)); actual = entry.getValue(); Assert.assertEquals("The XHTML generated for intro did not match the expected result for: " + relativePath, expected, actual); } } return; - } + } } } fail("Config extension not found"); diff --git a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializerTest.java b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializerTest.java index 2d505da0b..843d97295 100644 --- a/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializerTest.java +++ b/org.eclipse.ua.tests/intro/org/eclipse/ua/tests/intro/util/IntroModelSerializerTest.java @@ -4,7 +4,7 @@ * 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 *******************************************************************************/ @@ -33,8 +33,8 @@ import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager; import org.eclipse.ui.internal.intro.impl.presentations.BrowserIntroPartImplementation; import org.eclipse.ui.intro.config.IIntroContentProvider; import org.eclipse.ui.intro.config.IIntroContentProviderSite; - -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; /* * A utility for regenerating the _expected.txt files that contain the expected @@ -42,29 +42,30 @@ import junit.framework.TestCase; * the plugin manifest (for this test plugin only), constructs the intro model, then * serializes the model to a text file, which is stored in the same directory as the * intro 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 this test as a JUnit plug-in test. * 2. Right-click in "Package Explorer -> Refresh". - * + * * The new files should appear. */ -public class IntroModelSerializerTest extends TestCase { - +public class IntroModelSerializerTest { + /* * Ensure that org.eclipse.help.ui is started. It contributes extra * content filtering that is used by this test. See * UIContentFilterProcessor. */ - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { HelpUIPlugin.getDefault(); } - + + @Test public void testRunSerializer() throws FileNotFoundException { /* * Serialize the test intros. @@ -84,12 +85,12 @@ public class IntroModelSerializerTest extends TestCase { */ IntroModelRoot model = ExtensionPointManager.getInst().getModel(id); IntroModelSerializer serializer = new IntroModelSerializer(model); - + String file = FileUtil.getResultFile(pluginRoot + content); PrintWriter out = new PrintWriter(new FileOutputStream(file)); out.print(serializer.toString()); out.close(); - + /* * Now do the intro XHTML files. Find all the XHTML files * referenced from the model. |