### Question:
JDBCDatasourceResource { @GET @Path( "/{name : .+}" ) @Produces( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully retrieved the JDBC datasource" ), @ResponseCode( code = 500, condition = "An error occurred retrieving the JDBC datasource" ) } ) public Response getConnection( @PathParam( "name" ) String name ) { try { IDatabaseConnection connection = service.getConnectionByName( name ); connection.setPassword( null ); return Response.ok( connection ).build(); } catch ( ConnectionServiceException e ) { logger.error( "Error " + e.getMessage() ); return Response.serverError().build(); } } JDBCDatasourceResource(); @DELETE @Path( "/{name : .+}" ) @StatusCodes( { @ResponseCode( code = 204, condition = "JDBC datasource removed successfully." ), @ResponseCode( code = 304, condition = "User is not authorized to remove the JDBC datasource or the connection does not exist." ), @ResponseCode( code = 500, condition = "An unexpected error occurred while deleting the JDBC datasource." ) } ) Response deleteConnection( @PathParam( "name" ) String name ); @GET @Path( "/" ) @Produces( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully retrieved the list of JDBC datasource IDs" ), @ResponseCode( code = 500, condition = "Internal error retrieving JDBC datasource IDs" ) } ) JaxbList<String> getConnectionIDs(); @GET @Path( "/{name : .+}" ) @Produces( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully retrieved the JDBC datasource" ), @ResponseCode( code = 500, condition = "An error occurred retrieving the JDBC datasource" ) } ) Response getConnection( @PathParam( "name" ) String name ); @PUT @Path( "/{connectionId : .+}" ) @Consumes( { APPLICATION_JSON } ) @StatusCodes( { @ResponseCode( code = 204, condition = "JDBC datasource added successfully." ), @ResponseCode( code = 401, condition = "User is not authorized to add JDBC datasources." ), @ResponseCode( code = 304, condition = "Datasource was not modified" ), @ResponseCode( code = 500, condition = "An unexpected error occurred while adding the JDBC datasource." ) } ) Response addOrUpdate( @PathParam( "connectionId" ) String connectionName, DatabaseConnection connection );  }### Answer:
@Test public void testGetConnection() throws Exception { doReturn( connection ).when( service ).getConnectionByName( "Name" ); Response response = resource.getConnection( "Name" ); assertEquals( "Name", ( (IDatabaseConnection) response.getEntity() ).getName() ); assertNull( ( (IDatabaseConnection) response.getEntity() ).getPassword() ); assertEquals( Response.Status.OK.getStatusCode(), response.getStatus() ); verify( service, times( 1 ) ).getConnectionByName( "Name" ); }
@Test public void testGetConnectionError() throws Exception { doThrow( mock( ConnectionServiceException.class ) ).when( service ).getConnectionByName( "Name" ); assertEquals( Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resource.getConnection( "Name" ).getStatus() ); verify( service, times( 1 ) ).getConnectionByName( "Name" ); }