@Test public void addCommandListener() throws Exception { ZigBeeNetworkManager mockedNetworkManager = Mockito.mock(ZigBeeNetworkManager.class); Mockito.when(mockedNetworkManager.getNotificationService()).thenReturn(new NotificationService()); ZigBeeCommandNotifier notifier = new ZigBeeCommandNotifier(mockedNetworkManager); ZigBeeCommandListener commandListener = Mockito.mock(ZigBeeCommandListener.class); notifier.addCommandListener(commandListener); Set<ZigBeeCommandListener> commandListeners = (Set<ZigBeeCommandListener>) TestUtilities .getField(ZigBeeCommandNotifier.class, notifier, "commandListeners"); assertEquals(1, commandListeners.size()); assertEquals(commandListener, commandListeners.iterator().next()); notifier.addCommandListener(commandListener); assertEquals(1, commandListeners.size()); notifier.addCommandListener(Mockito.mock(ZigBeeCommandListener.class)); assertEquals(2, commandListeners.size()); ZigBeeCommand command = Mockito.mock(ZigBeeCommand.class); notifier.notifyCommandListeners(command); Mockito.verify(commandListener, Mockito.timeout(TIMEOUT).times(1)).commandReceived(command); ZclCommand zclCommand = Mockito.mock(ZclCommand.class); Mockito.when(zclCommand.isDisableDefaultResponse()).thenReturn(true); notifier.notifyCommandListeners(zclCommand); Mockito.when(zclCommand.isDisableDefaultResponse()).thenReturn(false); notifier.notifyCommandListeners(zclCommand); notifier.removeCommandListener(commandListener); assertEquals(1, commandListeners.size()); }
public synchronized void addCommandListener(ZigBeeCommandListener commandListener) { commandListeners.add(commandListener); }
ZigBeeCommandNotifier { public synchronized void addCommandListener(ZigBeeCommandListener commandListener) { commandListeners.add(commandListener); } }
ZigBeeCommandNotifier { public synchronized void addCommandListener(ZigBeeCommandListener commandListener) { commandListeners.add(commandListener); } ZigBeeCommandNotifier(ZigBeeNetworkManager networkManager); }
ZigBeeCommandNotifier { public synchronized void addCommandListener(ZigBeeCommandListener commandListener) { commandListeners.add(commandListener); } ZigBeeCommandNotifier(ZigBeeNetworkManager networkManager); synchronized void addCommandListener(ZigBeeCommandListener commandListener); synchronized void removeCommandListener(ZigBeeCommandListener commandListener); synchronized void notifyCommandListeners(final ZigBeeCommand command); }
ZigBeeCommandNotifier { public synchronized void addCommandListener(ZigBeeCommandListener commandListener) { commandListeners.add(commandListener); } ZigBeeCommandNotifier(ZigBeeNetworkManager networkManager); synchronized void addCommandListener(ZigBeeCommandListener commandListener); synchronized void removeCommandListener(ZigBeeCommandListener commandListener); synchronized void notifyCommandListeners(final ZigBeeCommand command);  }