@Override public MutationInterceptor createInterceptor(InterceptorParameters params) { final Optional<Integer> max = params.getInteger(this.limit); if (!max.isPresent()) { throw new IllegalArgumentException("Max mutation per class filter requires a limit parameter"); } return new LimitNumberOfMutationPerClassFilter(max.get()); }
public Optional<Integer> getInteger(FeatureParameter key) { final Optional<String> val = getString(key); if (val.isPresent()) { return Optional.ofNullable(Integer.parseInt(val.get())); } return Optional.empty(); }
@Test public void shouldReturnNoneWhenFeatureSettingsAbsent() { this.testee = new InterceptorParameters(null, null, null); assertThat(this.testee.getString(FeatureParameter.named("foo"))).isEqualTo(Optional.empty()); }
private InterceptorParameters makeFor(String key, String ... vals) { final Map<String, List<String>> values = new HashMap<>(); values.put(key, Arrays.asList(vals)); final FeatureSetting fs = new FeatureSetting(null, null,values); return new InterceptorParameters(fs, null, null); }
@Override public MutationInterceptor createInterceptor(InterceptorParameters params) { return new LoggingCallsFilter(params.data().getLoggingClasses()); }
private static Function<MutationInterceptorFactory, MutationInterceptor> toInterceptor( final FeatureSelector<MutationInterceptorFactory> features, final ReportOptions data, final ClassByteArraySource source) { return a -> a.createInterceptor(new InterceptorParameters(features.getSettingForFeature(a.provides().name()), data, source)); } }
@Override public MutationInterceptor createInterceptor(InterceptorParameters params) { if (params.data().isDetectInlinedCode()) { return new InlinedFinallyBlockFilter(); } return CompoundMutationInterceptor.nullInterceptor(); }
@Test public void shouldReturnListsOfStringsWhenPresent() { this.testee = makeFor("foo", "bar", "car"); assertThat(this.testee.getList(FeatureParameter.named("foo"))).contains("bar", "car"); }
@Test public void shouldReturnNoneWhenValueAbsent() { this.testee = makeFor("nomatch", "bar"); assertThat(this.testee.getString(FeatureParameter.named("foo"))).isEqualTo(Optional.empty()); }
@Test public void shouldReturnIntegerWhenPresent() { this.testee = makeFor("foo", "11"); assertThat(this.testee.getInteger(FeatureParameter.named("foo"))).isEqualTo(Optional.ofNullable(11)); }
@Override public MutationInterceptor createInterceptor(InterceptorParameters interceptorParameters) { Set<String> matchers = availabeMatchers.keySet(); List<String> exclusions = interceptorParameters.getList(EXCEPT); if(exclusions != null) matchers.removeAll(exclusions); return new StopMethodInterceptor( StopMethodMatcher.any( matchers.stream() .map(key -> availabeMatchers.get(key)) .collect(Collectors.toList()) ) ); }
@Test public void shouldReturnStringParamsWhenPresent() { this.testee = makeFor("foo", "bar"); assertThat(this.testee.getString(FeatureParameter.named("foo"))).isEqualTo(Optional.ofNullable("bar")); }