aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2013-09-24 07:41:06 (EDT)
committerJohn Ross2013-09-24 09:18:41 (EDT)
commit530039e3ff865e1c855707f69d5d4c4b16ffb0a1 (patch)
tree6f659f393498562c697f9067108e31327a195783
parentaa6a7a8049cfe5089b7307c3a815e16b15d5f0b2 (diff)
downloadrt.equinox.framework-530039e3ff865e1c855707f69d5d4c4b16ffb0a1.zip
rt.equinox.framework-530039e3ff865e1c855707f69d5d4c4b16ffb0a1.tar.gz
rt.equinox.framework-530039e3ff865e1c855707f69d5d4c4b16ffb0a1.tar.bz2
Bug 411877 - Remove duplicates and consolidate tests based on the single concept per test paradigm rather than single assertjross/411877
per test.
-rwxr-xr-xbundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/DevClasspathTests.java305
1 files changed, 104 insertions, 201 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/DevClasspathTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/DevClasspathTests.java
index 5dc6ae0..ffc57bf 100755
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/DevClasspathTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/DevClasspathTests.java
@@ -26,6 +26,39 @@ public class DevClasspathTests extends CoreTest {
return new TestSuite(DevClasspathTests.class);
}
+ private static void assertEnumerationSize(String message, int expected, Enumeration<?> actual) {
+ assertNotNull(message, actual);
+ assertEquals(message, expected, Collections.list(actual).size());
+ }
+
+ private static void assertEquals(String message, Collection<?> expected, Enumeration<?> actual) {
+ if (expected == null) {
+ assertNull(message, actual);
+ return;
+ }
+ assertNotNull(message, actual);
+ Collection<?> actualCollection = Collections.list(actual);
+ assertEquals(message, expected, actualCollection);
+ }
+
+ private static void assertEquals(String message, Collection<? extends Object> expected, Collection<? extends Object> actual) {
+ if (expected == null && actual == null)
+ return;
+ if (expected == null || actual == null)
+ fail(message);
+ assertEquals(message, expected.size(), actual.size());
+ for (Object o : expected)
+ assertTrue(message, actual.contains(o));
+ }
+
+ private static void assertFragmentsAttachedToHost(Bundle host, int numOfFragments) {
+ Enumeration<URL> entries = host.findEntries("/", "MANIFEST.MF", true);
+ assertNotNull("No manifest entries found for host: " + host);
+ int expected = numOfFragments + 1; // + 1 for the host bundle's manifest.
+ int actual = Collections.list(entries).size();
+ assertEquals("Wrong number of fragments for host: " + host, expected, actual);
+ }
+
private BundleInstaller installer;
public void testBug351083() throws Exception {
@@ -46,178 +79,64 @@ public class DevClasspathTests extends CoreTest {
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$
}
- public void testBundleFindEntriesReturnsEntriesOnDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb2 = installBundle(equinox, "tb2");
- installBundle(equinox, "tb2.fragment");
- Collection<String> expected = Arrays.asList("tb2/X.class", "tb2/Y.class");
- Enumeration<URL> actual = tb2.findEntries("tb2", "*.class", false);
- String message = "Wrong entries";
- assertNotNull(message, actual);
- assertEquals(message, expected.size(), Collections.list(actual).size());
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleFindEntriesReturnsNullForDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb2 = installBundle(equinox, "tb2");
- Bundle tb2Fragment = installBundle(equinox, "tb2.fragment");
- // Verify the fragment bundle is attached to host.
- Enumeration<URL> entries = tb2.findEntries("/", "MANIFEST.MF", true);
- entries.nextElement();
- entries.nextElement();
- String message = "Entries should not exist";
- assertNull(message, tb2.findEntries("bin", "*", true));
- assertNull(message, tb2Fragment.findEntries("bin", "*", true));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleFindEntriesReturnsNullForEntriesOnDevClasspathWhenRootDirNotOnBundleClasspath() throws Exception {
+ public void testBundleFindEntriesOmitsDevClasspathEntriesWhenRootDirNotOnBundleClasspath() throws Exception {
Equinox equinox = createAndStartEquinox("bin");
try {
Bundle tb3 = installBundle(equinox, "tb3");
- assertNull("Entries should not exist", tb3.findEntries("tb3/", "*", true));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetEntryReturnsEntryOnDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb2 = installBundle(equinox, "tb2");
- assertNotNull("Entry should exist", tb2.getEntry("tb2/X.class"));
+ Collection<String> expected = Arrays.asList("tb3.properties", "META-INF/", "META-INF/MANIFEST.MF");
+ Enumeration<URL> actual = tb3.findEntries("/", "*", true);
+ assertNotNull("Wrong entry paths", actual);
+ assertEquals("Wrong entry paths", expected.size(), Collections.list(actual).size());
} finally {
equinox.stop();
}
}
- public void testBundleGetEntryReturnsNullForDevClasspath() throws Exception {
+ public void testBundleFindEntriesSquashesDevClasspathEntries() throws Exception {
Equinox equinox = createAndStartEquinox("bin");
try {
Bundle tb2 = installBundle(equinox, "tb2");
- String message = "Entry should not exist";
- assertNull(message, tb2.getEntry("bin"));
- assertNull(message, tb2.getEntry("bin/tb2"));
- assertNull(message, tb2.getEntry("bin/tb2/X.class"));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetEntryReturnsNullForEntryOnDevClasspathWhenRootDirNotOnBundleClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb3 = installBundle(equinox, "tb3");
- String message = "Entry should not exist";
- assertNull(message, tb3.getEntry("tb3/Y.class"));
- assertNull(message, tb3.getEntry("bin/tb3/Y.class"));
+ Collection<String> expected = Arrays.asList("tb2.properties", "META-INF/", "META-INF/MANIFEST.MF", "tb2/", "tb2/X.class", ".classpath");
+ Enumeration<URL> actual = tb2.findEntries("/", "*", true);
+ assertNotNull("Wrong entry paths", actual);
+ assertEquals("Wrong entry paths", expected.size(), Collections.list(actual).size());
} finally {
equinox.stop();
}
}
- public void testBundleGetEntryPathsReturnsEntryPathsOnDevClasspath() throws Exception {
+ public void testBundleGetEntryPathsReturnsRootEntries() throws Exception {
Equinox equinox = createAndStartEquinox("bin");
try {
Bundle tb2 = installBundle(equinox, "tb2");
- Collection<String> expected = Arrays.asList("tb2/X.class");
- Enumeration<String> actual = tb2.getEntryPaths("tb2");
+ Collection<String> expected = Arrays.asList("tb2.properties", "META-INF/", "tb2/", ".classpath");
+ Enumeration<String> actual = tb2.getEntryPaths("/");
assertEquals("Wrong entry paths", expected, actual);
} finally {
equinox.stop();
}
}
- public void testBundleGetEntryPathsReturnsNullForDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb2 = installBundle(equinox, "tb2");
- assertNull("Entry paths should not exist", tb2.getEntryPaths("bin"));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetEntryPathsReturnsNullForEntriesOnDevClasspathWhenRootDirNotOnBundleClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb3 = installBundle(equinox, "tb3");
- assertNull("Entries should not exist", tb3.getEntryPaths("tb3"));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetResourceReturnsResourceOnDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb2 = installBundle(equinox, "tb2");
- assertNotNull("Resource should exist", tb2.getResource(".classpath"));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetResourceReturnsNullForDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb2 = installBundle(equinox, "tb2");
- String message = "Resource should not exist";
- assertNull(message, tb2.getResource("bin"));
- assertNull(message, tb2.getResource("bin/tb2"));
- assertNull(message, tb2.getResource("bin/tb2/X.class"));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetResourceReturnsResourceOnDevClasspathWhenRootDirNotOnBundleClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb3 = installBundle(equinox, "tb3");
- assertNotNull("Resource should exist", tb3.getResource("tb3/Y.class"));
- assertNull("Resource should not exist", tb3.getResource("bin/tb3/Y.class"));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetResourcesReturnsResourcesOnDevClasspath() throws Exception {
+ public void testBundleGetEntryReturnsRootEntry() throws Exception {
Equinox equinox = createAndStartEquinox("bin");
try {
Bundle tb2 = installBundle(equinox, "tb2");
- installBundle(equinox, "tb2.fragment");
- Enumeration<URL> actual = tb2.getResources(".classpath");
- String message = "Wrong resources";
- assertNotNull(message, actual);
- assertEquals(message, 2, Collections.list(actual).size());
+ assertNotNull("Entry should exist", tb2.getEntry("tb2.properties"));
} finally {
equinox.stop();
}
}
- public void testBundleGetResourcesReturnsNullForDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
+ public void testBundleLoadClassForClassNotOnDevClasspath() throws Exception {
+ Equinox equinox = createAndStartEquinox(null);
try {
Bundle tb2 = installBundle(equinox, "tb2");
- assertNull("Resources should not exist", tb2.getEntryPaths("bin"));
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetResourcesReturnsResourcesOnDevClasspathWhenRootDirNotOnBundleClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb3 = installBundle(equinox, "tb3");
- assertNotNull("Resources should exist", tb3.getResources("tb3/Y.class"));
+ try {
+ tb2.loadClass("tb2.X");
+ fail("Class load should have failed");
+ } catch (ClassNotFoundException e) {
+ // Okay.
+ }
} finally {
equinox.stop();
}
@@ -239,76 +158,80 @@ public class DevClasspathTests extends CoreTest {
}
}
- public void testBundleLoadClassForClassNotOnDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox(null);
- try {
- Bundle tb2 = installBundle(equinox, "tb2");
- try {
- tb2.loadClass("tb2.X");
- fail("Class load should have failed");
- } catch (ClassNotFoundException e) {
- // Okay.
- }
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleGetEntryReturnsRootEntry() throws Exception {
+ public void testPathsContainingDevClasspathNull() throws Exception {
Equinox equinox = createAndStartEquinox("bin");
try {
Bundle tb2 = installBundle(equinox, "tb2");
- assertNotNull("Entry should exist", tb2.getEntry("tb2.properties"));
+ Bundle tb2Fragment = installBundle(equinox, "tb2.fragment");
+ assertFragmentsAttachedToHost(tb2, 1);
+ String message = "Paths containing dev classpath should return null";
+ // Bundle.findEntries
+ assertNull(message, tb2.findEntries("bin", "*", true));
+ assertNull(message, tb2Fragment.findEntries("bin", "*", true));
+ // Bundle.getEntry
+ assertNull(message, tb2.getEntry("bin"));
+ assertNull(message, tb2.getEntry("bin/tb2"));
+ assertNull(message, tb2.getEntry("bin/tb2/X.class"));
+ // Bundle.getEntryPaths
+ assertNull(message, tb2.getEntryPaths("bin"));
+ // Bundle.getResource
+ assertNull(message, tb2.getResource("bin"));
+ assertNull(message, tb2.getResource("bin/tb2"));
+ assertNull(message, tb2.getResource("bin/tb2/X.class"));
+ // Bundle.getResources
+ assertNull(message, tb2.getEntryPaths("bin"));
} finally {
equinox.stop();
}
}
- public void testBundleFindEntriesOmitsDevClasspathEntriesWhenRootDirNotOnBundleClasspath() throws Exception {
+ public void testPathsContainingDevClasspathNullWhenBundleRootDirNotOnBundleClasspath() throws Exception {
Equinox equinox = createAndStartEquinox("bin");
try {
Bundle tb3 = installBundle(equinox, "tb3");
- Collection<String> expected = Arrays.asList("tb3.properties", "META-INF/", "META-INF/MANIFEST.MF");
- Enumeration<URL> actual = tb3.findEntries("/", "*", true);
- assertNotNull("Wrong entry paths", actual);
- assertEquals("Wrong entry paths", expected.size(), Collections.list(actual).size());
- } finally {
- equinox.stop();
- }
- }
-
- public void testBundleEntryPathsReturnsEntryPathsOnDevClasspath() throws Exception {
- Equinox equinox = createAndStartEquinox("bin");
- try {
- Bundle tb2 = installBundle(equinox, "tb2");
- Collection<String> expected = Arrays.asList("tb2/X.class");
- Enumeration<String> actual = tb2.getEntryPaths("tb2");
- assertEquals("Wrong entry paths", expected, actual);
+ String message = "Paths containing dev classpath should return null";
+ // Bundle.findEntries
+ assertNull(message, tb3.findEntries("tb3/", "*", true));
+ // Bundle.getEntry
+ assertNull(message, tb3.getEntry("tb3/Y.class"));
+ assertNull(message, tb3.getEntry("bin/tb3/Y.class"));
+ // Bundle.getEntryPaths
+ assertNull(message, tb3.getEntryPaths("tb3"));
} finally {
equinox.stop();
}
}
- public void testBundleGetEntryPathsReturnsRootEntries() throws Exception {
+ public void testPathsOnDevClasspathNotNull() throws Exception {
Equinox equinox = createAndStartEquinox("bin");
try {
Bundle tb2 = installBundle(equinox, "tb2");
- Collection<String> expected = Arrays.asList("tb2.properties", "META-INF/", "tb2/", ".classpath");
- Enumeration<String> actual = tb2.getEntryPaths("/");
- assertEquals("Wrong entry paths", expected, actual);
+ installBundle(equinox, "tb2.fragment");
+ String message = "Paths on dev classpath should not return null";
+ // Bundle.findEntries
+ assertEnumerationSize(message, Arrays.asList("tb2/X.class", "tb2/Y.class").size(), tb2.findEntries("tb2", "*.class", false));
+ // Bundle.getEntry
+ assertNotNull(message, tb2.getEntry("tb2/X.class"));
+ // Bundle.getEntryPaths
+ assertEquals(message, Arrays.asList("tb2/X.class"), tb2.getEntryPaths("tb2"));
+ // Bundle.getResource
+ assertNotNull("Resource should exist", tb2.getResource(".classpath"));
+ // Bundle.getResources
+ assertEnumerationSize(message, 2, tb2.getResources(".classpath"));
} finally {
equinox.stop();
}
}
- public void testBundleFindEntriesSquashesDevClasspathEntries() throws Exception {
+ public void testPathsOnDevClasspathNotNullWhenBundleRootDirNotOnBundleClasspath() throws Exception {
Equinox equinox = createAndStartEquinox("bin");
try {
- Bundle tb2 = installBundle(equinox, "tb2");
- Collection<String> expected = Arrays.asList("tb2.properties", "META-INF/", "META-INF/MANIFEST.MF", "tb2/", "tb2/X.class", ".classpath");
- Enumeration<URL> actual = tb2.findEntries("/", "*", true);
- assertNotNull("Wrong entry paths", actual);
- assertEquals("Wrong entry paths", expected.size(), Collections.list(actual).size());
+ Bundle tb3 = installBundle(equinox, "tb3");
+ String message = "Paths on dev classpath should not return null";
+ // Bundle.getResource
+ assertNotNull(message, tb3.getResource("tb3/Y.class"));
+ // Bundle.getResources
+ assertNotNull(message, tb3.getResources("tb3/Y.class"));
} finally {
equinox.stop();
}
@@ -322,26 +245,6 @@ public class DevClasspathTests extends CoreTest {
installer.shutdown();
}
- private void assertEquals(String message, Collection<?> expected, Enumeration<?> actual) {
- if (expected == null) {
- assertNull(message, actual);
- return;
- }
- assertNotNull(message, actual);
- Collection<?> actualCollection = Collections.list(actual);
- assertEquals(message, expected, actualCollection);
- }
-
- private void assertEquals(String message, Collection<? extends Object> expected, Collection<? extends Object> actual) {
- if (expected == null && actual == null)
- return;
- if (expected == null || actual == null)
- fail(message);
- assertEquals(message, expected.size(), actual.size());
- for (Object o : expected)
- assertTrue(message, actual.contains(o));
- }
-
private Equinox createAndStartEquinox(String devClasspath) throws BundleException {
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();