Extract common code in test
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/6634b5f3 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/6634b5f3 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/6634b5f3 Branch: refs/heads/model_features Commit: 6634b5f35620b3920a8385ef0fc63e6791a06b62 Parents: b9ae8bf Author: Christian Schneider <ch...@die-schneider.net> Authored: Wed Aug 9 15:51:45 2017 +0200 Committer: Christian Schneider <ch...@die-schneider.net> Committed: Thu Aug 10 15:54:06 2017 +0200 ---------------------------------------------------------------------- .../service/FeaturesServiceImplTest.java | 62 +++++++++----------- 1 file changed, 28 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/6634b5f3/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java ---------------------------------------------------------------------- diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java index 01ad34b..a5ec75a 100644 --- a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java +++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java @@ -73,32 +73,27 @@ public class FeaturesServiceImplTest extends TestBase { field.setAccessible(true); field.set(null, null); } + + @Test + public void testListFeatureWithoutVersion() throws Exception { + Feature transactionFeature = feature("transaction", "1.0.0"); + FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature); + assertNotNull(impl.getFeatures("transaction", null)); + assertSame(transactionFeature, impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)[0]); + } @Test public void testGetFeature() throws Exception { Feature transactionFeature = feature("transaction", "1.0.0"); - final Map<String, Map<String, Feature>> features = features(transactionFeature); - FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class); - EasyMock.replay(installSupport); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg ) { - protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception { - return features; - } - }; + FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature); assertNotNull(impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)); assertSame(transactionFeature, impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)[0]); } @Test public void testGetFeatureStripVersion() throws Exception { - FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) { - protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception { - return features(feature("transaction", "1.0.0")); - } - }; + Feature transactionFeature = feature("transaction", "1.0.0"); + FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature); Feature[] features = impl.getFeatures("transaction", " 1.0.0 "); assertEquals(1, features.length); Feature feature = features[0]; @@ -108,29 +103,15 @@ public class FeaturesServiceImplTest extends TestBase { @Test public void testGetFeatureNotAvailable() throws Exception { - FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) { - protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception { - return features(feature("transaction", "1.0.0")); - } - }; + Feature transactionFeature = feature("transaction", "1.0.0"); + FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature); assertEquals(0, impl.getFeatures("activemq", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION).length); } @Test public void testGetFeatureHighestAvailable() throws Exception { - final Map<String, Map<String, Feature>> features = features( - feature("transaction", "1.0.0"), - feature("transaction", "2.0.0") - ); - FeaturesServiceConfig cfg = new FeaturesServiceConfig(); - BundleInstallSupport installSupport = EasyMock.mock(BundleInstallSupport.class); - final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) { - protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception { - return features; - } - }; + FeaturesServiceImpl impl = featuresServiceWithFeatures(feature("transaction", "1.0.0"), + feature("transaction", "2.0.0")); assertNotNull(impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)); assertEquals("2.0.0", impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)[0].getVersion()); } @@ -175,6 +156,19 @@ public class FeaturesServiceImplTest extends TestBase { assertInstalled(featureService, b1Feature); } + private FeaturesServiceImpl featuresServiceWithFeatures(Feature... staticFeatures) { + final Map<String, Map<String, Feature>> features = features(staticFeatures); + FeaturesServiceConfig cfg = new FeaturesServiceConfig(); + BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class); + EasyMock.replay(installSupport); + final FeaturesServiceImpl impl = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg ) { + protected Map<String,Map<String,Feature>> getFeatureCache() throws Exception { + return features; + } + }; + return impl; + } + private FeaturesServiceImpl createTestFeatureService() { FeaturesServiceConfig cfg = new FeaturesServiceConfig(); BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class);