MyService { public Response handleRequest(Request request) { if (request.getSSOToken() == null) { return new Response("sso token is not defined"); } boolean isRegistryValid = this.registry.is_valid(request.getSSOToken()); if (!isRegistryValid) { return new Response("sso token is invalid"); } return new Response("hello " + request.getName() + "!"); } MyService(SingleSignOnRegistry registry); Response handleRequest(Request request);  }
@Test public void undefinedSSOTokenIsRejected() { Response response = myService.handleRequest(new Request("Foo", null)); assertEquals("sso token is not defined", response.getText()); }
@Test public void invalidSSOTokenIsRejected() { Response response = myService.handleRequest(new Request("Foo", new SSOToken())); assertEquals("sso token is invalid", response.getText()); }
@Test public void validSSOTokenIsAccepted() { SSOToken ssoToken = new SSOToken(); Mockito.doReturn(true).when(kataSingleSignOnRegistry).is_valid(ssoToken); Response response = myService.handleRequest(new Request("Foo", ssoToken)); assertEquals("hello Foo!", response.getText()); }