### Question:
MessageReceiver implements AutoCloseable { void disableRealTimeReceiving() { LoggingService.logDebug(MODULE_NAME, "Start disable real time receiving"); try { if (consumer == null || listener == null || consumer.getMessageListener() == null) return; listener = null; consumer.setMessageListener(null); } catch (Exception exp) { logError(MODULE_NAME, "Error in disabling real time listener", new AgentSystemException(exp.getMessage() , exp)); } LoggingService.logDebug(MODULE_NAME, "Finished disable real time receiving"); } MessageReceiver(String name, MessageConsumer consumer); void close();  }### Answer:
@Test public void testDisablingRealTimeReceivingWhenClientConsumerIsNull() { try { messageReceiver = spy(new MessageReceiver(name, null)); messageReceiver.disableRealTimeReceiving(); Mockito.verify(messageConsumer, Mockito.never()).setMessageListener(any(IOMessageListener.class)); verifyStatic(LoggingService.class); LoggingService.logDebug(MODULE_NAME, "Start disable real time receiving"); verifyStatic(LoggingService.class, Mockito.never()); LoggingService.logDebug(MODULE_NAME, "Finished disable real time receiving"); } catch (Exception e) { fail("This should not happen"); } }
@Test public void testDisableRealTimeReceiving() { try { messageReceiver.enableRealTimeReceiving(); messageReceiver.disableRealTimeReceiving(); Mockito.verify(messageConsumer).setMessageListener(any(IOMessageListener.class)); } catch (Exception e) { fail("This should not happen"); } }