SystemUsersResource extends AbstractJaxRSResource { @GET @Produces ( { MediaType.APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Response object containing an xml list of the users in the platform." ), @ResponseCode ( code = 403, condition = "Response due to the requesting user not having sufficient privileges." ), @ResponseCode ( code = 500, condition = "Internal server error occurs when the server cannot retrieve the list of users." ) } ) public Response getUsers() throws Exception { try { return buildOkResponse( getSystemService().getUsers().asXML(), MediaType.APPLICATION_XML ); } catch ( IllegalAccessException exception ) { return Response.status( UNAUTHORIZED ).build(); } catch ( ServletException exception ) { return Response.status( INTERNAL_SERVER_ERROR ).build(); } catch ( IOException exception ) { return Response.status( INTERNAL_SERVER_ERROR ).build(); } }  @GET @Produces ( { MediaType.APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Response object containing an xml list of the users in the platform." ), @ResponseCode ( code = 403, condition = "Response due to the requesting user not having sufficient privileges." ), @ResponseCode ( code = 500, condition = "Internal server error occurs when the server cannot retrieve the list of users." ) } ) Response getUsers();  }
@Test public void testGetUsers() throws Exception { SystemService mockSystemService = mock( SystemService.class ); doReturn( mockSystemService ).when( systemUsersResource ).getSystemService(); Document mockDocument = mock( Document.class ); doReturn( mockDocument ).when( mockSystemService ).getUsers(); String xml = "xml"; doReturn( xml ).when( mockDocument ).asXML(); Response mockResponse = mock( Response.class ); doReturn( mockResponse ).when( systemUsersResource ).buildOkResponse( xml, MediaType.APPLICATION_XML ); Response testResponse = systemUsersResource.getUsers(); assertEquals( mockResponse, testResponse ); verify( systemUsersResource, times( 1 ) ).getSystemService(); verify( mockSystemService, times( 1 ) ).getUsers(); verify( mockDocument, times( 1 ) ).asXML(); verify( systemUsersResource, times( 1 ) ).buildOkResponse( xml, MediaType.APPLICATION_XML ); }