### Question:
ConsumedThing extends Thing<ConsumedThingProperty<Object>, ConsumedThingAction<Object, Object>, ConsumedThingEvent<Object>> { public Pair<ProtocolClient, Form> getClientFor(Form form, Operation op) throws ConsumedThingException { return getClientFor(List.of(form), op); } ConsumedThing(Servient servient, Thing thing); Pair<ProtocolClient, Form> getClientFor(Form form,
                                                   Operation op); Pair<ProtocolClient, Form> getClientFor(List<Form> forms,
                                                   Operation op); CompletableFuture<Map<String, Object>> readProperties(String... names); CompletableFuture<Map<String, Object>> readProperties(List<String> names); CompletableFuture<Map<String, Object>> readProperties(); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); static Form handleUriVariables(Form form, Map<String, Object> parameters);  }### Answer:
@Test public void getClientFor() throws ConsumedThingException, ProtocolClientException { when(servient.hasClientFor("test")).thenReturn(true); when(servient.getClientFor("test")).thenReturn(client); when(form1.getHrefScheme()).thenReturn("test"); ConsumedThing consumedThing = new ConsumedThing(servient, thing); Pair<ProtocolClient, Form> clientFor = consumedThing.getClientFor(form1, op); assertEquals(client, clientFor.first()); assertEquals(form1, clientFor.second()); }
@Test public void getClientForFirstInClient() throws ConsumedThingException, ProtocolClientException { when(servient.hasClientFor("test")).thenReturn(true); when(servient.getClientFor("test")).thenReturn(client); when(servient.getClientSchemes()).thenReturn(List.of("test", "bar")); when(form1.getHrefScheme()).thenReturn("bar"); when(form2.getHrefScheme()).thenReturn("test"); ConsumedThing consumedThing = new ConsumedThing(servient, thing); Pair<ProtocolClient, Form> clientFor = consumedThing.getClientFor(List.of(form1, form2), op); assertEquals(client, clientFor.first()); assertEquals(form2, clientFor.second()); }
@Test(expected = NoFormForInteractionConsumedThingException.class) public void getClientForWithUnsupportedOperation() throws ConsumedThingException, ProtocolClientException { when(servient.hasClientFor("test")).thenReturn(true); when(servient.getClientFor("test")).thenReturn(client); when(form1.getHrefScheme()).thenReturn("test"); when(form1.getOp()).thenReturn(List.of(Operation.READ_PROPERTY)); ConsumedThing consumedThing = new ConsumedThing(servient, thing); consumedThing.getClientFor(form1, Operation.WRITE_PROPERTY); }
@Test(expected = NoClientFactoryForSchemesConsumedThingException.class) public void getClientForWithUnsupportedProtocol() throws ConsumedThingException, ProtocolClientException { when(servient.hasClientFor("test")).thenReturn(true); when(servient.getClientFor("test")).thenReturn(client); when(form1.getHrefScheme()).thenReturn("http"); when(form1.getOp()).thenReturn(List.of(Operation.READ_PROPERTY)); ConsumedThing consumedThing = new ConsumedThing(servient, thing); consumedThing.getClientFor(form1, Operation.WRITE_PROPERTY); }