KataService { public Response handleRequest(Request request) throws IllegalAccessException { if (!singleSignOnRegistry.is_valid(request.getSSOToken())) { throw new IllegalAccessException("SSO token is invalid"); } return new Response("Hello " + request.getName()); } KataService(SingleSignOnRegistry singleSignOnRegistry); Response handleRequest(Request request);  }
@Test public void with_valid_credential_and_eric_name_should_return_hello_eric() throws IllegalAccessException { SSOToken validCredentials = new SSOToken(); doReturn(true).when(singleSignOnRegistry).is_valid(validCredentials); Response response = kataService.handleRequest(new Request("Éric", validCredentials)); assertThat(response.getText()).isEqualTo("Hello Éric"); }
@Test(expected = IllegalAccessException.class) public void with_invalid_credentials_should_deny_access() throws IllegalAccessException { SSOToken invalidCredentials = new SSOToken(); doReturn(false).when(singleSignOnRegistry).is_valid(invalidCredentials); kataService.handleRequest(new Request("Éric", invalidCredentials)); }