VirgoEEBundleComparable implements Comparator<Bundle> { @Override public int compare(Bundle b1, Bundle b2) { if(b1 == b2) { return 0; } String name1 = b1.getSymbolicName(); String name2 = b2.getSymbolicName(); Integer index1 = orderedImplBundles.indexOf(name1); Integer index2 = orderedImplBundles.indexOf(name2); if(index1 == -1 && index2 == -1) { return name1.compareTo(name2); } else if(index1 == -1) { return 1; } else if(index2 == -1) { return -1; } else { return index1.compareTo(index2); } } VirgoEEBundleComparable(); @Override int compare(Bundle b1, Bundle b2);  }
@Test public void testCompareTwoNotSpecialBundles() { System.clearProperty(WebAppBundleTrackerCustomizer.IMPL_BUNDLES); VirgoEEBundleComparable comparable = new VirgoEEBundleComparable(); Bundle b1 = EasyMock.createMock(Bundle.class); Bundle b2 = EasyMock.createMock(Bundle.class); EasyMock.expect(b1.getSymbolicName()).andReturn("a"); EasyMock.expect(b2.getSymbolicName()).andReturn("b"); EasyMock.replay(b1, b2); assertEquals("When not matching impl.bundles bundles should be sorted alphabetically",-1, comparable.compare(b1, b2)); }
@Test public void testEqualNotBundles() { System.clearProperty(WebAppBundleTrackerCustomizer.IMPL_BUNDLES); VirgoEEBundleComparable comparable = new VirgoEEBundleComparable(); Bundle b1 = EasyMock.createMock(Bundle.class); EasyMock.expect(b1.getSymbolicName()).andReturn("a"); EasyMock.replay(b1); assertEquals("Exact bundles comparison is wrong", 0, comparable.compare(b1, b1)); }
@Test public void testTwoBundlesSameSymbolicNames() { System.clearProperty(WebAppBundleTrackerCustomizer.IMPL_BUNDLES); VirgoEEBundleComparable comparable = new VirgoEEBundleComparable(); Bundle b1 = EasyMock.createMock(Bundle.class); Bundle b2 = EasyMock.createMock(Bundle.class); EasyMock.expect(b1.getSymbolicName()).andReturn("a"); EasyMock.expect(b2.getSymbolicName()).andReturn("a"); EasyMock.replay(b1, b2); assertEquals("Bundles have same symbolic name, should be equal",0, comparable.compare(b1, b2)); }
@Test public void testSpecialToNotSpecialBundles() { System.setProperty(WebAppBundleTrackerCustomizer.IMPL_BUNDLES, "b;bundle-version\\=1.0.0"); VirgoEEBundleComparable comparable = new VirgoEEBundleComparable(); Bundle b1 = EasyMock.createMock(Bundle.class); Bundle b2 = EasyMock.createMock(Bundle.class); EasyMock.expect(b1.getSymbolicName()).andReturn("a"); EasyMock.expect(b2.getSymbolicName()).andReturn("b"); EasyMock.replay(b1, b2); assertEquals("Bundle b is declared as impl - should be less", -1, comparable.compare(b2, b1)); }
@Test public void testTwoSpecialBundles() { System.setProperty(WebAppBundleTrackerCustomizer.IMPL_BUNDLES, "b;bundle-version\\=1.0.0,a;bundle-version\\=1.0.0"); VirgoEEBundleComparable comparable = new VirgoEEBundleComparable(); Bundle b1 = EasyMock.createMock(Bundle.class); Bundle b2 = EasyMock.createMock(Bundle.class); EasyMock.expect(b1.getSymbolicName()).andReturn("a"); EasyMock.expect(b2.getSymbolicName()).andReturn("b"); EasyMock.replay(b1, b2); assertEquals("Bundle b is declared first in impl.bundles - should be less",-1, comparable.compare(b2, b1)); }