### Question:
Servient { public Observable<Thing> discover() throws ServientException { return discover(new ThingFilter(DiscoveryMethod.ANY)); } Servient();  Servient(Config config);  Servient(ServientConfig config);   Servient(List<ProtocolServer> servers,
             Map<String, ProtocolClientFactory> clientFactories,
             Map<String, Object> credentialStore,
             Map<String, ExposedThing> things); @Override String toString(); List<ProtocolServer> getServers(); CompletableFuture<Void> start(); CompletableFuture<Void> shutdown(); CompletableFuture<ExposedThing> expose(String id); CompletableFuture<ExposedThing> destroy(String id); boolean addThing(ExposedThing exposedThing); CompletableFuture<Thing> fetch(String url); CompletableFuture<Thing> fetch(URI url); ProtocolClient getClientFor(String scheme); boolean hasClientFor(String scheme); CompletableFuture<Map<String, Thing>> fetchDirectory(String url); CompletableFuture<Map<String, Thing>> fetchDirectory(URI url); CompletableFuture<Void> register(String directory,
                                            ExposedThing thing); CompletableFuture<Void> unregister(String directory,
                                              ExposedThing thing); Observable<Thing> discover(); Observable<Thing> discover(ThingFilter filter); Map<String, ExposedThing> getThings(); T getServer(Class<T> server); Object getCredentials(String id); CompletableFuture<Void> runScript(File file, Wot wot); CompletableFuture<Void> runPrivilegedScript(File file, Wot wot); List<String> getClientSchemes(); static Set<String> getAddresses(); static Servient clientOnly(Config config); static Servient serverOnly(Config config); static String getVersion();  }### Answer:
@Test public void discoverShouldCallUnderlyingClient() throws ServientException { when(clientFactory.getClient()).thenReturn(client); when(client.discover(any())).thenReturn(Observable.just(thing)); Servient servient = new Servient(List.of(), Map.of("test", clientFactory), Map.of(), Map.of()); servient.discover(); verify(client).discover(any()); }
@Test public void discoverWithQueryShouldCallUnderlyingClient() throws ServientException { ThingFilter filter = new ThingFilter().setQuery(new SparqlThingQuery("?x <http: when(clientFactory.getClient()).thenReturn(client); when(client.discover(any())).thenReturn(Observable.just(thing)); Servient servient = new Servient(List.of(), Map.of("test", clientFactory), Map.of(), Map.of()); servient.discover(filter); verify(client).discover(filter); }
@Test public void discoverDirectoryShouldAccessDirectoryWithUnderlyingClient() throws URISyntaxException, ServientException { when(clientFactory.getClient()).thenReturn(client); when(client.readResource(any())).thenReturn(completedFuture(null)); Servient servient = new Servient(List.of(), Map.of("test", clientFactory), Map.of(), Map.of()); ThingFilter filter = new ThingFilter().setMethod(DiscoveryMethod.DIRECTORY).setUrl(new URI("test:/")); servient.discover(filter); verify(client).readResource(new Form.Builder().setHref("test:/").build()); }
@Test(expected = ProtocolClientNotImplementedException.class) public void discoverWithNoClientImplementsDiscoverShouldFail() throws ServientException { Servient servient = new Servient(List.of(), Map.of(), Map.of(), Map.of()); servient.discover(); }
@Test public void discoverWithAtLeastOneClientImplementingDiscoverShouldSucceed() throws Throwable { when(exposedThing.getId()).thenReturn("counter"); when(clientFactory.getClient()).thenReturn(client); when(client.discover(any())).thenReturn(Observable.just(exposedThing)); Servient servient = new Servient(List.of(), Map.of("test", clientFactory), Map.of(), Map.of()); @NonNull List<Thing> things = servient.discover().toList().blockingGet(); assertThat(things, hasItem(exposedThing)); }