### Question:
ControlWebsocketWorker implements Runnable { @Override public void run() { Thread.currentThread().setName(Constants.LOCAL_API_CONTROL_WEBSOCKET_WORKER); LoggingService.logDebug(MODULE_NAME,"Initiating control signals for unacknowledged signals"); for(Map.Entry<ChannelHandlerContext, ControlSignalSentInfo> contextEntry : WebSocketMap.unackControlSignalsMap.entrySet()){ ChannelHandlerContext ctx = contextEntry.getKey(); ControlSignalSentInfo controlSignalSentInfo = contextEntry.getValue(); int tryCount = controlSignalSentInfo.getSendTryCount(); long lastSendTime = WebSocketMap.unackControlSignalsMap.get(ctx).getTimeMillis(); long timeEllapsed = (System.currentTimeMillis() - lastSendTime)/1000; if (timeEllapsed > 20) { if (tryCount < 10) { initiateControlSignal(ctx); } else { LoggingService.logDebug(MODULE_NAME, " Initiating control signal expires"); WebSocketMap.unackControlSignalsMap.remove(ctx); WebsocketUtil.removeWebsocketContextFromMap(ctx, WebSocketMap.controlWebsocketMap); StatusReporter.setLocalApiStatus().setOpenConfigSocketsCount(WebSocketMap.controlWebsocketMap.size()); return; } } } LoggingService.logDebug(MODULE_NAME,"Finished Initiating control signals for unacknowledged signals"); }  @Override void run();  }### Answer:
@Test public void testRunWhenUnackControlSignalsMapIsEmpty() { controlWebsocketWorker.run(); PowerMockito.verifyStatic(LoggingService.class); LoggingService.logInfo(MODULE_NAME,"Initiating control signals for unacknowledged signals"); PowerMockito.verifyStatic(LoggingService.class); LoggingService.logInfo(MODULE_NAME,"Finished Initiating control signals for unacknowledged signals"); }
@Test public void testRunWhenUnackControlSignalsMapIsNotEmpty() { try { WebSocketMap.unackControlSignalsMap.put(context, controlSignalSentInfo); controlWebsocketWorker.run(); Mockito.verify(controlSignalSentInfo, Mockito.atLeastOnce()).getSendTryCount(); PowerMockito.verifyPrivate(controlWebsocketWorker).invoke("initiateControlSignal", Mockito.eq(context)); Mockito.verify(context).alloc(); Mockito.verify(context).channel(); } catch (Exception e) { fail("This should not happen"); } }
@Test public void testRunWhenUnackControlSignalsMapIsNotEmptyAndSendTryCountIsGreaterThan10() { try { WebSocketMap.unackControlSignalsMap.put(context, controlSignalSentInfo); PowerMockito.when(controlSignalSentInfo.getSendTryCount()).thenReturn(11); controlWebsocketWorker.run(); Mockito.verify(controlSignalSentInfo, Mockito.atLeastOnce()).getSendTryCount(); PowerMockito.verifyPrivate(controlWebsocketWorker, Mockito.never()).invoke("initiateControlSignal", Mockito.eq(context)); PowerMockito.verifyStatic(WebsocketUtil.class); WebsocketUtil.removeWebsocketContextFromMap(Mockito.eq(context), Mockito.eq(WebSocketMap.controlWebsocketMap)); Mockito.verify(localApiStatus).setOpenConfigSocketsCount(Mockito.eq(WebSocketMap.controlWebsocketMap.size())); } catch (Exception e) { fail("This should not happen"); } }