### Question:
RestrictionQualifier implements Qualifier<T> { @Override public Stream<ComponentDescriptor<T>> filter(final Class<T> componentType, final Stream<ComponentDescriptor<T>> candidates) { return candidates.filter(this::isRestricted); } RestrictionQualifier(final Restriction restriction); @Override Stream<ComponentDescriptor<T>> filter(final Class<T> componentType,
                                                 final Stream<ComponentDescriptor<T>> candidates); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final String TYPE_MEMBER; static final String NAMES_MEMBER; }### Answer:
@Test public void shouldAcceptGivenComponentDescriptorWithNoRestrictionWhenRestrictionIsApplication() { RestrictionQualifier<Object> qualifier = new RestrictionQualifier<>(Restriction.application()); List<ComponentDescriptor<Object>> filtered = qualifier.filter(Object.class, Stream.of(descriptor)) .collect(Collectors.toList()); assertEquals(1, filtered.size()); }
@Test public void shouldNotAcceptGivenNonMatchingComponentDescriptor() { RestrictionQualifier<Object> qualifier = new RestrictionQualifier<>(Restriction.streams("test")); List<ComponentDescriptor<Object>> filtered = qualifier.filter(Object.class, Stream.of(descriptor)) .collect(Collectors.toList()); assertTrue(filtered.isEmpty()); }
@Test public void shouldNotAcceptGivenRestrictionMatchingComponentDescriptor() { RestrictionQualifier<Object> qualifier = new RestrictionQualifier<>(Restriction.streams("test")); ComponentAttribute restriction = new ComponentAttribute("restricted"); restriction.add("type", Restriction.TYPE_STREAMS); restriction.add("names", new String[]{"test"}); descriptor.metadata().addAttribute(restriction); List<ComponentDescriptor<Object>> filtered = qualifier.filter(Object.class, Stream.of(descriptor)) .collect(Collectors.toList()); assertEquals(1, filtered.size()); }