@Test public void timer_PERFORM_KEY_ESTABLISHMENT() throws Exception { System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); SmartEnergyClient extension = new SmartEnergyClient(Mockito.mock(ZigBeeCbkeProvider.class)); ZigBeeNetworkManager networkManager = Mockito.mock(ZigBeeNetworkManager.class); assertEquals(ZigBeeStatus.SUCCESS, extension.extensionInitialize(networkManager)); ArgumentCaptor<Long> timerCaptor = ArgumentCaptor.forClass(Long.class); TestUtilities.setField(SmartEnergyClient.class, extension, "trustCenterKeyEstablishmentEndpoint", 1); ZigBeeNode node = Mockito.mock(ZigBeeNode.class); Mockito.when(networkManager.getNode(0)).thenReturn(node); ZigBeeEndpoint endpoint = Mockito.mock(ZigBeeEndpoint.class); Mockito.when(endpoint.getEndpointAddress()).thenReturn(new ZigBeeEndpointAddress(0, 1)); Mockito.when(node.getEndpoint(1)).thenReturn(endpoint); ZclKeyEstablishmentCluster cluster = Mockito.mock(ZclKeyEstablishmentCluster.class); Mockito.when(endpoint.getInputCluster(ZclKeyEstablishmentCluster.CLUSTER_ID)).thenReturn(cluster); Mockito.when(networkManager.scheduleTask(ArgumentMatchers.argThat(new ArgumentMatcher<Runnable>() { boolean doOnce = true; @Override public boolean matches(Runnable argument) { if (!doOnce) { return true; } doOnce = false; Runnable runnable = argument; try { runnable.run(); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } return true; } }), timerCaptor.capture())).thenReturn(Mockito.mock(ScheduledFuture.class)); ZclKeyEstablishmentClient cbkeClient = Mockito.mock(ZclKeyEstablishmentClient.class); Map<ZigBeeEndpointAddress, ZclKeyEstablishmentClient> clientRegistry = new HashMap<>(); clientRegistry.put(new ZigBeeEndpointAddress(0, 1), cbkeClient); TestUtilities.setField(SmartEnergyClient.class, extension, "cbkeClientRegistry", clientRegistry); TestUtilities.setField(SmartEnergyClient.class, extension, "seState", SmartEnergyClientState.PERFORM_KEY_ESTABLISHMENT); TestUtilities.invokeMethod(SmartEnergyClient.class, extension, "timerStart", int.class, 123456); Mockito.verify(cbkeClient, Mockito.timeout(TIMEOUT)).start(); assertEquals(1, timerCaptor.getAllValues().size()); assertEquals(Long.valueOf(123456), timerCaptor.getAllValues().get(0)); }
@Override public ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager) { this.networkManager = networkManager; return ZigBeeStatus.SUCCESS; }
SmartEnergyClient implements ZigBeeNetworkExtension, ZigBeeCommandListener, ZigBeeNetworkNodeListener,
        ZigBeeNetworkStateListener { @Override public ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager) { this.networkManager = networkManager; return ZigBeeStatus.SUCCESS; } }
SmartEnergyClient implements ZigBeeNetworkExtension, ZigBeeCommandListener, ZigBeeNetworkNodeListener,
        ZigBeeNetworkStateListener { @Override public ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager) { this.networkManager = networkManager; return ZigBeeStatus.SUCCESS; } SmartEnergyClient(ZigBeeCbkeProvider cbkeProvider); }
SmartEnergyClient implements ZigBeeNetworkExtension, ZigBeeCommandListener, ZigBeeNetworkNodeListener,
        ZigBeeNetworkStateListener { @Override public ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager) { this.networkManager = networkManager; return ZigBeeStatus.SUCCESS; } SmartEnergyClient(ZigBeeCbkeProvider cbkeProvider); @Override ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager); @Override ZigBeeStatus extensionStartup(); @Override void extensionShutdown(); ZigBeeCbkeProvider getCbkeProvider(); boolean setCryptoSuite(ZigBeeCryptoSuites requestedCryptoSuite); void addListener(final SmartEnergyStatusCallback listener); void removeListener(final SmartEnergyStatusCallback listener); void setKeepAlivePeriod(int timeout); Calendar getLastKeepAlive(); ZigBeeStatus startKeyExchange(ZigBeeEndpointAddress endpoint); @Override void commandReceived(ZigBeeCommand command); @Override void networkStateUpdated(ZigBeeNetworkState state); SmartEnergyClientState getDiscoveryState(); @Override void nodeAdded(ZigBeeNode node); @Override void nodeUpdated(ZigBeeNode node); }
SmartEnergyClient implements ZigBeeNetworkExtension, ZigBeeCommandListener, ZigBeeNetworkNodeListener,
        ZigBeeNetworkStateListener { @Override public ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager) { this.networkManager = networkManager; return ZigBeeStatus.SUCCESS; } SmartEnergyClient(ZigBeeCbkeProvider cbkeProvider); @Override ZigBeeStatus extensionInitialize(ZigBeeNetworkManager networkManager); @Override ZigBeeStatus extensionStartup(); @Override void extensionShutdown(); ZigBeeCbkeProvider getCbkeProvider(); boolean setCryptoSuite(ZigBeeCryptoSuites requestedCryptoSuite); void addListener(final SmartEnergyStatusCallback listener); void removeListener(final SmartEnergyStatusCallback listener); void setKeepAlivePeriod(int timeout); Calendar getLastKeepAlive(); ZigBeeStatus startKeyExchange(ZigBeeEndpointAddress endpoint); @Override void commandReceived(ZigBeeCommand command); @Override void networkStateUpdated(ZigBeeNetworkState state); SmartEnergyClientState getDiscoveryState(); @Override void nodeAdded(ZigBeeNode node); @Override void nodeUpdated(ZigBeeNode node);  }