### Question:
EncodedCharactersFilter extends ZuulFilter { @Override public boolean shouldFilter() { boolean shouldFilter = true; RequestContext context = RequestContext.getCurrentContext(); final String serviceId = (String) context.get(SERVICE_ID_KEY); List<ServiceInstance> instanceList = discoveryClient.getInstances(serviceId); List<Map<String, String>> enabledList = instanceList.stream() .map(ServiceInstance::getMetadata) .filter(metadata -> metadata.get(METADATA_KEY) == null || String.valueOf(true).equalsIgnoreCase(metadata.get(METADATA_KEY))) .collect(Collectors.toList()); if (enabledList.size() == instanceList.size()) { shouldFilter = false; } return shouldFilter; }  @Override String filterType(); @Override int filterOrder(); @Override boolean shouldFilter(); @Override Object run(); static final String METADATA_KEY; }### Answer:
@Test void givenSingleInstance_WhenConfiguredFalse_ShouldFilter() { List<ServiceInstance> instanceList = new ArrayList<>(); instanceList.add(serviceInstanceWithFalseConfiguration); when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(instanceList); assertThat(filter.shouldFilter(), is(equalTo(true))); }
@Test void givenSingleInstance_WhenConfiguredTrue_ShouldNotFilter() { List<ServiceInstance> instanceList = new ArrayList<>(); instanceList.add(serviceInstanceWithTrueConfiguration); when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(instanceList); assertThat(filter.shouldFilter(), is(equalTo(false))); }
@Test void givenSingleInstance_WhenNotConfigured_ShouldNotFilter() { List<ServiceInstance> instanceList = new ArrayList<>(); instanceList.add(serviceInstanceWithNoConfiguration); when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(instanceList); assertThat(filter.shouldFilter(), is(equalTo(false))); }
@Test void givenMultipleInstances_WhenMixedSetup_ShouldBePessimistic() { List<ServiceInstance> instanceList = new ArrayList<>(); instanceList.add(serviceInstanceWithFalseConfiguration); instanceList.add(serviceInstanceWithTrueConfiguration); when(discoveryClient.getInstances(SERVICE_ID)).thenReturn(instanceList); assertThat(filter.shouldFilter(), is(equalTo(true))); }