### Question:
HealthController { @ResponseBody @RequestMapping(value = "readiness", method = RequestMethod.GET) public ResponseEntity readiness(HttpServletRequest request) { boolean isConfigReadiness = isConfigReadiness(); boolean isNamingReadiness = isNamingReadiness(request); if (isConfigReadiness && isNamingReadiness) { return ResponseEntity.ok().body("OK"); } if (!isConfigReadiness && !isNamingReadiness) { return ResponseEntity.status(500).body("Config and Naming are not in readiness"); } if (!isConfigReadiness) { return ResponseEntity.status(500).body("Config is not in readiness"); } return ResponseEntity.status(500).body("Naming is not in readiness"); } @Autowired  HealthController(PersistService persistService, ApiCommands apiCommands); @ResponseBody @RequestMapping(value = "liveness", method = RequestMethod.GET) ResponseEntity liveness(); @ResponseBody @RequestMapping(value = "readiness", method = RequestMethod.GET) ResponseEntity readiness(HttpServletRequest request);  }### Answer:
@Test public void testReadiness() throws Exception { String url = "/v1/console/health/readiness"; Mockito.when(persistService.configInfoCount(any(String.class))).thenReturn(0); Mockito.when(apiCommands.hello(any(HttpServletRequest.class))).thenReturn(new JSONObject()); MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(url); Assert.assertEquals(200, mockmvc.perform(builder).andReturn().getResponse().getStatus()); Mockito.when(persistService.configInfoCount(any(String.class))).thenThrow( new RuntimeException("HealthControllerTest.testReadiness")); Mockito.when(apiCommands.hello(any(HttpServletRequest.class))).thenThrow( new RuntimeException("HealthControllerTest.testReadiness")); builder = MockMvcRequestBuilders.get(url); MockHttpServletResponse response = mockmvc.perform(builder).andReturn().getResponse(); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals("Config and Naming are not in readiness", response.getContentAsString()); Mockito.when(persistService.configInfoCount(any(String.class))).thenThrow( new RuntimeException("HealthControllerTest.testReadiness")); Mockito.when(apiCommands.hello(any(HttpServletRequest.class))).thenReturn(new JSONObject()); response = mockmvc.perform(builder).andReturn().getResponse(); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals("Config is not in readiness", response.getContentAsString()); Mockito.when(persistService.configInfoCount(any(String.class))).thenReturn(0); Mockito.when(apiCommands.hello(any(HttpServletRequest.class))).thenThrow( new RuntimeException("HealthControllerTest.testReadiness")); builder = MockMvcRequestBuilders.get(url); response = mockmvc.perform(builder).andReturn().getResponse(); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals("Naming is not in readiness", response.getContentAsString()); }