PolicyConverterRegistry { @NotNull public PolicyConverter getFromPolicyElement(String name, Element policy) { return policyConverters.stream() .filter(converter -> converter.canConvert(name, policy)) .findFirst().orElseGet(() -> getConverterFromFileName(XMLPolicyConverter.EXTENSION)); } @Inject  PolicyConverterRegistry(final Set<PolicyConverter> converters); @NotNull boolean isValidPolicyExtension(String fileName); @NotNull PolicyConverter getConverterFromFileName(String fileName); @NotNull PolicyConverter getFromPolicyElement(String name, Element policy);  }
@Test void getFromPolicyElement() { PolicyConverterTest textExtConverter = new PolicyConverterTest(".test.ext", "hello"); PolicyConverterTest defaultConverter = new PolicyConverterTest(".xml", "default-converter"); PolicyConverterRegistry policyConverterRegistry = new PolicyConverterRegistry(ImmutableSet.of(textExtConverter, defaultConverter)); assertEquals(textExtConverter, policyConverterRegistry.getFromPolicyElement("hello", null)); assertEquals(defaultConverter, policyConverterRegistry.getFromPolicyElement("another-name", null)); }