Skip to content

Instantly share code, notes, and snippets.

@Pacane
Last active November 4, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pacane/d9fc72e469ee4eb53f7b to your computer and use it in GitHub Desktop.
Save Pacane/d9fc72e469ee4eb53f7b to your computer and use it in GitHub Desktop.
@RunWith(JukitoRunner.class)
public class EndpointTestWithJukito {
private final String A_USERNAME = "Bobby";
private final int USER_ID = 1337;
@Inject
private UserInformationService userInformationService;
@Inject
private ResponseFactory responseFactory;
@Inject
private Endpoint endpoint;
@Test
public void getUsername_delegatesToUserInformationService() {
endpoint.getUsername(USER_ID);
verify(userInformationService).getUsername(USER_ID);
}
@Test
public void getUsername_returnsOkWhenUserIsFound() {
Response OK_RESPONSE = new OkResponse();
given(responseFactory.createOk(A_USERNAME)).willReturn(OK_RESPONSE);
given(userInformationService.getUsername(USER_ID)).willReturn(A_USERNAME);
Response result = endpoint.getUsername(USER_ID);
assertThat(result).isSameAs(OK_RESPONSE);
}
@Test
public void getUser_returnsNotFoundWhenUserIsNotFound() {
Response NOT_FOUND_RESPONSE = new NotFoundResponse();
given(responseFactory.createNotFound()).willReturn(NOT_FOUND_RESPONSE);
given(userInformationService.getUsername(USER_ID)).willThrow(NotFoundException.class);
Response result = endpoint.getUsername(USER_ID);
assertThat(result).isSameAs(NOT_FOUND_RESPONSE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment