### Question:
StreamFilter implements Predicate<Stream> { @Override public boolean test(Stream stream) { return matchesStreamKey(stream.getKey(), keyQuery) && matchesSchemaKey(stream.getSchemaKey(), schemaKeyQuery) && matchesSpecification(stream.getSpecification(), specQuery); } StreamFilter(StreamKeyQuery keyQuery, SpecificationQuery specQuery, SchemaKeyQuery schemaKeyQuery); @Override boolean test(Stream stream); static boolean matchesStreamKey(StreamKey key, StreamKeyQuery streamKeyQuery);  }### Answer:
@Test public void filterBySpec() { TagQuery tagQuery = TagQuery.builder().nameRegex(REGEX).valueRegex(REGEX).build(); SpecificationQuery specificationQuery = SpecificationQuery.builder() .typeRegex(REGEX) .descriptionRegex(REGEX) .tags(Collections.singletonList(tagQuery)) .build(); streamFilter = new StreamFilter(null, specificationQuery, null); Stream stream = new Stream(); stream.setSpecification(matchingSpecification()); assertTrue(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().setType(FAIL); assertFalse(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().setDescription(FAIL); assertFalse(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().getTags().get(0).setName(FAIL); assertFalse(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().getTags().get(0).setValue(FAIL); assertFalse(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().setType(null); assertFalse(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().setDescription(null); assertFalse(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().getTags().get(0).setName(null); assertFalse(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().getTags().get(0).setValue(null); assertFalse(streamFilter.test(stream)); stream.setSpecification(matchingSpecification()); stream.getSpecification().setTags(null); assertFalse(streamFilter.test(stream)); }
@Test public void filterBySchema() { SchemaKeyQuery schemaKeyQuery = SchemaKeyQuery.builder() .domainRegex(REGEX) .nameRegex(REGEX) .build(); streamFilter = new StreamFilter(null, null, schemaKeyQuery); Stream stream = new Stream(); stream.setSchemaKey(matchingSchemaKey()); assertTrue(streamFilter.test(stream)); stream.setSchemaKey(matchingSchemaKey()); stream.getSchemaKey().setDomain(FAIL); assertFalse(streamFilter.test(stream)); stream.setSchemaKey(matchingSchemaKey()); stream.getSchemaKey().setName(FAIL); assertFalse(streamFilter.test(stream)); stream.setSchemaKey(matchingSchemaKey()); stream.getSchemaKey().setName(null); assertFalse(streamFilter.test(stream)); stream.setSchemaKey(matchingSchemaKey()); stream.getSchemaKey().setDomain(null); assertFalse(streamFilter.test(stream)); }
@Test public void filterByStreamKey() { StreamKeyQuery streamKeyQuery = StreamKeyQuery.builder() .domainRegex(REGEX) .nameRegex(REGEX) .version(1) .build(); streamFilter = new StreamFilter(streamKeyQuery, null, null); Stream stream = new Stream(); stream.setKey(matchingStreamKey()); assertTrue(streamFilter.test(stream)); stream.setKey(matchingStreamKey()); stream.getKey().setDomain(FAIL); assertFalse(streamFilter.test(stream)); stream.setKey(matchingStreamKey()); stream.getKey().setName(FAIL); assertFalse(streamFilter.test(stream)); stream.setKey(matchingStreamKey()); stream.getKey().setVersion(2); assertFalse(streamFilter.test(stream)); stream.setKey(matchingStreamKey()); stream.getKey().setVersion(null); assertFalse(streamFilter.test(stream)); }