Search in sources :

Example 1 with CommandResultFuture

use of com.zsmartsystems.zigbee.CommandResultFuture in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNetworkDiscovererTest method setupTest.

@Before
public void setupTest() {
    networkManager = Mockito.mock(ZigBeeNetworkManager.class);
    nodeCapture = ArgumentCaptor.forClass(ZigBeeNode.class);
    // commandCapture = ArgumentCaptor.forClass(ZigBeeCommand.class);
    // matcherCapture = ArgumentCaptor.forClass(CommandResponseMatcher.class);
    // Mockito.when(networkManager.unicast(commandCapture.capture(), matcherCapture.capture())).thenReturn(null);
    Mockito.doAnswer(new Answer<Future<CommandResult>>() {

        @Override
        public Future<CommandResult> answer(InvocationOnMock invocation) {
            ZigBeeCommand command = (ZigBeeCommand) invocation.getArguments()[0];
            CommandResultFuture commandFuture = new CommandResultFuture(networkManager);
            CommandResult result = new CommandResult(responses.get(command.getClusterId()));
            commandFuture.set(result);
            return commandFuture;
        }
    }).when(networkManager).unicast(org.mockito.Matchers.any(ZigBeeCommand.class), org.mockito.Matchers.any(ZigBeeTransactionMatcher.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Runnable runnable = (Runnable) invocation.getArguments()[0];
            new Thread(runnable).start();
            return null;
        }
    }).when(networkManager).executeTask(org.mockito.Matchers.any(Runnable.class));
}
Also used : ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeNetworkManager(com.zsmartsystems.zigbee.ZigBeeNetworkManager) CommandResult(com.zsmartsystems.zigbee.CommandResult) CommandResultFuture(com.zsmartsystems.zigbee.CommandResultFuture) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CommandResultFuture(com.zsmartsystems.zigbee.CommandResultFuture) Future(java.util.concurrent.Future) ZigBeeTransactionMatcher(com.zsmartsystems.zigbee.ZigBeeTransactionMatcher) Before(org.junit.Before)

Aggregations

CommandResult (com.zsmartsystems.zigbee.CommandResult)1 CommandResultFuture (com.zsmartsystems.zigbee.CommandResultFuture)1 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)1 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)1 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)1 ZigBeeTransactionMatcher (com.zsmartsystems.zigbee.ZigBeeTransactionMatcher)1 Future (java.util.concurrent.Future)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1