OperationSupportCheckerImpl implements OperationSupportChecker { @Override public <T> Collection<T> filter(Collection<T> input, Function<T, CloudType> cloudTypeProvider, OperationType operationType) { return input.stream() .filter(elem -> { CloudType cloudType = cloudTypeProvider.apply(elem); return isOperationSupported(cloudType, operationType); }) .collect(Collectors.toList()); } @Autowired  OperationSupportCheckerImpl(ServiceRepository serviceRepository); @Override boolean isOperationSupported(CloudType cloudType, OperationType operationType); @Override Collection<T> filter(Collection<T> input, Function<T, CloudType> cloudTypeProvider, OperationType operationType);  }
@Test public void testFilter() { Instance firstInstance = EntityGenerator.getInstance(); List<Instance> instances = new ArrayList<Instance>() { { add(firstInstance); Instance secondInstance = EntityGenerator.getInstance(); secondInstance.setCloudType(DOCKER); } }; Collection<Instance> filteredInstances = operationSupportChecker.filter( instances, Instance::getCloudType, ADD_IMAGE ); assertThat(filteredInstances, contains(firstInstance)); }