### Question:
LoginServerResource extends ServerResource implements LoginResource { @Override public Representation authenticate() { Credentials cred = getCredentialsFromQuery(); Authentication result = getAuthentication(cred); JaxbRepresentation<Authentication> resultRep = new JaxbRepresentation<Authentication>(result); resultRep.setFormattedOutput(true); return resultRep; } LoginServerResource(@Nonnull UserService userService); @Override Representation authenticate();  }### Answer:
@Test public void authenticate() throws Exception { Request req = new Request(); req.setResourceRef(""); sut.setRequest(req); sut.setQueryValue("username", USERNAME); sut.setQueryValue("passwordHash", PASSWORD); JaxbRepresentation<Authentication> resultRep = new JaxbRepresentation<Authentication>( sut.authenticate(), Authentication.class); Authentication result = resultRep.getObject(); assertEquals(result.getStatus(), "success"); assertEquals(result.getProfile().getFirstName(), FIRSTNAME); assertEquals(result.getProfile().getLastName(), LASTNAME); assertEquals(result.getProfile().isEnabled(), ENABLED); assertEquals(sut.getResponse().getStatus().getCode(), HttpStatus.SC_OK); }
@Test public void authenticateWhenUserNotFound() throws IOException { Request req = new Request(); req.setResourceRef(""); sut.setRequest(req); sut.setQueryValue("username", "notMatchUsername"); sut.setQueryValue("passwordHash", PASSWORD); JaxbRepresentation<Authentication> resultRep = new JaxbRepresentation<Authentication>( sut.authenticate(), Authentication.class); Authentication result = resultRep.getObject(); assertEquals(result.getStatus(), "fail"); assertEquals(result.getStatusInfo(), "Incorrect username or password"); assertEquals(sut.getResponse().getStatus().getCode(), HttpStatus.SC_NOT_FOUND); }