### Question:
AkkaProtocolClient implements ProtocolClient { @SuppressWarnings("squid:S1192") @Override public CompletableFuture<Content> readResource(Form form) { return request(form, resourceIdentifier -> { if (resourceIdentifier.length == 2 && resourceIdentifier[0].equals("properties")) { return new ReadProperty(resourceIdentifier[1]); } else if (resourceIdentifier.length == 2 && resourceIdentifier[0].equals("all") && resourceIdentifier[1].equals("properties")) { return new ReadAllProperties(); } else if (resourceIdentifier.length == 1 && resourceIdentifier[0].equals("thing")) { return new GetThingDescription(); } else if (resourceIdentifier.length == 1 && resourceIdentifier[0].equals("thing-directory")) { return new GetThings(); } else { return null; } }); } AkkaProtocolClient(ActorSystem system,
                              Duration askTimeout,
                              Duration discoverTimeout);   AkkaProtocolClient(ActorSystem system,
                       Duration askTimeout,
                       Duration discoverTimeout,
                       AkkaProtocolPattern pattern); @SuppressWarnings("squid:S1192") @Override CompletableFuture<Content> readResource(Form form); @Override CompletableFuture<Content> writeResource(Form form, Content content); @Override CompletableFuture<Content> invokeResource(Form form, Content content); @Override Observable<Content> observeResource(Form form); @Override Observable<Thing> discover(ThingFilter filter);  }### Answer:
@Test public void readResourceShouldUseCorrectMessageToReadProperty() { when(form.getHref()).thenReturn("akka: when(system.actorSelection(anyString())).thenReturn(actorSelection); when(pattern.ask(any(ActorSelection.class), any(), any())).thenReturn(completedFuture(message)); AkkaProtocolClient client = new AkkaProtocolClient(system, askTimeout, discoverTimeout, pattern); client.readResource(form); verify(pattern).ask(any(ActorSelection.class), any(ReadProperty.class), any()); }
@Test public void readResourceShouldUseCorrectMessageToReadAllProperties() { when(form.getHref()).thenReturn("akka: when(system.actorSelection(anyString())).thenReturn(actorSelection); when(pattern.ask(any(ActorSelection.class), any(), any())).thenReturn(completedFuture(message)); AkkaProtocolClient client = new AkkaProtocolClient(system, askTimeout, discoverTimeout, pattern); client.readResource(form); verify(pattern).ask(any(ActorSelection.class), any(ReadAllProperties.class), any()); }
@Test public void readResourceShouldUseCorrectMessageToGetThingDescription() { when(form.getHref()).thenReturn("akka: when(system.actorSelection(anyString())).thenReturn(actorSelection); when(pattern.ask(any(ActorSelection.class), any(), any())).thenReturn(completedFuture(message)); AkkaProtocolClient client = new AkkaProtocolClient(system, askTimeout, discoverTimeout, pattern); client.readResource(form); verify(pattern).ask(any(ActorSelection.class), any(GetThingDescription.class), any()); }
@Test public void readResourceShouldUseCorrectMessageToGetThings() { when(form.getHref()).thenReturn("akka: when(system.actorSelection(anyString())).thenReturn(actorSelection); when(pattern.ask(any(ActorSelection.class), any(), any())).thenReturn(completedFuture(message)); AkkaProtocolClient client = new AkkaProtocolClient(system, askTimeout, discoverTimeout, pattern); client.readResource(form); verify(pattern).ask(any(ActorSelection.class), any(GetThings.class), any()); }