### Question:
JadexProtocolClient implements ProtocolClient { @Override public Observable<Thing> discover(ThingFilter filter) { return Observable .<ThingService>create(source -> platform.scheduleStep(ia -> { ServiceQuery<ThingService> query = new ServiceQuery<>(ThingService.class, ServiceScope.GLOBAL); ITerminableIntermediateFuture<ThingService> search = ia.searchServices(query); search.addIntermediateResultListener(source::onNext, source::onComplete, source::onError); return DONE; })) .flatMap(thingService -> Observable.<Thing>create(source -> thingService.get().addResultListener(json -> { source.onNext(Thing.fromJson(json)); source.onComplete(); }, source::onError))) .filter(thing -> { if (filter.getQuery() != null) { return !filter.getQuery().filter(List.of(thing)).isEmpty(); } else { return true; } }); } JadexProtocolClient(IExternalAccess platform); @Override CompletableFuture<Content> readResource(Form form); @Override CompletableFuture<Content> writeResource(Form form, Content content); @Override Observable<Thing> discover(ThingFilter filter);  }### Answer:
@Test public void discoverShouldReturnFoundThings() { when(platform.scheduleStep(any())).then(invocationOnMock -> { IComponentStep step = invocationOnMock.getArgument(0, IComponentStep.class); step.execute(internalPlatform); return null; }); when(internalPlatform.searchServices(any())).thenReturn(searchFuture); doAnswer(invocationOnMock -> { IFunctionalIntermediateResultListener resultListener = invocationOnMock.getArgument(0, IFunctionalIntermediateResultListener.class); IFunctionalIntermediateFinishedListener finishedListener = invocationOnMock.getArgument(1, IFunctionalIntermediateFinishedListener.class); resultListener.intermediateResultAvailable(thingService); finishedListener.finished(); return null; }).when(searchFuture).addIntermediateResultListener(any(), any(), any()); when(thingService.get()).thenReturn(thingServiceFuture); doAnswer(invocationOnMock -> { IFunctionalResultListener resultListener = invocationOnMock.getArgument(0, IFunctionalResultListener.class); resultListener.resultAvailable("{\"id\":\"counter\",\"title\":\"Zähler\"}"); return null; }).when(thingServiceFuture).addResultListener(any(), any()); client = new JadexProtocolClient(platform); @NonNull List<Thing> things = client.discover(filter).toList().blockingGet(); assertThat(things, hasItem(new Thing.Builder().setId("counter").setTitle("Zähler").build())); }