EnumBasedFeatureProvider implements FeatureProvider { @Override public Set<Feature> getFeatures() { if (this.features == null){ return Collections.emptySet(); } return Collections.unmodifiableSet(features); } EnumBasedFeatureProvider();  EnumBasedFeatureProvider(Class<? extends Feature>... featureEnums); EnumBasedFeatureProvider addFeatureEnum(Class<? extends Feature> featureEnum); @Override Set<Feature> getFeatures(); @Override FeatureMetaData getMetaData(Feature feature);  }
@Test public void shouldReturnCorrectListOfFeaturesForEnum() { FeatureProvider provider = new EnumBasedFeatureProvider(ValidFeatureEnum.class); assertEquals(provider.getFeatures().toArray()[0], ValidFeatureEnum.FEATURE1); assertEquals(provider.getFeatures().toArray()[1], ValidFeatureEnum.FEATURE2); }
@Test public void shouldReturnCombinedFeatureListForMultipleEnumsViaConstructor() { FeatureProvider provider = new EnumBasedFeatureProvider(ValidFeatureEnum.class, OtherFeatureEnum.class); assertEquals(ValidFeatureEnum.values().length + OtherFeatureEnum.values().length, provider.getFeatures().size()); assertTrue(provider.getFeatures().contains(ValidFeatureEnum.FEATURE1)); assertTrue(provider.getFeatures().contains(OtherFeatureEnum.ADDITIONAL_FEATURE)); }
@Test public void providerShouldNotEagerlyCreateFeaturesSet() { FeatureProvider provider = new EnumBasedFeatureProvider(); assertEquals(0, provider.getFeatures().size()); }