Last active
November 4, 2015 21:49
-
-
Save Pacane/d9fc72e469ee4eb53f7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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