Skip to content

Commit e021ffa

Browse files
committed
Minor fixes and some new test cases.
Signed-off-by: Tatiana Leon <tatiana.leon@digi.com>
1 parent 26b3da2 commit e021ffa

File tree

9 files changed

+744
-22
lines changed

9 files changed

+744
-22
lines changed

library/src/main/java/com/digi/xbee/api/connection/serial/AbstractSerialPort.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public abstract class AbstractSerialPort implements IConnectionInterface {
7777
* @param port COM port name to use.
7878
* @param parameters Serial port connection parameters.
7979
*
80+
* @throws IllegalArgumentException if {@code port.length == 0}.
8081
* @throws NullPointerException if {@code port == null} or
8182
* if {@code parameters == null}.
8283
*
@@ -97,6 +98,8 @@ protected AbstractSerialPort(String port, SerialPortParameters parameters) {
9798
* @param baudRate Serial connection baud rate, the rest of parameters will
9899
* be set by default.
99100
*
101+
* @throws IllegalArgumentException if {@code port.length == 0} or
102+
* if {@code baudRate < 0}.
100103
* @throws NullPointerException if {@code port == null}.
101104
*
102105
* @see #DEFAULT_DATA_BITS
@@ -121,7 +124,9 @@ protected AbstractSerialPort(String port, int baudRate) {
121124
* set by default.
122125
* @param receiveTimeout Receive timeout in milliseconds.
123126
*
124-
* @throws IllegalArgumentException if {@code receiveTimeout < 0}.
127+
* @throws IllegalArgumentException if {@code port.length == 0} or
128+
* if {@code baudRate < 0} or
129+
* if {@code receiveTimeout < 0}.
125130
* @throws NullPointerException if {@code port == null}.
126131
*
127132
* @see DEFAULT_DATA_BITS
@@ -144,7 +149,8 @@ protected AbstractSerialPort(String port, int baudRate, int receiveTimeout) {
144149
* @param parameters Serial port connection parameters.
145150
* @param receiveTimeout Serial connection receive timeout in milliseconds.
146151
*
147-
* @throws IllegalArgumentException if {@code receiveTimeout < 0}.
152+
* @throws IllegalArgumentException if {@code port.length == 0} or
153+
* if {@code receiveTimeout < 0}.
148154
* @throws NullPointerException if {@code port == null} or
149155
* if {@code parameters == null}.
150156
*
@@ -155,13 +161,16 @@ protected AbstractSerialPort(String port, int baudRate, int receiveTimeout) {
155161
*/
156162
protected AbstractSerialPort(String port, SerialPortParameters parameters, int receiveTimeout) {
157163
if (port == null)
158-
throw new NullPointerException("Serial port cannot be null");
164+
throw new NullPointerException("Serial port cannot be null.");
159165

160166
if (parameters == null)
161-
throw new NullPointerException("SerialPortParameters cannot be null");
167+
throw new NullPointerException("SerialPortParameters cannot be null.");
162168

169+
if (port.length() == 0)
170+
throw new IllegalArgumentException("Serial port cannot be an empty string.");
171+
163172
if (receiveTimeout < 0)
164-
throw new IllegalArgumentException("Receive timeout cannot be less than 0");
173+
throw new IllegalArgumentException("Receive timeout cannot be less than 0.");
165174

166175
this.port = port;
167176
this.baudRate = parameters.baudrate;

library/src/main/java/com/digi/xbee/api/models/XBee64BitAddress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public XBee64BitAddress(int b0, int b1, int b2, int b3, int b4, int b5, int b6,
150150
throw new IllegalArgumentException("B3 must be between 0 and 255.");
151151
if (b5 > 255 || b5 < 0)
152152
throw new IllegalArgumentException("B4 must be between 0 and 255.");
153-
if (b5 > 255 || b5 < 0)
153+
if (b4 > 255 || b4 < 0)
154154
throw new IllegalArgumentException("B5 must be between 0 and 255.");
155155
if (b6 > 255 || b6 < 0)
156156
throw new IllegalArgumentException("B6 must be between 0 and 255.");

library/src/test/java/com/digi/xbee/api/NodeDiscoveryDiscoverDevicesBlockTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public final void testDiscoverDevicesOneNodeId() throws Exception {
480480
List<RemoteXBeeDevice> remotes = nd.discoverDevices(list);
481481

482482
// Verify the result.
483-
assertThat("The discovered devices list should not be empty", remotes.size(), is(equalTo(ndAnswers.size())));
483+
assertThat("The discovered devices list must have a size of " + ndAnswers.size(), remotes.size(), is(equalTo(ndAnswers.size())));
484484
assertThat("The Node ID of the discovered device should be '" + id + "'", remotes.get(0).getNodeID(), is(equalTo(id)));
485485

486486
PowerMockito.verifyPrivate(nd, Mockito.times(1)).invoke(SEND_NODE_DISCOVERY_COMMAND_METHOD, Mockito.anyString());
@@ -528,7 +528,7 @@ public final void testDiscoverDevicesOneNodeIdTwoDevices() throws Exception {
528528
List<RemoteXBeeDevice> remotes = nd.discoverDevices(list);
529529

530530
// Verify the result.
531-
assertThat("The discovered devices list should not be empty", remotes.size(), is(equalTo(ndAnswers.size())));
531+
assertThat("The discovered devices list must have a size of " + ndAnswers.size(), remotes.size(), is(equalTo(ndAnswers.size())));
532532

533533
PowerMockito.verifyPrivate(nd, Mockito.times(1)).invoke(SEND_NODE_DISCOVERY_COMMAND_METHOD, Mockito.anyString());
534534
Mockito.verify(deviceMock, Mockito.times(1)).addPacketListener(packetListener);
@@ -576,7 +576,7 @@ public final void testDiscoverDevicesTwoNodeIds() throws Exception {
576576
List<RemoteXBeeDevice> remotes = nd.discoverDevices(list);
577577

578578
// Verify the result.
579-
assertThat("The discovered devices list should not be empty", remotes.size(), is(equalTo(ndAnswers.size())));
579+
assertThat("The discovered devices list must have a size of " + ndAnswers.size(), remotes.size(), is(equalTo(ndAnswers.size())));
580580

581581
PowerMockito.verifyPrivate(nd, Mockito.times(1)).invoke(SEND_NODE_DISCOVERY_COMMAND_METHOD, Mockito.anyString());
582582
Mockito.verify(deviceMock, Mockito.times(1)).addPacketListener(packetListener);
@@ -615,7 +615,7 @@ public void testDiscoverDevicesDuplicatedNodeIds() throws Exception {
615615
List<RemoteXBeeDevice> remotes = nd.discoverDevices(list);
616616

617617
// Verify the result.
618-
assertThat("The discovered devices list should not be empty", remotes.size(), is(equalTo(ndAnswers.size())));
618+
assertThat("The discovered devices list must have a size of " + ndAnswers.size(), remotes.size(), is(equalTo(ndAnswers.size())));
619619
assertThat("The Node ID of the discovered device should be '" + id + "'", remotes.get(0).getNodeID(), is(equalTo(id)));
620620

621621
PowerMockito.verifyPrivate(nd, Mockito.times(1)).invoke(SEND_NODE_DISCOVERY_COMMAND_METHOD, Mockito.anyString());

library/src/test/java/com/digi/xbee/api/NodeDiscoveryDiscoverDevicesListenerTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ public final void testDiscoverDevicesErrorAddingDeviceToNetwork() throws Excepti
268268
String error = "Error adding device '0013A20040A6A0DB - Ni string' to the network.";
269269

270270
assertThat("The discovered devices list should be empty", listener.getDiscoveredDevices().size(), is(equalTo(0)));
271+
assertThat("There must be discovery errors", listener.getErrors().size(), is(equalTo(1)));
271272
assertThat("The discovery error should be " + error, listener.getErrors().get(0), is(equalTo(error)));
272273
}
273274

@@ -349,7 +350,7 @@ public final void testDiscoverDevicesOneDigiMeshDevice() throws Exception {
349350
Thread.sleep(30);
350351
}
351352

352-
assertThat("The discovered devices list should be empty", listener.getDiscoveredDevices().size(), is(equalTo(ndAnswers.size())));
353+
assertThat("The discovered devices list must have a size of " + ndAnswers.size(), listener.getDiscoveredDevices().size(), is(equalTo(ndAnswers.size())));
353354

354355
RemoteXBeeDevice remoteDevice = listener.getDiscoveredDevices().get(0);
355356

@@ -417,7 +418,7 @@ public final void testDiscoverDevicesOneDigiPointDevice() throws Exception {
417418
Thread.sleep(30);
418419
}
419420

420-
assertThat("The discovered devices list should be empty", listener.getDiscoveredDevices().size(), is(equalTo(ndAnswers.size())));
421+
assertThat("The discovered devices list must have a size of " + ndAnswers.size(), listener.getDiscoveredDevices().size(), is(equalTo(ndAnswers.size())));
421422

422423
RemoteXBeeDevice remoteDevice = listener.getDiscoveredDevices().get(0);
423424

@@ -484,7 +485,7 @@ public final void testDiscoverDevicesOneRaw802Device() throws Exception {
484485
Thread.sleep(30);
485486
}
486487

487-
assertThat("The discovered devices list should be empty", listener.getDiscoveredDevices().size(),
488+
assertThat("The discovered devices list must have a size of " + (ndAnswers.size() -1), listener.getDiscoveredDevices().size(),
488489
is(equalTo(ndAnswers.size() - 1 /* Remove the end packet */)));
489490

490491
RemoteXBeeDevice remoteDevice = listener.getDiscoveredDevices().get(0);
@@ -550,7 +551,7 @@ public final void testDiscoverDevicesOneZigBeeDevice() throws Exception {
550551
Thread.sleep(30);
551552
}
552553

553-
assertThat("The discovered devices list should be empty", listener.getDiscoveredDevices().size(), is(equalTo(ndAnswers.size())));
554+
assertThat("The discovered devices list must have a size of " + ndAnswers.size(), listener.getDiscoveredDevices().size(), is(equalTo(ndAnswers.size())));
554555

555556
RemoteXBeeDevice remoteDevice = listener.getDiscoveredDevices().get(0);
556557

@@ -621,7 +622,7 @@ public final void testDiscoverDevicesTwoZigBeeDevice() throws Exception {
621622
Thread.sleep(30);
622623
}
623624

624-
assertThat("The discovered devices list should be empty", listener.getDiscoveredDevices().size(), is(equalTo(ndAnswers.size())));
625+
assertThat("The discovered devices list must have a size of " + ndAnswers.size(), listener.getDiscoveredDevices().size(), is(equalTo(ndAnswers.size())));
625626

626627
List<RemoteXBeeDevice> list = listener.getDiscoveredDevices();
627628

0 commit comments

Comments
 (0)