PolicyRestController extends RestrictedBaseController { private String doConnect(final HttpURLConnection connection) throws IOException { connection.connect(); if (connection.getResponseCode() == 200) { String responseJson = null; try (java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream())) { scanner.useDelimiter("\\A"); responseJson = scanner.hasNext() ? scanner.next() : ""; } catch (Exception e) { policyLogger.error("Exception Occured" + e); throw e; } policyLogger.info("JSON response from PAP: " + responseJson); return responseJson; } return null; } PolicyRestController(); @Autowired private  PolicyRestController(CommonClassDao commonClassDao); static CommonClassDao getCommonClassDao(); static void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping(value = {"/policycreation/save_policy"}, method = {RequestMethod.POST}) void policyCreationController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/getDictionary/*"}, method = {RequestMethod.GET}) void getDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/saveDictionary/*/*"}, method = {RequestMethod.POST}) void saveDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/deleteDictionary/*/*"}, method = {RequestMethod.POST}) void deletetDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/searchDictionary"}, method = {RequestMethod.POST}) ModelAndView searchDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/searchPolicy"}, method = {RequestMethod.POST}) ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response); void deleteElasticData(String fileName); String notifyOtherPapsToUpdateConfigurations(String mode, String newName, String oldName);  }
@Test public void testDoConnect() throws Exception { HttpURLConnection mockConnection = Mockito.mock(HttpURLConnection.class); PolicyRestController controller = new PolicyRestController(); Mockito.doNothing().when(mockConnection).connect(); InputStream mockInputStream = Mockito.mock(InputStream.class); when(mockConnection.getResponseCode()).thenReturn(200); when(mockConnection.getInputStream()).thenReturn(mockInputStream); Whitebox.invokeMethod(controller, "doConnect", mockConnection); verify(mockConnection).getResponseCode(); verify(mockConnection).getInputStream(); when(mockConnection.getResponseCode()).thenReturn(201); assertNull(Whitebox.invokeMethod(controller, "doConnect", mockConnection)); }