diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/registry/RegistryListenerTest.java')
-rw-r--r-- | bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/registry/RegistryListenerTest.java | 64 |
1 files changed, 25 insertions, 39 deletions
diff --git a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/registry/RegistryListenerTest.java b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/registry/RegistryListenerTest.java index a3253f4fa..ab532a5c0 100644 --- a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/registry/RegistryListenerTest.java +++ b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/registry/RegistryListenerTest.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.equinox.common.tests.registry; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -37,7 +39,7 @@ public class RegistryListenerTest { final private static int MAX_TIME_PER_BUNDLE = 10000; // maximum time to wait for bundle event in milliseconds private static BundleContext fBundleContext; - + @BeforeClass public static void setUp() throws Exception { fBundleContext = FrameworkUtil.getBundle(RegistryListenerTest.class).getBundleContext(); @@ -64,11 +66,11 @@ public class RegistryListenerTest { assertTrue(listener.isAdded()); assertNotNull(extPointIDs); - assertTrue(extPointIDs.length == 1); + assertEquals(1, extPointIDs.length); assertTrue("bundle01.xp1".equals(extPointIDs[0])); assertNotNull(extensionsReceived); - assertTrue(extensionsReceived.length == 1); + assertEquals(1, extensionsReceived.length); assertTrue("bundle02.ext1".equals(extensionsReceived[0])); listener.reset(); @@ -84,11 +86,11 @@ public class RegistryListenerTest { assertTrue(listener.isRemoved()); assertNotNull(extPointIDs); - assertTrue(extPointIDs.length == 1); + assertEquals(1, extPointIDs.length); assertTrue("bundle01.xp1".equals(extPointIDs[0])); assertNotNull(extensionsReceived); - assertTrue(extensionsReceived.length == 1); + assertEquals(1, extensionsReceived.length); assertTrue("bundle02.ext1".equals(extensionsReceived[0])); } finally { @@ -123,11 +125,11 @@ public class RegistryListenerTest { assertTrue(listener.isAdded()); assertNotNull(extPointIDs); - assertTrue(extPointIDs.length == 1); + assertEquals(1, extPointIDs.length); assertTrue("bundle01.xp1".equals(extPointIDs[0])); assertNotNull(extensionsReceived); - assertTrue(extensionsReceived.length == 1); + assertEquals(1, extensionsReceived.length); assertTrue("bundle02.ext1".equals(extensionsReceived[0])); listener.reset(); @@ -143,11 +145,11 @@ public class RegistryListenerTest { assertTrue(listener.isRemoved()); assertNotNull(extPointIDs); - assertTrue(extPointIDs.length == 1); + assertEquals(1, extPointIDs.length); assertTrue("bundle01.xp1".equals(extPointIDs[0])); assertNotNull(extensionsReceived); - assertTrue(extensionsReceived.length == 1); + assertEquals(1, extensionsReceived.length); assertTrue("bundle02.ext1".equals(extensionsReceived[0])); } finally { @@ -184,21 +186,21 @@ public class RegistryListenerTest { String[] extPointIDs = listenerGlobal.extPointsReceived(MAX_TIME_PER_BUNDLE); String[] extensionsReceived = listenerGlobal.extensionsReceived(MAX_TIME_PER_BUNDLE); assertTrue(listenerGlobal.isAdded()); - checkIDs(extPointIDs, new String[] {"bundleMultiple.xp1", "bundleMultiple.xp2"}); - checkIDs(extensionsReceived, new String[] {"bundleMultiple.ext11", "bundleMultiple.ext12"}); + assertArrayEquals(extPointIDs, new String[] { "bundleMultiple.xp1", "bundleMultiple.xp2" }); + assertArrayEquals(extensionsReceived, new String[] { "bundleMultiple.ext11", "bundleMultiple.ext12" }); // test additions on listener on extension point with extensions String[] extPointIDs1 = listener1.extPointsReceived(20000); String[] extensionsReceived1 = listener1.extensionsReceived(20000); assertTrue(listener1.isAdded()); - checkIDs(extPointIDs1, new String[] {"bundleMultiple.xp1"}); - checkIDs(extensionsReceived1, new String[] {"bundleMultiple.ext11", "bundleMultiple.ext12"}); + assertArrayEquals(extPointIDs1, new String[] { "bundleMultiple.xp1" }); + assertArrayEquals(extensionsReceived1, new String[] { "bundleMultiple.ext11", "bundleMultiple.ext12" }); // test additions on listener on extension point with no extensions String[] extPointIDs2 = listener2.extPointsReceived(MAX_TIME_PER_BUNDLE); String[] extensionsReceived2 = listener2.extensionsReceived(50); assertTrue(listener2.isAdded()); - checkIDs(extPointIDs2, new String[] {"bundleMultiple.xp2"}); + assertArrayEquals(extPointIDs2, new String[] { "bundleMultiple.xp2" }); assertNull(extensionsReceived2); // removal @@ -213,21 +215,21 @@ public class RegistryListenerTest { extPointIDs = listenerGlobal.extPointsReceived(MAX_TIME_PER_BUNDLE); extensionsReceived = listenerGlobal.extensionsReceived(MAX_TIME_PER_BUNDLE); assertTrue(listenerGlobal.isRemoved()); - checkIDs(extPointIDs, new String[] {"bundleMultiple.xp1", "bundleMultiple.xp2"}); - checkIDs(extensionsReceived, new String[] {"bundleMultiple.ext11", "bundleMultiple.ext12"}); + assertArrayEquals(extPointIDs, new String[] { "bundleMultiple.xp1", "bundleMultiple.xp2" }); + assertArrayEquals(extensionsReceived, new String[] { "bundleMultiple.ext11", "bundleMultiple.ext12" }); // test removals on listener on extension point with extensions extPointIDs1 = listener1.extPointsReceived(MAX_TIME_PER_BUNDLE); extensionsReceived1 = listener1.extensionsReceived(MAX_TIME_PER_BUNDLE); assertTrue(listener1.isRemoved()); - checkIDs(extPointIDs1, new String[] {"bundleMultiple.xp1"}); - checkIDs(extensionsReceived1, new String[] {"bundleMultiple.ext11", "bundleMultiple.ext12"}); + assertArrayEquals(extPointIDs1, new String[] { "bundleMultiple.xp1" }); + assertArrayEquals(extensionsReceived1, new String[] { "bundleMultiple.ext11", "bundleMultiple.ext12" }); // test removals on listener on extension point with no extensions extPointIDs2 = listener2.extPointsReceived(MAX_TIME_PER_BUNDLE); extensionsReceived2 = listener2.extensionsReceived(50); assertTrue(listener2.isRemoved()); - checkIDs(extPointIDs2, new String[] {"bundleMultiple.xp2"}); + assertArrayEquals(extPointIDs2, new String[] { "bundleMultiple.xp2" }); assertNull(extensionsReceived2); } finally { @@ -258,14 +260,14 @@ public class RegistryListenerTest { // 1st registration: extension point; extension => 2 callbacks // 2nd registration should be ignored: extension => 0 callbacks // total: 2 callbacks - assertTrue(listener.waitFor(2, MAX_TIME_PER_BUNDLE) == 2); + assertEquals(2, listener.waitFor(2, MAX_TIME_PER_BUNDLE)); // test additions on listener on extension point with extensions String[] extPointIDs = listener.extPointsReceived(50); String[] extensionsReceived = listener.extensionsReceived(50); assertTrue(listener.isAdded()); - checkIDs(extPointIDs, new String[] {"bundleMultiple.xp1"}); - checkIDs(extensionsReceived, new String[] {"bundleMultiple.ext11", "bundleMultiple.ext12"}); + assertArrayEquals(extPointIDs, new String[] { "bundleMultiple.xp1" }); + assertArrayEquals(extensionsReceived, new String[] { "bundleMultiple.ext11", "bundleMultiple.ext12" }); // removal: unregistering listener once should remove both registrations listener.reset(); @@ -275,7 +277,7 @@ public class RegistryListenerTest { BundleTestingHelper.refreshPackages(fBundleContext, testBundles); // test removals on listener on extension point with extensions - assertTrue(listener.waitFor(3, 200) == 0); + assertEquals(0, listener.waitFor(3, 200)); extPointIDs = listener.extPointsReceived(50); extensionsReceived = listener.extensionsReceived(50); assertNull(extPointIDs); @@ -289,20 +291,4 @@ public class RegistryListenerTest { } } - // For simplicity, this method does not expect duplicate IDs in either array - private void checkIDs(String[] receivedIDs, String[] expectedIDs) { - assertNotNull(receivedIDs); - assertNotNull(expectedIDs); - assertTrue(receivedIDs.length == expectedIDs.length); - for (String expected : expectedIDs) { - boolean found = false; - for (String receivedID : receivedIDs) { - if (expected.equals(receivedID)) { - found = true; - break; - } - } - assertTrue(found); - } - } } |