### Question:
Servient { public CompletableFuture<ExposedThing> expose(String id) { ExposedThing thing = things.get(id); if (servers.isEmpty()) { return failedFuture(new ServientException("Servient has no servers to expose Things")); } if (thing == null) { return failedFuture(new ServientException("Thing must be added to the servient first")); } log.info("Servient exposing '{}'", id); thing.setBase(""); Map<String, ExposedThingProperty<Object>> properties = thing.getProperties(); properties.forEach((n, p) -> p.setForms(new ArrayList<>())); Map<String, ExposedThingAction<Object, Object>> actions = thing.getActions(); actions.forEach((n, a) -> a.setForms(new ArrayList<>())); Map<String, ExposedThingEvent<Object>> events = thing.getEvents(); events.forEach((n, e) -> e.setForms(new ArrayList<>())); CompletableFuture<Void>[] serverFutures = getServers().stream().map(s -> s.expose(thing)).toArray(CompletableFuture[]::new); return CompletableFuture.allOf(serverFutures).thenApply(result -> thing); } 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 expose() throws InterruptedException, ExecutionException { when(server.expose(any())).thenReturn(completedFuture(null)); Servient servient = new Servient(List.of(server), Map.of(), Map.of(), Map.of("counter", exposedThing)); assertThat(servient.expose("counter").get(), is(exposedThing)); verify(server).expose(exposedThing); }
@Test(expected = ServientException.class) public void exposeWithoutServers() throws Throwable { Servient servient = new Servient(List.of(), Map.of(), Map.of(), Map.of("counter", exposedThing)); try { servient.expose("counter").get(); } catch (ExecutionException e) { throw e.getCause(); } }
@Test(expected = ServientException.class) public void exposeUnknownThing() throws Throwable { Servient servient = new Servient(List.of(), Map.of(), Map.of(), Map.of()); try { servient.expose("counter").get(); } catch (ExecutionException e) { throw e.getCause(); } }