diff options
author | Alexander Kurtakov | 2021-12-01 10:01:45 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2021-12-01 11:23:40 +0000 |
commit | 457dd2f67cc42e0ff514dfa302ad77f8cd3e598b (patch) | |
tree | 6a8b3b643111d6ab138a1080af359aa26702a862 | |
parent | dfad3634c242bdb1cb6ab29d1a7f26e2bd769147 (diff) | |
download | rt.equinox.bundles-457dd2f67cc42e0ff514dfa302ad77f8cd3e598b.tar.gz rt.equinox.bundles-457dd2f67cc42e0ff514dfa302ad77f8cd3e598b.tar.xz rt.equinox.bundles-457dd2f67cc42e0ff514dfa302ad77f8cd3e598b.zip |
Bug 577552 - Switch tests to mockito
Convert equinox.region.tests.
Remove useless target file.
Do some slight modernization to have it less verbose as newer Java
versions allow.
Change-Id: Ifbf4f4b9b08c32c57a02a537656566b2ae231d15
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/188391
Tested-by: Equinox Bot <equinox-bot@eclipse.org>
7 files changed, 173 insertions, 195 deletions
diff --git a/bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF index ec77ab250..dbd9cfe94 100644 --- a/bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.region.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Equinox Region Tests Bundle-SymbolicName: org.eclipse.equinox.region.tests -Bundle-Version: 1.5.100.qualifier +Bundle-Version: 1.6.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Import-Package: junit.framework;version="4.8.1", org.aspectj.internal.lang.annotation;version="[1.6.3,2.0.0)";resolution:=optional, @@ -11,7 +11,6 @@ Import-Package: junit.framework;version="4.8.1", org.aspectj.lang.reflect;version="[1.6.3,2.0.0)";resolution:=optional, org.aspectj.runtime.internal;version="[1.6.3,2.0.0)";resolution:=optional, org.aspectj.runtime.reflect;version="[1.6.3,2.0.0)";resolution:=optional, - org.easymock;version="2.4.0", org.eclipse.core.tests.harness;resolution:=optional, org.eclipse.equinox.region;version="1.1.0", org.eclipse.osgi.service.urlconversion;version="1.0.0", @@ -19,6 +18,8 @@ Import-Package: junit.framework;version="4.8.1", org.junit.rules;version="4.12.0", org.junit.runner;version="4.12.0", org.junit.runners;version="4.12.0", + org.mockito, + org.mockito.stubbing, org.osgi.framework;version="1.8.0", org.osgi.framework.hooks.bundle;version="1.1.0", org.osgi.framework.hooks.resolver;version="1.0.0", diff --git a/bundles/org.eclipse.equinox.region.tests/pom.xml b/bundles/org.eclipse.equinox.region.tests/pom.xml index b537eeeea..a28e4764c 100644 --- a/bundles/org.eclipse.equinox.region.tests/pom.xml +++ b/bundles/org.eclipse.equinox.region.tests/pom.xml @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.region.tests</artifactId> - <version>1.5.100-SNAPSHOT</version> + <version>1.6.0-SNAPSHOT</version> <packaging>eclipse-test-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.region.tests/regionTestTarget.target b/bundles/org.eclipse.equinox.region.tests/regionTestTarget.target deleted file mode 100644 index c71fd9b81..000000000 --- a/bundles/org.eclipse.equinox.region.tests/regionTestTarget.target +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?pde version="3.6"?> - -<target name="Region Test Target" sequenceNumber="6"> -<locations> -<location path="${eclipse_home}" type="Profile"/> -<location includeAllPlatforms="false" includeMode="slicer" includeSource="true" type="InstallableUnit"> -<unit id="org.easymock" version="2.4.0.v20090202-0900"/> -<unit id="org.easymock.source" version="2.4.0.v20090202-0900"/> -<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20100519200754/repository/"/> -</location> -<location includeAllPlatforms="false" includeMode="slicer" includeSource="true" type="InstallableUnit"> -<unit id="org.aspectj.feature.group" version="1.6.7.20091231194938"/> -<repository location="http://download.eclipse.org/tools/ajdt/aspectj/update"/> -</location> -</locations> -<environment> -<os>macosx</os> -<ws>cocoa</ws> -<arch>x86_64</arch> -<nl>en_US</nl> -</environment> -<launcherArgs> -<vmArgs>-Declipse.p2.mirrors=false -Xdock:icon=../Resources/Eclipse.icns -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts -Xms40m -Xmx384m -Xdock:icon=../Resources/Eclipse.icns -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgs> -</launcherArgs> -</target> diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/BundleIdBasedRegionTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/BundleIdBasedRegionTests.java index 842629dc1..92b7059fd 100644 --- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/BundleIdBasedRegionTests.java +++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/BundleIdBasedRegionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2020 VMware Inc. + * Copyright (c) 2011, 2021 VMware Inc. and others * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -16,15 +16,20 @@ package org.eclipse.equinox.region.internal.tests; 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.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.util.HashSet; import java.util.Iterator; -import org.easymock.EasyMock; import org.eclipse.equinox.region.*; import org.eclipse.equinox.region.RegionDigraph.FilteredRegion; -import org.junit.*; +import org.junit.Before; +import org.junit.Test; import org.osgi.framework.*; public class BundleIdBasedRegionTests { @@ -66,18 +71,18 @@ public class BundleIdBasedRegionTests { @Before public void setUp() throws Exception { this.threadLocal = new ThreadLocal<Region>(); - this.mockBundle = EasyMock.createMock(Bundle.class); - EasyMock.expect(this.mockBundle.getSymbolicName()).andReturn(BUNDLE_SYMBOLIC_NAME).anyTimes(); - EasyMock.expect(this.mockBundle.getVersion()).andReturn(BUNDLE_VERSION).anyTimes(); - EasyMock.expect(this.mockBundle.getBundleId()).andReturn(BUNDLE_ID).anyTimes(); + this.mockBundle = mock(Bundle.class); + when(this.mockBundle.getSymbolicName()).thenReturn(BUNDLE_SYMBOLIC_NAME); + when(this.mockBundle.getVersion()).thenReturn(BUNDLE_VERSION); + when(this.mockBundle.getBundleId()).thenReturn(BUNDLE_ID); - this.mockBundleContext = EasyMock.createMock(BundleContext.class); - EasyMock.expect(this.mockBundleContext.getBundle(BUNDLE_ID)).andReturn(this.mockBundle).anyTimes(); + this.mockBundleContext = mock(BundleContext.class); + when(this.mockBundleContext.getBundle(BUNDLE_ID)).thenReturn(this.mockBundle); - this.mockRegion = EasyMock.createMock(Region.class); - this.mockRegion2 = EasyMock.createMock(Region.class); + this.mockRegion = mock(Region.class); + this.mockRegion2 = mock(Region.class); - this.mockRegionFilter = EasyMock.createMock(RegionFilter.class); + this.mockRegionFilter = mock(RegionFilter.class); this.regionIterator = new Iterator<Region>() { @@ -96,21 +101,11 @@ public class BundleIdBasedRegionTests { // nothing } }; - this.mockGraph = EasyMock.createMock(RegionDigraph.class); - this.mockGraph.connect(EasyMock.isA(Region.class), EasyMock.eq(this.mockRegionFilter), EasyMock.eq(this.mockRegion)); - EasyMock.expectLastCall().anyTimes(); + this.mockGraph = mock(RegionDigraph.class); + this.mockGraph.connect(isA(Region.class), eq(this.mockRegionFilter), eq(this.mockRegion)); this.bundleIdToRegionMapping = RegionReflectionUtils.newStandardBundleIdToRegionMapping(); } - private void replayMocks() { - EasyMock.replay(this.mockBundleContext, this.mockBundle, this.mockRegion, this.mockRegion2, this.mockRegionFilter, this.mockGraph); - } - - @After - public void tearDown() throws Exception { - EasyMock.verify(this.mockBundleContext, this.mockBundle, this.mockRegion, this.mockRegion2, this.mockRegionFilter, this.mockGraph); - } - @Test public void testGetName() { defaultSetUp(); @@ -124,18 +119,18 @@ public class BundleIdBasedRegionTests { } private Region createBundleIdBasedRegion(String regionName) { - return RegionReflectionUtils.newBundleIdBasedRegion(regionName, this.mockGraph, this.bundleIdToRegionMapping, this.mockBundleContext, this.threadLocal); + return RegionReflectionUtils.newBundleIdBasedRegion(regionName, this.mockGraph, this.bundleIdToRegionMapping, + this.mockBundleContext, this.threadLocal); } private void defaultSetUp() { - EasyMock.expect(this.mockGraph.iterator()).andReturn(this.regionIterator).anyTimes(); - EasyMock.expect(this.mockGraph.getEdges(EasyMock.isA(Region.class))).andReturn(new HashSet<FilteredRegion>()).anyTimes(); - replayMocks(); + when(this.mockGraph.iterator()).thenReturn(this.regionIterator); + when(this.mockGraph.getEdges(isA(Region.class))).thenReturn(new HashSet<>()); } @Test public void testAddBundle() throws BundleException { - EasyMock.expect(this.mockGraph.iterator()).andReturn(this.regionIterator).anyTimes(); + when(this.mockGraph.iterator()).thenReturn(this.regionIterator); HashSet<FilteredRegion> edges = new HashSet<FilteredRegion>(); edges.add(new FilteredRegion() { @@ -151,8 +146,7 @@ public class BundleIdBasedRegionTests { return mockRegionFilter; } }); - EasyMock.expect(this.mockGraph.getEdges(EasyMock.isA(Region.class))).andReturn(edges).anyTimes(); - replayMocks(); + when(this.mockGraph.getEdges(isA(Region.class))).thenReturn(edges); Region r = createDefaultBundleIdBasedRegion(); r.addBundle(this.mockBundle); @@ -171,11 +165,10 @@ public class BundleIdBasedRegionTests { public void testAddConflictingBundle() throws BundleException { defaultSetUp(); - Bundle mockBundle2 = EasyMock.createMock(Bundle.class); - EasyMock.expect(mockBundle2.getSymbolicName()).andReturn(BUNDLE_SYMBOLIC_NAME).anyTimes(); - EasyMock.expect(mockBundle2.getVersion()).andReturn(BUNDLE_VERSION).anyTimes(); - EasyMock.expect(mockBundle2.getBundleId()).andReturn(BUNDLE_ID_2).anyTimes(); - EasyMock.replay(mockBundle2); + Bundle mockBundle2 = mock(Bundle.class); + when(mockBundle2.getSymbolicName()).thenReturn(BUNDLE_SYMBOLIC_NAME); + when(mockBundle2.getVersion()).thenReturn(BUNDLE_VERSION); + when(mockBundle2.getBundleId()).thenReturn(BUNDLE_ID_2); Region r = createDefaultBundleIdBasedRegion(); r.addBundle(this.mockBundle); @@ -207,10 +200,10 @@ public class BundleIdBasedRegionTests { @Override public Region next() { switch (next--) { - case 2 : - return mockRegion; - default : - return mockRegion2; + case 2: + return mockRegion; + default: + return mockRegion2; } } @@ -219,33 +212,17 @@ public class BundleIdBasedRegionTests { // nothing } }; - EasyMock.expect(this.mockGraph.iterator()).andReturn(this.regionIterator).anyTimes(); - EasyMock.expect(this.mockGraph.getEdges(EasyMock.isA(Region.class))).andReturn(new HashSet<FilteredRegion>()).anyTimes(); - EasyMock.expect(this.mockRegion.contains(EasyMock.eq(BUNDLE_ID))).andReturn(true).anyTimes(); - EasyMock.expect(this.mockRegion2.contains(EasyMock.eq(BUNDLE_ID))).andReturn(false).anyTimes(); + when(this.mockGraph.iterator()).thenReturn(this.regionIterator); + when(this.mockGraph.getEdges(isA(Region.class))).thenReturn(new HashSet<>()); + when(this.mockRegion.contains(eq(BUNDLE_ID))).thenReturn(true); + when(this.mockRegion2.contains(eq(BUNDLE_ID))).thenReturn(false); RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, BUNDLE_ID, mockRegion); - replayMocks(); - Region r = createDefaultBundleIdBasedRegion(); return r; } @Test - public void testInstallBundleStringInputStream() { - defaultSetUp(); - - // TODO - } - - @Test - public void testInstallBundleString() { - defaultSetUp(); - - // TODO - } - - @Test public void testContains() throws BundleException { defaultSetUp(); @@ -306,7 +283,7 @@ public class BundleIdBasedRegionTests { Region r = createDefaultBundleIdBasedRegion(); Region s = createBundleIdBasedRegion(OTHER_REGION_NAME); assertFalse(r.equals(s)); - assertFalse(r.equals(null)); + assertNotNull(r); } @Test diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardBundleIdToRegionMappingTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardBundleIdToRegionMappingTests.java index 0b392edcb..f503f5997 100644 --- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardBundleIdToRegionMappingTests.java +++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardBundleIdToRegionMappingTests.java @@ -18,8 +18,8 @@ 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 static org.mockito.Mockito.mock; -import org.easymock.EasyMock; import org.eclipse.equinox.region.Region; import org.junit.Before; import org.junit.Test; @@ -38,7 +38,7 @@ public class StandardBundleIdToRegionMappingTests { @Before public void setUp() throws Exception { this.bundleIdToRegionMapping = RegionReflectionUtils.newStandardBundleIdToRegionMapping(); - this.mockRegion = EasyMock.createMock(Region.class); + this.mockRegion = mock(Region.class); } @Test @@ -57,7 +57,8 @@ public class StandardBundleIdToRegionMappingTests { @Test(expected = BundleException.class) public void testAssociateBundleAlreadyAssociatedWithOtherRegion() { RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion); - RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, EasyMock.createMock(Region.class)); + RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, + mock(Region.class)); } @Test @@ -69,9 +70,11 @@ public class StandardBundleIdToRegionMappingTests { @Test public void testIsBundleAssociatedWithRegion() { - assertFalse(RegionReflectionUtils.isBundleAssociatedWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion)); + assertFalse(RegionReflectionUtils.isBundleAssociatedWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, + mockRegion)); RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion); - assertFalse(RegionReflectionUtils.isBundleAssociatedWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion)); + assertFalse(RegionReflectionUtils.isBundleAssociatedWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, + mockRegion)); } @Test @@ -80,8 +83,10 @@ public class StandardBundleIdToRegionMappingTests { RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, TEST_BUNDLE_ID, mockRegion); RegionReflectionUtils.associateBundleWithRegion(this.bundleIdToRegionMapping, OTHER_TEST_BUNDLE_ID, mockRegion); assertEquals(2, RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion).size()); - assertTrue(RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion).contains(TEST_BUNDLE_ID)); - assertTrue(RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion).contains(OTHER_TEST_BUNDLE_ID)); + assertTrue( + RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion).contains(TEST_BUNDLE_ID)); + assertTrue(RegionReflectionUtils.getBundleIds(this.bundleIdToRegionMapping, mockRegion) + .contains(OTHER_TEST_BUNDLE_ID)); } @Test diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java index 29abe13a3..884454082 100644 --- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java +++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java @@ -19,14 +19,16 @@ 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 static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.util.*; -import org.easymock.EasyMock; import org.eclipse.equinox.region.*; import org.eclipse.equinox.region.RegionDigraph.FilteredRegion; import org.eclipse.virgo.teststubs.osgi.framework.StubBundle; import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext; -import org.junit.*; +import org.junit.Before; +import org.junit.Test; import org.osgi.framework.*; public class StandardRegionDigraphTests { @@ -43,8 +45,6 @@ public class StandardRegionDigraphTests { private RegionFilter regionFilter2; - private Bundle mockBundle; - @Before public void setUp() throws Exception { StubBundle stubSystemBundle = new StubBundle(0L, "osgi.framework", new Version("0"), "loc"); @@ -52,19 +52,18 @@ public class StandardRegionDigraphTests { stubBundleContext.addInstalledBundle(stubSystemBundle); this.digraph = RegionReflectionUtils.newStandardRegionDigraph(stubBundleContext, new ThreadLocal<Region>()); - this.mockRegion1 = EasyMock.createMock(Region.class); - EasyMock.expect(this.mockRegion1.getName()).andReturn("mockRegion1").anyTimes(); - EasyMock.expect(this.mockRegion1.getRegionDigraph()).andReturn(this.digraph).anyTimes(); + this.mockRegion1 = mock(Region.class); + when(this.mockRegion1.getName()).thenReturn("mockRegion1"); + when(this.mockRegion1.getRegionDigraph()).thenReturn(this.digraph); - this.mockRegion2 = EasyMock.createMock(Region.class); - EasyMock.expect(this.mockRegion2.getName()).andReturn("mockRegion2").anyTimes(); - EasyMock.expect(this.mockRegion2.getRegionDigraph()).andReturn(this.digraph).anyTimes(); + this.mockRegion2 = mock(Region.class); + when(this.mockRegion2.getName()).thenReturn("mockRegion2"); + when(this.mockRegion2.getRegionDigraph()).thenReturn(this.digraph); - this.mockRegion3 = EasyMock.createMock(Region.class); - EasyMock.expect(this.mockRegion3.getName()).andReturn("mockRegion3").anyTimes(); - EasyMock.expect(this.mockRegion3.getRegionDigraph()).andReturn(this.digraph).anyTimes(); + this.mockRegion3 = mock(Region.class); + when(this.mockRegion3.getName()).thenReturn("mockRegion3"); + when(this.mockRegion3.getRegionDigraph()).thenReturn(this.digraph); - this.mockBundle = EasyMock.createMock(Bundle.class); } private void setDefaultFilters() { @@ -72,28 +71,23 @@ public class StandardRegionDigraphTests { this.regionFilter2 = digraph.createRegionFilterBuilder().build(); } - private void setAllowedFilters(String b1Name, Version b1Version, String b2Name, Version b2Version) throws InvalidSyntaxException { - String filter1 = "(&(" + RegionFilter.VISIBLE_BUNDLE_NAMESPACE + "=" + b1Name + ")(" + Constants.BUNDLE_VERSION_ATTRIBUTE + "=" + b1Version + "))"; - regionFilter1 = digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, filter1).build(); - - String filter2 = "(&(" + RegionFilter.VISIBLE_BUNDLE_NAMESPACE + "=" + b2Name + ")(" + Constants.BUNDLE_VERSION_ATTRIBUTE + "=" + b2Version + "))"; - regionFilter2 = digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, filter2).build(); - - } + private void setAllowedFilters(String b1Name, Version b1Version, String b2Name, Version b2Version) + throws InvalidSyntaxException { + String filter1 = "(&(" + RegionFilter.VISIBLE_BUNDLE_NAMESPACE + "=" + b1Name + ")(" + + Constants.BUNDLE_VERSION_ATTRIBUTE + "=" + b1Version + "))"; + regionFilter1 = digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, filter1) + .build(); - private void replayMocks() { - EasyMock.replay(this.mockRegion1, this.mockRegion2, this.mockRegion3, this.mockBundle); - } + String filter2 = "(&(" + RegionFilter.VISIBLE_BUNDLE_NAMESPACE + "=" + b2Name + ")(" + + Constants.BUNDLE_VERSION_ATTRIBUTE + "=" + b2Version + "))"; + regionFilter2 = digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, filter2) + .build(); - @After - public void tearDown() throws Exception { - EasyMock.verify(this.mockRegion1, this.mockRegion2, this.mockRegion3, this.mockBundle); } @Test public void testConnect() throws BundleException { setDefaultFilters(); - replayMocks(); this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2); } @@ -105,10 +99,8 @@ public class StandardRegionDigraphTests { String b2Name = "b2"; Version b2Version = new Version("0"); setAllowedFilters(b1Name, b1Version, b2Name, b2Version); - EasyMock.expect(this.mockRegion1.getBundle(b1Name, b1Version)).andReturn(null).anyTimes(); - EasyMock.expect(this.mockRegion1.getBundle(b2Name, b2Version)).andReturn(null).anyTimes(); - - replayMocks(); + when(this.mockRegion1.getBundle(b1Name, b1Version)).thenReturn(null); + when(this.mockRegion1.getBundle(b2Name, b2Version)).thenReturn(null); this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2); this.digraph.connect(this.mockRegion1, this.regionFilter2, this.mockRegion3); @@ -117,7 +109,6 @@ public class StandardRegionDigraphTests { @Test(expected = BundleException.class) public void testConnectLoop() throws BundleException { setDefaultFilters(); - replayMocks(); this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion1); } @@ -125,7 +116,6 @@ public class StandardRegionDigraphTests { @Test(expected = BundleException.class) public void testDuplicateConnection() throws BundleException { setDefaultFilters(); - replayMocks(); this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2); this.digraph.connect(this.mockRegion1, this.regionFilter2, this.mockRegion2); @@ -134,7 +124,6 @@ public class StandardRegionDigraphTests { @Test public void testReplaceConnection() throws BundleException { setDefaultFilters(); - replayMocks(); RegionFilter existing; @@ -154,7 +143,6 @@ public class StandardRegionDigraphTests { @Test public void testGetEdges() throws BundleException { setDefaultFilters(); - replayMocks(); this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2); this.digraph.connect(this.mockRegion1, this.regionFilter2, this.mockRegion3); @@ -193,7 +181,6 @@ public class StandardRegionDigraphTests { @Test public void testRemoveRegion() throws BundleException { setDefaultFilters(); - replayMocks(); this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2); this.digraph.connect(this.mockRegion2, this.regionFilter2, this.mockRegion1); @@ -207,7 +194,6 @@ public class StandardRegionDigraphTests { @Test public void testGetRegions() throws BundleException { setDefaultFilters(); - replayMocks(); this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2); Set<Region> regions = this.digraph.getRegions(); @@ -223,7 +209,6 @@ public class StandardRegionDigraphTests { @Test public void testCopyRegion() throws BundleException, InvalidSyntaxException { - replayMocks(); // needed to allow teardown to succeed. RegionDigraph testDigraph = RegionReflectionUtils.newStandardRegionDigraph(); long bundleId = 1; Region a = testDigraph.createRegion(REGION_A); @@ -269,7 +254,8 @@ public class StandardRegionDigraphTests { testDigraph.replace(testCopy); StandardRegionDigraphPeristenceTests.assertEquals(testDigraph, testCopy); - // test that we can continue to use the copy to replace as long as it is upto date with the last replace + // test that we can continue to use the copy to replace as long as it is upto + // date with the last replace Region testAdd1 = testCopy.createRegion("testAdd1"); testCopy.connect(testAdd1, testCopy.createRegionFilterBuilder().allow("testAdd1", "(testAdd=x)").build(), a); try { @@ -307,7 +293,8 @@ public class StandardRegionDigraphTests { testCopy = testDigraph.copy(); // add a new region to the original Region testAdd2 = testDigraph.createRegion("testAdd2"); - testDigraph.connect(testAdd2, testCopy.createRegionFilterBuilder().allow("testAdd2", "(testAdd=x)").build(), origA); + testDigraph.connect(testAdd2, testCopy.createRegionFilterBuilder().allow("testAdd2", "(testAdd=x)").build(), + origA); try { testDigraph.replace(testCopy); fail("Digraph changed since copy."); @@ -318,7 +305,8 @@ public class StandardRegionDigraphTests { testCopy = testDigraph.copy(); // change a connection in the original testDigraph.removeRegion(testAdd2); - testDigraph.connect(testAdd2, testCopy.createRegionFilterBuilder().allow("testAdd2", "(testAdd=y)").build(), origA); + testDigraph.connect(testAdd2, testCopy.createRegionFilterBuilder().allow("testAdd2", "(testAdd=y)").build(), + origA); try { testDigraph.replace(testCopy); fail("Digraph changed since copy."); @@ -329,7 +317,8 @@ public class StandardRegionDigraphTests { testCopy = testDigraph.copy(); Region origB = testDigraph.getRegion(REGION_B); // add a connection in the original - testDigraph.connect(testAdd2, testCopy.createRegionFilterBuilder().allow("testAdd2", "(testAdd=y)").build(), origB); + testDigraph.connect(testAdd2, testCopy.createRegionFilterBuilder().allow("testAdd2", "(testAdd=y)").build(), + origB); try { testDigraph.replace(testCopy); fail("Digraph changed since copy."); @@ -374,15 +363,16 @@ public class StandardRegionDigraphTests { @Test public void testVisitRegions() throws BundleException, InvalidSyntaxException { - replayMocks(); // needed to allow teardown to succeed. RegionDigraph testDigraph = RegionReflectionUtils.newStandardRegionDigraph(); Region a = testDigraph.createRegion(REGION_A); Region b = testDigraph.createRegion(REGION_B); Region c = testDigraph.createRegion(REGION_C); Region d = testDigraph.createRegion(REGION_D); - testDigraph.connect(a, testDigraph.createRegionFilterBuilder().allow("b", "(b=x)").allow("c", "(c=x)").allow("d", "(d=x)").build(), b); - testDigraph.connect(b, testDigraph.createRegionFilterBuilder().allow("c", "(c=x)").allow("d", "(d=x)").build(), c); + testDigraph.connect(a, testDigraph.createRegionFilterBuilder().allow("b", "(b=x)").allow("c", "(c=x)") + .allow("d", "(d=x)").build(), b); + testDigraph.connect(b, testDigraph.createRegionFilterBuilder().allow("c", "(c=x)").allow("d", "(d=x)").build(), + c); testDigraph.connect(c, testDigraph.createRegionFilterBuilder().allow("d", "(d=x)").build(), d); Map<String, String> attributes = new HashMap<String, String>(); @@ -426,7 +416,6 @@ public class StandardRegionDigraphTests { @Test public void testGetHooks() throws BundleException { setDefaultFilters(); - replayMocks(); assertNotNull("Resolver Hook is null", digraph.getResolverHookFactory()); assertNotNull("Bundle Event Hook is null", digraph.getBundleEventHook()); diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionFilterTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionFilterTests.java index f92a5cf6a..e5887fd90 100644 --- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionFilterTests.java +++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionFilterTests.java @@ -18,9 +18,10 @@ 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 static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.util.*; -import org.easymock.EasyMock; import org.eclipse.equinox.region.RegionFilter; import org.eclipse.equinox.region.RegionFilterBuilder; import org.eclipse.virgo.teststubs.osgi.framework.*; @@ -55,44 +56,44 @@ public class StandardRegionFilterTests { @Before public void setUp() throws Exception { this.stubBundle = new StubBundle(BUNDLE_SYMBOLIC_NAME, BUNDLE_VERSION); - this.fooService = new StubServiceRegistration<Object>(new StubBundleContext(), "foo.Service"); - this.barService = new StubServiceRegistration<Object>(new StubBundleContext(), "bar.Service"); + this.fooService = new StubServiceRegistration<>(new StubBundleContext(), "foo.Service"); + this.barService = new StubServiceRegistration<>(new StubBundleContext(), "bar.Service"); - this.fooPackage = EasyMock.createMock(BundleCapability.class); - Map<String, Object> fooAttrs = new HashMap<String, Object>(); + this.fooPackage = mock(BundleCapability.class); + Map<String, Object> fooAttrs = new HashMap<>(); fooAttrs.put(BundleRevision.PACKAGE_NAMESPACE, "foo"); - EasyMock.expect(fooPackage.getNamespace()).andReturn(BundleRevision.PACKAGE_NAMESPACE).anyTimes(); - EasyMock.expect(fooPackage.getAttributes()).andReturn(fooAttrs).anyTimes(); - EasyMock.replay(fooPackage); + when(fooPackage.getNamespace()).thenReturn(BundleRevision.PACKAGE_NAMESPACE); + when(fooPackage.getAttributes()).thenReturn(fooAttrs); - this.fooServiceCapability = EasyMock.createMock(BundleCapability.class); - Map<String, Object> fooServiceAttrs = new HashMap<String, Object>(); + this.fooServiceCapability = mock(BundleCapability.class); + Map<String, Object> fooServiceAttrs = new HashMap<>(); fooServiceAttrs.put(Constants.OBJECTCLASS, "foo.Service"); - EasyMock.expect(fooServiceCapability.getNamespace()).andReturn(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE).anyTimes(); - EasyMock.expect(fooServiceCapability.getAttributes()).andReturn(fooServiceAttrs).anyTimes(); - EasyMock.replay(fooServiceCapability); + when(fooServiceCapability.getNamespace()).thenReturn(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE); + when(fooServiceCapability.getAttributes()).thenReturn(fooServiceAttrs); - this.barPackage = EasyMock.createMock(BundleCapability.class); - Map<String, Object> barAttrs = new HashMap<String, Object>(); + this.barPackage = mock(BundleCapability.class); + Map<String, Object> barAttrs = new HashMap<>(); barAttrs.put(BundleRevision.PACKAGE_NAMESPACE, "bar"); - EasyMock.expect(barPackage.getNamespace()).andReturn(BundleRevision.PACKAGE_NAMESPACE).anyTimes(); - EasyMock.expect(barPackage.getAttributes()).andReturn(barAttrs).anyTimes(); - EasyMock.replay(barPackage); + when(barPackage.getNamespace()).thenReturn(BundleRevision.PACKAGE_NAMESPACE); + when(barPackage.getAttributes()).thenReturn(barAttrs); - this.barServiceCapability = EasyMock.createMock(BundleCapability.class); - Map<String, Object> barServiceAttrs = new HashMap<String, Object>(); + this.barServiceCapability = mock(BundleCapability.class); + Map<String, Object> barServiceAttrs = new HashMap<>(); barServiceAttrs.put(Constants.OBJECTCLASS, "bar.Service"); - EasyMock.expect(barServiceCapability.getNamespace()).andReturn(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE).anyTimes(); - EasyMock.expect(barServiceCapability.getAttributes()).andReturn(barServiceAttrs).anyTimes(); - EasyMock.replay(barServiceCapability); + when(barServiceCapability.getNamespace()).thenReturn(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE); + when(barServiceCapability.getAttributes()).thenReturn(barServiceAttrs); } - private RegionFilter createBundleFilter(String bundleSymbolicName, Version bundleVersion) throws InvalidSyntaxException { - String filter = "(&(" + RegionFilter.VISIBLE_BUNDLE_NAMESPACE + "=" + bundleSymbolicName + ")(" + Constants.BUNDLE_VERSION_ATTRIBUTE + ">=" + bundleVersion + "))"; - return RegionReflectionUtils.newStandardRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, filter).build(); + private RegionFilter createBundleFilter(String bundleSymbolicName, Version bundleVersion) + throws InvalidSyntaxException { + String filter = "(&(" + RegionFilter.VISIBLE_BUNDLE_NAMESPACE + "=" + bundleSymbolicName + ")(" + + Constants.BUNDLE_VERSION_ATTRIBUTE + ">=" + bundleVersion + "))"; + return RegionReflectionUtils.newStandardRegionFilterBuilder() + .allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, filter).build(); } - private RegionFilter createRegionFilter(String namespace, Collection<String> filters) throws InvalidSyntaxException { + private RegionFilter createRegionFilter(String namespace, Collection<String> filters) + throws InvalidSyntaxException { RegionFilterBuilder builder = RegionReflectionUtils.newStandardRegionFilterBuilder(); for (String filter : filters) { builder.allow(namespace, filter); @@ -114,7 +115,8 @@ public class StandardRegionFilterTests { @Test public void testBundleAllAllowed() { - RegionFilter regionFilter = RegionReflectionUtils.newStandardRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_BUNDLE_NAMESPACE).build(); + RegionFilter regionFilter = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allowAll(RegionFilter.VISIBLE_BUNDLE_NAMESPACE).build(); assertTrue(regionFilter.isAllowed(stubBundle)); } @@ -126,9 +128,11 @@ public class StandardRegionFilterTests { @Test public void testCapabilityAllowed() throws InvalidSyntaxException { - RegionFilter regionFilter = createRegionFilter(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, Arrays.asList(packageImportPolicy)); + RegionFilter regionFilter = createRegionFilter(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, + Arrays.asList(packageImportPolicy)); assertTrue(regionFilter.isAllowed(fooPackage)); - assertEquals(Arrays.asList(this.packageImportPolicy), regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_PACKAGE_NAMESPACE)); + assertEquals(Arrays.asList(this.packageImportPolicy), + regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_PACKAGE_NAMESPACE)); } @Test @@ -139,30 +143,37 @@ public class StandardRegionFilterTests { @Test public void testCapabilityAllAllowed() { - RegionFilter regionFilter = RegionReflectionUtils.newStandardRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_PACKAGE_NAMESPACE).build(); + RegionFilter regionFilter = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allowAll(RegionFilter.VISIBLE_PACKAGE_NAMESPACE).build(); assertTrue(regionFilter.isAllowed(barPackage)); } @Test public void testCapabilityNotAllowed() throws InvalidSyntaxException { - RegionFilter regionFilter = createRegionFilter(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, Arrays.asList(packageImportPolicy)); + RegionFilter regionFilter = createRegionFilter(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, + Arrays.asList(packageImportPolicy)); assertFalse(regionFilter.isAllowed(barPackage)); - assertEquals(Arrays.asList(this.packageImportPolicy), regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_PACKAGE_NAMESPACE)); + assertEquals(Arrays.asList(this.packageImportPolicy), + regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_PACKAGE_NAMESPACE)); } @SuppressWarnings("deprecation") @Test public void testServiceAllowed() throws InvalidSyntaxException { - RegionFilter regionFilter = createRegionFilter(RegionFilter.VISIBLE_SERVICE_NAMESPACE, Arrays.asList(serviceImportPolicy)); + RegionFilter regionFilter = createRegionFilter(RegionFilter.VISIBLE_SERVICE_NAMESPACE, + Arrays.asList(serviceImportPolicy)); assertTrue(regionFilter.isAllowed(fooService.getReference())); assertTrue(regionFilter.isAllowed(fooServiceCapability)); - assertEquals(Arrays.asList(serviceImportPolicy), regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_SERVICE_NAMESPACE)); + assertEquals(Arrays.asList(serviceImportPolicy), + regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_SERVICE_NAMESPACE)); - regionFilter = createRegionFilter(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE, Arrays.asList(serviceImportPolicy)); + regionFilter = createRegionFilter(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE, + Arrays.asList(serviceImportPolicy)); assertTrue(regionFilter.isAllowed(fooService.getReference())); assertTrue(regionFilter.isAllowed(fooServiceCapability)); assertNull(regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_SERVICE_NAMESPACE)); - assertEquals(Arrays.asList(serviceImportPolicy), regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE)); + assertEquals(Arrays.asList(serviceImportPolicy), + regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE)); } @Test @@ -175,11 +186,13 @@ public class StandardRegionFilterTests { @Test public void testServiceAllAllowed() { @SuppressWarnings("deprecation") - RegionFilter regionFilter = RegionReflectionUtils.newStandardRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_SERVICE_NAMESPACE).build(); + RegionFilter regionFilter = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allowAll(RegionFilter.VISIBLE_SERVICE_NAMESPACE).build(); assertTrue(regionFilter.isAllowed(fooService.getReference())); assertTrue(regionFilter.isAllowed(fooServiceCapability)); - regionFilter = RegionReflectionUtils.newStandardRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE).build(); + regionFilter = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allowAll(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE).build(); assertTrue(regionFilter.isAllowed(fooService.getReference())); assertTrue(regionFilter.isAllowed(fooServiceCapability)); } @@ -187,23 +200,31 @@ public class StandardRegionFilterTests { @SuppressWarnings("deprecation") @Test public void testServiceNotAllowed() throws InvalidSyntaxException { - RegionFilter regionFilter = createRegionFilter(RegionFilter.VISIBLE_SERVICE_NAMESPACE, Arrays.asList(serviceImportPolicy)); + RegionFilter regionFilter = createRegionFilter(RegionFilter.VISIBLE_SERVICE_NAMESPACE, + Arrays.asList(serviceImportPolicy)); assertFalse(regionFilter.isAllowed(barService.getReference())); assertFalse(regionFilter.isAllowed(barServiceCapability)); - assertEquals(Arrays.asList(serviceImportPolicy), regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_SERVICE_NAMESPACE)); - assertEquals(Arrays.asList(serviceImportPolicy), regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE)); + assertEquals(Arrays.asList(serviceImportPolicy), + regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_SERVICE_NAMESPACE)); + assertEquals(Arrays.asList(serviceImportPolicy), + regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE)); - regionFilter = createRegionFilter(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE, Arrays.asList(serviceImportPolicy)); + regionFilter = createRegionFilter(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE, + Arrays.asList(serviceImportPolicy)); assertFalse(regionFilter.isAllowed(barService.getReference())); assertFalse(regionFilter.isAllowed(barServiceCapability)); assertNull(regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_SERVICE_NAMESPACE)); - assertEquals(Arrays.asList(serviceImportPolicy), regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE)); + assertEquals(Arrays.asList(serviceImportPolicy), + regionFilter.getSharingPolicy().get(RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE)); } @SuppressWarnings("deprecation") @Test public void testAllNamespaceForService() throws InvalidSyntaxException { - RegionFilter negateNonServices = RegionReflectionUtils.newStandardRegionFilterBuilder().allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(" + RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE + "=" + RegionFilter.VISIBLE_SERVICE_NAMESPACE + ")").build(); + RegionFilter negateNonServices = RegionReflectionUtils.newStandardRegionFilterBuilder().allow( + RegionFilter.VISIBLE_ALL_NAMESPACE, + "(" + RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE + "=" + RegionFilter.VISIBLE_SERVICE_NAMESPACE + ")") + .build(); assertFalse(negateNonServices.isAllowed(stubBundle)); assertFalse(negateNonServices.isAllowed(fooPackage)); assertFalse(negateNonServices.isAllowed(barPackage)); @@ -212,7 +233,10 @@ public class StandardRegionFilterTests { assertTrue(negateNonServices.isAllowed(barService.getReference())); assertTrue(negateNonServices.isAllowed(barServiceCapability)); - negateNonServices = RegionReflectionUtils.newStandardRegionFilterBuilder().allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(" + RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE + "=" + RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE + ")").build(); + negateNonServices = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(" + RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE + "=" + + RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE + ")") + .build(); assertFalse(negateNonServices.isAllowed(stubBundle)); assertFalse(negateNonServices.isAllowed(fooPackage)); assertFalse(negateNonServices.isAllowed(barPackage)); @@ -224,7 +248,8 @@ public class StandardRegionFilterTests { @Test public void testAllNamespace() throws InvalidSyntaxException { - RegionFilter regionFilterNotAllowed = RegionReflectionUtils.newStandardRegionFilterBuilder().allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(all=namespace)").build(); + RegionFilter regionFilterNotAllowed = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(all=namespace)").build(); assertFalse(regionFilterNotAllowed.isAllowed(stubBundle)); assertFalse(regionFilterNotAllowed.isAllowed(fooPackage)); assertFalse(regionFilterNotAllowed.isAllowed(barPackage)); @@ -233,7 +258,8 @@ public class StandardRegionFilterTests { assertFalse(regionFilterNotAllowed.isAllowed(barService.getReference())); assertFalse(regionFilterNotAllowed.isAllowed(barServiceCapability)); - RegionFilter regionFilterAllAllowed = RegionReflectionUtils.newStandardRegionFilterBuilder().allowAll(RegionFilter.VISIBLE_ALL_NAMESPACE).build(); + RegionFilter regionFilterAllAllowed = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allowAll(RegionFilter.VISIBLE_ALL_NAMESPACE).build(); assertTrue(regionFilterAllAllowed.isAllowed(stubBundle)); assertTrue(regionFilterAllAllowed.isAllowed(fooPackage)); assertTrue(regionFilterAllAllowed.isAllowed(barPackage)); @@ -246,7 +272,10 @@ public class StandardRegionFilterTests { @SuppressWarnings("deprecation") @Test public void testNegativeAllNamespace() throws InvalidSyntaxException { - RegionFilter negateServices = RegionReflectionUtils.newStandardRegionFilterBuilder().allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(!(" + RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE + "=" + RegionFilter.VISIBLE_SERVICE_NAMESPACE + "))").build(); + RegionFilter negateServices = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(!(" + RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE + "=" + + RegionFilter.VISIBLE_SERVICE_NAMESPACE + "))") + .build(); assertTrue(negateServices.isAllowed(stubBundle)); assertTrue(negateServices.isAllowed(fooPackage)); assertTrue(negateServices.isAllowed(barPackage)); @@ -255,7 +284,10 @@ public class StandardRegionFilterTests { assertFalse(negateServices.isAllowed(barService.getReference())); assertFalse(negateServices.isAllowed(barServiceCapability)); - negateServices = RegionReflectionUtils.newStandardRegionFilterBuilder().allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(!(" + RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE + "=" + RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE + "))").build(); + negateServices = RegionReflectionUtils.newStandardRegionFilterBuilder() + .allow(RegionFilter.VISIBLE_ALL_NAMESPACE, "(!(" + RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE + "=" + + RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE + "))") + .build(); assertTrue(negateServices.isAllowed(stubBundle)); assertTrue(negateServices.isAllowed(fooPackage)); assertTrue(negateServices.isAllowed(barPackage)); |