From 9c306777fd22471c247cafd80c4c2132a352e6fa Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sat, 5 Oct 2024 13:02:37 +1300 Subject: [PATCH] Fix tests Signed-off-by: Chris Jackson --- .../zigbee/dongle/ember/ZigBeeDongleEzsp.java | 5 ++++- .../dongle/ember/ZigBeeTransportTransmitTest.java | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java b/com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java index a3ecbf67d..f63ff13b3 100644 --- a/com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java +++ b/com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java @@ -475,7 +475,10 @@ public ZigBeeStatus initialize() { if (networkParametersResponse == null) { return ZigBeeStatus.COMMUNICATION_ERROR; } - networkParameters = networkParametersResponse.getParameters(); + EmberNetworkParameters localNetworkParameters = networkParametersResponse.getParameters(); + if (localNetworkParameters != null) { + networkParameters = localNetworkParameters; + } logger.debug("Ember initial network parameters are {}", networkParameters); ieeeAddress = ncp.getIeeeAddress(); diff --git a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeTransportTransmitTest.java b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeTransportTransmitTest.java index 15e8fd9f5..76dd2f65b 100644 --- a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeTransportTransmitTest.java +++ b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeTransportTransmitTest.java @@ -15,6 +15,7 @@ import com.zsmartsystems.zigbee.TestUtilities; import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspGetNetworkParametersResponse; import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspGetParentChildParametersResponse; +import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspVersionResponse; import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberCurrentSecurityState; import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberNetworkParameters; import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberNetworkStatus; @@ -24,6 +25,7 @@ import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EzspStatus; import com.zsmartsystems.zigbee.dongle.ember.internal.EzspProtocolHandler; import com.zsmartsystems.zigbee.transport.ZigBeePort; +import com.zsmartsystems.zigbee.transport.ZigBeeTransportReceive; import com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmitAbstractTest; /** @@ -52,6 +54,11 @@ public void initialiseTransport() throws Exception { Mockito.when(ncp.setRadioPower(ArgumentMatchers.anyInt())).thenReturn(EmberStatus.EMBER_SUCCESS); Mockito.when(ncp.getNwkAddress()).thenReturn(Integer.valueOf(0)); Mockito.when(ncp.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); + final EzspVersionResponse version = Mockito.mock(EzspVersionResponse.class); + Mockito.when(version.getProtocolVersion()).thenReturn(4); + + Mockito.when(ncp.getVersion()).thenReturn(version); + Mockito.when(ncp.getNetworkParameters()).thenReturn(Mockito.mock(EzspGetNetworkParametersResponse.class)); ZigBeePort port = Mockito.mock(ZigBeePort.class); Mockito.when(port.open()).thenReturn(Boolean.TRUE); @@ -62,8 +69,13 @@ public EmberNcp getEmberNcp() { return ncp; } }; + EzspProtocolHandler frameHandler = Mockito.mock(EzspProtocolHandler.class); + Mockito.when(frameHandler.isAlive()).thenReturn(Boolean.TRUE); + TestUtilities.setField(ZigBeeDongleEzsp.class, dongle, "frameHandler", frameHandler); + + final ZigBeeTransportReceive receiver = Mockito.mock(ZigBeeTransportReceive.class); - TestUtilities.setField(ZigBeeDongleEzsp.class, dongle, "frameHandler", Mockito.mock(EzspProtocolHandler.class)); + dongle.setZigBeeTransportReceive(receiver); transport = dongle; }