### Question:
FieldAgent implements IOFogModule { public void instanceConfigUpdated() { logDebug("Start IOFog configuration update"); try { postFogConfig(); } catch (Exception e) { logError("Error posting updated for config ", e); } orchestrator.update(); logDebug("Finished IOFog configuration update"); } 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 testInstanceConfigUpdatedWhenControllerStatusIsNotProvisioned() { try { initiateMockStart(); when(orchestrator.request(eq("config"), any(), any(), any())).thenReturn(mock(JsonObject.class)); fieldAgent.instanceConfigUpdated(); Mockito.verify(orchestrator).update(); PowerMockito.verifyPrivate(fieldAgent).invoke("postFogConfig"); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService.logInfo(MODULE_NAME, "Post ioFog config"); PowerMockito.verifyStatic(LoggingService.class, never()); LoggingService.logInfo(MODULE_NAME, "Finished Post ioFog config"); } catch (Exception e) { fail("This should never happen"); } }
@Test public void testInstanceConfigUpdatedWhenControllerStatusIsProvisioned() { try { initiateMockStart(); when(fieldAgentStatus.getControllerStatus()).thenReturn(Constants.ControllerStatus.OK); when(orchestrator.request(eq("config"), any(), any(), any())).thenReturn(mock(JsonObject.class)); fieldAgent.instanceConfigUpdated(); Mockito.verify(orchestrator).update(); PowerMockito.verifyPrivate(fieldAgent).invoke("postFogConfig"); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService.logInfo(MODULE_NAME, "Post ioFog config"); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService.logInfo(MODULE_NAME, "Finished Post ioFog config"); } catch (Exception e) { fail("This should never happen"); } }
@Test public void throwsSSLHandshakeExceptionWhenOrchestratorIsCalledToUpdateConfiguration() { try { initiateMockStart(); when(fieldAgentStatus.getControllerStatus()).thenReturn(Constants.ControllerStatus.OK); when(orchestrator.request(eq("config"), any(), any(), any())).thenThrow(new SSLHandshakeException("Invalid operation")); fieldAgent.instanceConfigUpdated(); Mockito.verify(orchestrator).update(); PowerMockito.verifyPrivate(fieldAgent).invoke("postFogConfig"); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService. logError(eq(MODULE_NAME), eq("Unable to post ioFog config due to broken certificate "), any()); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService.logDebug(MODULE_NAME, "Finished IOFog configuration update"); } catch (Exception e) { fail("This should never happen"); } }
@Test public void throwsExceptionWhenOrchestratorIsCalledToUpdateConfiguration() { try { initiateMockStart(); when(fieldAgentStatus.getControllerStatus()).thenReturn(Constants.ControllerStatus.OK); when(orchestrator.request(eq("config"), any(), any(), any())).thenThrow(new Exception("Invalid operation")); fieldAgent.instanceConfigUpdated(); Mockito.verify(orchestrator).update(); PowerMockito.verifyPrivate(fieldAgent).invoke("postFogConfig"); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService. logError(eq(MODULE_NAME), eq("Unable to post ioFog config "), any()); PowerMockito.verifyStatic(LoggingService.class, atLeastOnce()); LoggingService.logDebug(MODULE_NAME, "Finished IOFog configuration update"); } catch (Exception e) { fail("This should never happen"); } }