### Question:
FieldAgent implements IOFogModule { public void sendUSBInfoFromHalToController() { logDebug("Start send USB Info from hal To Controller"); if (notProvisioned()) { return; } Optional<StringBuilder> response = getResponse(USB_INFO_URL); if (isResponseValid(response)) { String usbInfo = response.get().toString(); StatusReporter.setResourceManagerStatus().setUsbConnectionsInfo(usbInfo); JsonObject json = Json.createObjectBuilder() .add("info", usbInfo) .build(); try { orchestrator.request(COMMAND_USB_INFO, RequestType.PUT, null, json); } catch (Exception e) { LoggingService.logError(MODULE_NAME, "Error while sending USBInfo from hal to controller", new AgentSystemException(e.getMessage(), e)); } } logDebug("Finished send USB Info from hal To Controller"); } private  FieldAgent(); @Override int getModuleIndex(); @Override String getModuleName(); static FieldAgent getInstance(); final void postTracking(JsonObject events); JsonObject provision(String key); String deProvision(boolean isTokenExpired); void instanceConfigUpdated(); void start(); void sendUSBInfoFromHalToController(); void sendHWInfoFromHalToController(); String getCheckUpgradeReadyReport(); void changeReadInterval();  }### Answer:
@Test public void testSendUSBInfoFromHalToController() { try { when(fieldAgentStatus.getControllerStatus()).thenReturn(Constants.ControllerStatus.OK); when(orchestrator.request(eq(COMMAND_USB_INFO), any(), any(), any())).thenReturn(jsonObject); initiateMockStart(); fieldAgent.sendUSBInfoFromHalToController(); PowerMockito.verifyPrivate(fieldAgent, atLeastOnce()).invoke("getResponse", any()); Mockito.verify(orchestrator, atLeastOnce()).request(eq("config"), eq(RequestType.PATCH), eq(null), any()); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService.logDebug(MODULE_NAME, "Start send USB Info from hal To Controller"); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService.logDebug(MODULE_NAME, "Finished send USB Info from hal To Controller"); } catch (Exception e){ fail("This should never happen"); } }
@Test public void throwsExceptionWhenSendUSBInfoFromHalToController() { try { when(fieldAgentStatus.getControllerStatus()).thenReturn(Constants.ControllerStatus.OK); when(orchestrator.request(eq(COMMAND_USB_INFO), any(), any(), any())).thenThrow(mock(Exception.class)); initiateMockStart(); fieldAgent.sendUSBInfoFromHalToController(); PowerMockito.verifyPrivate(fieldAgent).invoke("getResponse", any()); Mockito.verify(orchestrator, atLeastOnce()).request(eq("config"), eq(RequestType.PATCH), eq(null), any()); PowerMockito.verifyStatic(StatusReporter.class, atLeastOnce()); StatusReporter.setResourceManagerStatus(); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService.logError(eq(MODULE_NAME), eq("Error while sending USBInfo from hal to controller"), any()); } catch (Exception e){ fail("This should never happen"); } }