### Question:
AbstractNiFiTemplatesRestClient implements NiFiTemplatesRestClient { @Nonnull @Override public Set<TemplateDTO> findByInputPortName(@Nonnull final String inputPortName) { return findAll().stream() .map(template -> findById(template.getId())) .filter(template -> { final Set<PortDTO> ports = template .map(TemplateDTO::getSnippet) .map(FlowSnippetDTO::getInputPorts) .orElse(Collections.emptySet()); return ports.stream() .filter(port -> port.getName().equalsIgnoreCase(inputPortName)) .findFirst() .isPresent(); }) .map(Optional::get) .collect(Collectors.toSet()); }  @Nonnull @Override TemplateDTO create(@Nullable final String name, @Nonnull final String xml); @Nonnull @Override Set<TemplateDTO> findByInputPortName(@Nonnull final String inputPortName); @Nonnull @Override Optional<TemplateDTO> findByName(@Nonnull final String name);  }### Answer:
@Test public void findByInputPortName() { final TemplateDTO basicTemplate1 = new TemplateDTO(); basicTemplate1.setId("cf54ca27-ccb0-49a1-94f2-2834c4379b70"); final TemplateDTO basicTemplate2 = new TemplateDTO(); basicTemplate2.setId("43ce4a07-10ac-40c0-b195-598bc753988b"); final TemplateDTO basicTemplate3 = new TemplateDTO(); basicTemplate3.setId("7f57c685-f9dd-497e-8e97-7d1e6d43b59c"); final PortDTO port1 = new PortDTO(); port1.setId("ee77fc99-2f19-43d3-ae26-091f9caa1401"); port1.setName("to-other-template"); final PortDTO port2 = new PortDTO(); port2.setId("1b2a3c92-1964-4f87-9835-b8a19f024249"); port2.setName("to-standard-ingest"); final FlowSnippetDTO flow1 = new FlowSnippetDTO(); flow1.setInputPorts(ImmutableSet.of(port1)); final FlowSnippetDTO flow2 = new FlowSnippetDTO(); flow2.setInputPorts(ImmutableSet.of(port2)); final TemplateDTO fullTemplate1 = new TemplateDTO(); fullTemplate1.setId("cf54ca27-ccb0-49a1-94f2-2834c4379b70"); fullTemplate1.setSnippet(flow1); final TemplateDTO fullTemplate2 = new TemplateDTO(); fullTemplate2.setId("43ce4a07-10ac-40c0-b195-598bc753988b"); fullTemplate2.setSnippet(flow2); final NiFiTemplatesRestClient client = Mockito.mock(AbstractNiFiTemplatesRestClient.class, Mockito.CALLS_REAL_METHODS); Mockito.when(client.findAll()).thenReturn(ImmutableSet.of(basicTemplate1, basicTemplate2, basicTemplate3)); Mockito.when(client.findById("cf54ca27-ccb0-49a1-94f2-2834c4379b70")).thenReturn(Optional.of(fullTemplate1)); Mockito.when(client.findById("43ce4a07-10ac-40c0-b195-598bc753988b")).thenReturn(Optional.of(fullTemplate2)); Mockito.when(client.findById("7f57c685-f9dd-497e-8e97-7d1e6d43b59c")).thenReturn(Optional.empty()); final Set<TemplateDTO> matches = client.findByInputPortName("to-standard-ingest"); Assert.assertEquals(fullTemplate2, matches.stream().findFirst().get()); Assert.assertEquals(0, client.findByInputPortName("invalid").size()); }