Skip to content

Commit bee5153

Browse files
committed
Migration from Junit4 to Junit5.
1 parent dbe5aa2 commit bee5153

File tree

108 files changed

+3783
-1542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+3783
-1542
lines changed

leshan-client-cf/pom.xml

-12
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,5 @@ Contributors:
5252
<artifactId>cf-oscore</artifactId>
5353
<version>${californium.version}</version>
5454
</dependency>
55-
56-
<!-- test dependencies -->
57-
<dependency>
58-
<groupId>ch.qos.logback</groupId>
59-
<artifactId>logback-classic</artifactId>
60-
<scope>test</scope>
61-
</dependency>
62-
<dependency>
63-
<groupId>junit</groupId>
64-
<artifactId>junit</artifactId>
65-
<scope>test</scope>
66-
</dependency>
6755
</dependencies>
6856
</project>

leshan-client-core/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ Contributors:
4343
<scope>test</scope>
4444
</dependency>
4545
<dependency>
46-
<groupId>junit</groupId>
47-
<artifactId>junit</artifactId>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter-engine</artifactId>
4848
<scope>test</scope>
4949
</dependency>
5050
</dependencies>

leshan-client-core/src/test/java/org/eclipse/leshan/client/send/ManualDataSenderTest.java

+16-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*******************************************************************************/
1515
package org.eclipse.leshan.client.send;
1616

17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
1719
import java.time.Instant;
1820
import java.util.AbstractMap;
1921
import java.util.ArrayList;
@@ -35,9 +37,8 @@
3537
import org.eclipse.leshan.core.response.ErrorCallback;
3638
import org.eclipse.leshan.core.response.ResponseCallback;
3739
import org.eclipse.leshan.core.response.SendResponse;
38-
import org.junit.Assert;
39-
import org.junit.Before;
40-
import org.junit.Test;
40+
import org.junit.jupiter.api.BeforeEach;
41+
import org.junit.jupiter.api.Test;
4142

4243
public class ManualDataSenderTest {
4344
private ManualDataSender manualDataSender;
@@ -47,7 +48,7 @@ public class ManualDataSenderTest {
4748
private final List<LwM2mPath> givenPaths = Arrays.asList(new LwM2mPath(1, 2, 3), new LwM2mPath(4, 5, 6),
4849
new LwM2mPath(7, 8, 9));
4950

50-
@Before
51+
@BeforeEach
5152
public void prepareDataSender() {
5253
manualDataSender = new ManualDataSender();
5354
fakeDataSenderManager = new FakeDataSenderManager(manualDataSender);
@@ -67,16 +68,16 @@ public void test_successful_data_send() {
6768

6869
// ensure that sent values equals collected ones.
6970
TimestampedLwM2mNodes lastValuesSent = fakeDataSenderManager.getLastValuesSent();
70-
Assert.assertEquals(currentValues, lastValuesSent.getNodes());
71+
assertEquals(currentValues, lastValuesSent.getNodes());
7172

7273
// re send to ensure data was flushed (we do not resent same data)
7374
Map<LwM2mPath, LwM2mNode> newValue = fakeDataSenderManager.changeCurrentValues(givenServer, givenPaths);
7475
manualDataSender.collectData(givenPaths);
7576
manualDataSender.sendCollectedData(givenServer, ContentFormat.SENML_CBOR, 0, false);
7677
lastValuesSent = fakeDataSenderManager.getLastValuesSent();
7778

78-
Assert.assertEquals(1, lastValuesSent.getTimestamps().size());
79-
Assert.assertEquals(newValue, lastValuesSent.getNodes());
79+
assertEquals(1, lastValuesSent.getTimestamps().size());
80+
assertEquals(newValue, lastValuesSent.getNodes());
8081
}
8182

8283
@Test
@@ -102,10 +103,10 @@ public void test_collect_several_data() throws InterruptedException {
102103
// ensure that sent values equals collected ones.
103104
TimestampedLwM2mNodes lastValuesSent = fakeDataSenderManager.getLastValuesSent();
104105
List<Instant> timestamps = new ArrayList<>(lastValuesSent.getTimestamps());
105-
Assert.assertEquals(3, timestamps.size());
106-
Assert.assertEquals(firstValue, lastValuesSent.getNodesAt(timestamps.get(0)));
107-
Assert.assertEquals(secondValue, lastValuesSent.getNodesAt(timestamps.get(1)));
108-
Assert.assertEquals(thirdValue, lastValuesSent.getNodesAt(timestamps.get(2)));
106+
assertEquals(3, timestamps.size());
107+
assertEquals(firstValue, lastValuesSent.getNodesAt(timestamps.get(0)));
108+
assertEquals(secondValue, lastValuesSent.getNodesAt(timestamps.get(1)));
109+
assertEquals(thirdValue, lastValuesSent.getNodesAt(timestamps.get(2)));
109110
}
110111

111112
@Test
@@ -125,7 +126,7 @@ public void test_unsuccessful_data_send() {
125126

126127
// ensure that sent values equals collected ones.
127128
TimestampedLwM2mNodes lastValuesSent = fakeDataSenderManager.getLastValuesSent();
128-
Assert.assertEquals(currentValues, lastValuesSent.getNodes());
129+
assertEquals(currentValues, lastValuesSent.getNodes());
129130
}
130131

131132
@Test
@@ -145,7 +146,7 @@ public void test_error_during_data_send() {
145146

146147
// ensure that sent values equals collected ones.
147148
TimestampedLwM2mNodes lastValuesSent = fakeDataSenderManager.getLastValuesSent();
148-
Assert.assertEquals(currentValues, lastValuesSent.getNodes());
149+
assertEquals(currentValues, lastValuesSent.getNodes());
149150
}
150151

151152
@Test
@@ -162,13 +163,13 @@ public void test_successful_data_send_without_flush() {
162163

163164
// ensure that sent values equals collected ones.
164165
TimestampedLwM2mNodes lastValuesSent = fakeDataSenderManager.getLastValuesSent();
165-
Assert.assertEquals(currentValues, lastValuesSent.getNodes());
166+
assertEquals(currentValues, lastValuesSent.getNodes());
166167

167168
// re send to ensure data was not flushed
168169
manualDataSender.sendCollectedData(givenServer, ContentFormat.SENML_CBOR, 0, false);
169170

170171
lastValuesSent = fakeDataSenderManager.getLastValuesSent();
171-
Assert.assertEquals(currentValues, lastValuesSent.getNodes());
172+
assertEquals(currentValues, lastValuesSent.getNodes());
172173
}
173174

174175
static class FakeDataSenderManager extends DataSenderManager {

leshan-client-core/src/test/java/org/eclipse/leshan/client/util/BaseInstanceEnablerFactoryTest.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*******************************************************************************/
1616
package org.eclipse.leshan.client.util;
1717

18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
2021

2122
import java.util.Arrays;
2223
import java.util.Collections;
@@ -29,17 +30,16 @@
2930
import org.eclipse.leshan.core.model.LwM2mModel;
3031
import org.eclipse.leshan.core.model.ObjectLoader;
3132
import org.eclipse.leshan.core.model.StaticModel;
32-
import org.junit.Test;
33+
import org.junit.jupiter.api.Test;
3334

3435
public class BaseInstanceEnablerFactoryTest {
3536

3637
public static final LwM2mModel model = new StaticModel(ObjectLoader.loadDefault());
3738
public static List<Integer> emptyList = Collections.emptyList();
3839

39-
@Test(expected = IllegalStateException.class)
40+
@Test
4041
public void create_instance_with_unexpected_id() {
4142
final int id = 2;
42-
4343
BaseInstanceEnablerFactory badInstanceEnablerFactory = new BaseInstanceEnablerFactory() {
4444

4545
@Override
@@ -49,7 +49,9 @@ public LwM2mInstanceEnabler create() {
4949
}
5050
};
5151

52-
badInstanceEnablerFactory.create(model.getObjectModel(LwM2mId.ACCESS_CONTROL), id, emptyList);
52+
assertThrowsExactly(IllegalStateException.class, () -> {
53+
badInstanceEnablerFactory.create(model.getObjectModel(LwM2mId.ACCESS_CONTROL), id, emptyList);
54+
});
5355
}
5456

5557
@Test
@@ -65,7 +67,7 @@ public LwM2mInstanceEnabler create() {
6567
List<Integer> alreadyUsedIds = Arrays.asList(2, 3, 5, 6);
6668
LwM2mInstanceEnabler instance = instanceEnablerFactory.create(model.getObjectModel(LwM2mId.ACCESS_CONTROL),
6769
null, alreadyUsedIds);
68-
assertNotNull("instance id is not set", instance.getId());
69-
assertFalse("new id must not be already used", alreadyUsedIds.contains(instance.getId()));
70+
assertNotNull(instance.getId(), "instance id is not set");
71+
assertFalse(alreadyUsedIds.contains(instance.getId()), "new id must not be already used");
7072
}
7173
}

leshan-client-core/src/test/java/org/eclipse/leshan/client/util/LinkFormatHelperTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*******************************************************************************/
1717
package org.eclipse.leshan.client.util;
1818

19-
import static org.junit.Assert.assertArrayEquals;
20-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
2121

2222
import java.util.ArrayList;
2323
import java.util.Arrays;
@@ -48,7 +48,7 @@
4848
import org.eclipse.leshan.core.oscore.OscoreSetting;
4949
import org.eclipse.leshan.core.request.ContentFormat;
5050
import org.eclipse.leshan.core.util.Hex;
51-
import org.junit.Test;
51+
import org.junit.jupiter.api.Test;
5252

5353
public class LinkFormatHelperTest {
5454

leshan-client-core/src/test/java/org/eclipse/leshan/client/util/ObjectEnablerTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*******************************************************************************/
1818
package org.eclipse.leshan.client.util;
1919

20-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.util.concurrent.CountDownLatch;
2323
import java.util.concurrent.TimeUnit;
@@ -28,7 +28,7 @@
2828
import org.eclipse.leshan.client.servers.ServerIdentity;
2929
import org.eclipse.leshan.core.LwM2mId;
3030
import org.eclipse.leshan.core.request.DeleteRequest;
31-
import org.junit.Test;
31+
import org.junit.jupiter.api.Test;
3232

3333
public class ObjectEnablerTest {
3434

@@ -40,7 +40,7 @@ public void check_callback_on_delete() throws InterruptedException {
4040
LwM2mObjectEnabler objectEnabler = initializer.create(LwM2mId.ACCESS_CONTROL);
4141

4242
objectEnabler.delete(ServerIdentity.SYSTEM, new DeleteRequest(LwM2mId.ACCESS_CONTROL, instanceEnabler.getId()));
43-
assertTrue("callback delete should have been called", instanceEnabler.waitForDelete(2, TimeUnit.SECONDS));
43+
assertTrue(instanceEnabler.waitForDelete(2, TimeUnit.SECONDS), "callback delete should have been called");
4444
}
4545

4646
public static class TestInstanceEnabler extends BaseInstanceEnabler {

leshan-client-core/src/test/java/org/eclipse/leshan/client/util/ObjectsInitializerTest.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*******************************************************************************/
1616
package org.eclipse.leshan.client.util;
1717

18-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
1920

2021
import java.util.Arrays;
2122
import java.util.List;
@@ -25,16 +26,18 @@
2526
import org.eclipse.leshan.client.resource.LwM2mObjectEnabler;
2627
import org.eclipse.leshan.client.resource.ObjectsInitializer;
2728
import org.eclipse.leshan.core.LwM2mId;
28-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
2930

3031
public class ObjectsInitializerTest {
3132

32-
@Test(expected = IllegalArgumentException.class)
33+
@Test()
3334
public void set_single_instance_with_not_0_id() {
3435
int bad_id = 10; // single instance should have a 0 id
35-
3636
ObjectsInitializer objectsInitializer = new ObjectsInitializer();
37-
objectsInitializer.setInstancesForObject(LwM2mId.DEVICE, new BaseInstanceEnabler(bad_id));
37+
38+
assertThrowsExactly(IllegalArgumentException.class, () -> {
39+
objectsInitializer.setInstancesForObject(LwM2mId.DEVICE, new BaseInstanceEnabler(bad_id));
40+
});
3841
}
3942

4043
@Test
@@ -52,6 +55,6 @@ public void set_instances_with_custom_id() {
5255
LwM2mObjectEnabler AclObject = objectsInitializer.create(LwM2mId.ACCESS_CONTROL);
5356

5457
List<Integer> availableInstanceIds = AclObject.getAvailableInstanceIds();
55-
assertTrue("Bad instance id", availableInstanceIds.containsAll(expectedIds));
58+
assertTrue(availableInstanceIds.containsAll(expectedIds), "Bad instance id");
5659
}
5760
}

leshan-core-cf/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Contributors:
5151

5252
<!-- test dependencies -->
5353
<dependency>
54-
<groupId>junit</groupId>
55-
<artifactId>junit</artifactId>
54+
<groupId>org.junit.jupiter</groupId>
55+
<artifactId>junit-jupiter-engine</artifactId>
5656
<scope>test</scope>
5757
</dependency>
5858
</dependencies>

leshan-core-cf/src/test/java/org/eclipse/leshan/core/californium/ResponseCodeUtilTest.java

+22-16
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*******************************************************************************/
1616
package org.eclipse.leshan.core.californium;
1717

18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
20+
1821
import org.eclipse.californium.core.coap.CoAP.ResponseCode;
19-
import org.junit.Assert;
20-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2123

2224
public class ResponseCodeUtilTest {
2325

@@ -26,44 +28,48 @@ public void known_coap_code_to_known_lwm2m_Code() {
2628
org.eclipse.leshan.core.ResponseCode lwM2mResponseCode = ResponseCodeUtil
2729
.toLwM2mResponseCode(ResponseCode.CREATED);
2830

29-
Assert.assertEquals(org.eclipse.leshan.core.ResponseCode.CREATED, lwM2mResponseCode);
30-
Assert.assertEquals("CREATED(201)", lwM2mResponseCode.toString());
31+
assertEquals(org.eclipse.leshan.core.ResponseCode.CREATED, lwM2mResponseCode);
32+
assertEquals("CREATED(201)", lwM2mResponseCode.toString());
3133
}
3234

3335
@Test
3436
public void known_coap_code_to_unknown_lwm2m_code() {
3537
org.eclipse.leshan.core.ResponseCode lwM2mResponseCode = ResponseCodeUtil
3638
.toLwM2mResponseCode(ResponseCode.GATEWAY_TIMEOUT);
3739

38-
Assert.assertEquals(504, lwM2mResponseCode.getCode());
39-
Assert.assertEquals(org.eclipse.leshan.core.ResponseCode.UNKNOWN, lwM2mResponseCode.getName());
40-
Assert.assertEquals("UNKNOWN(504)", lwM2mResponseCode.toString());
40+
assertEquals(504, lwM2mResponseCode.getCode());
41+
assertEquals(org.eclipse.leshan.core.ResponseCode.UNKNOWN, lwM2mResponseCode.getName());
42+
assertEquals("UNKNOWN(504)", lwM2mResponseCode.toString());
4143
}
4244

4345
@Test
4446
public void known_lwm2m_code_to_known_coap_code() {
4547
ResponseCode coapResponseCode = ResponseCodeUtil
4648
.toCoapResponseCode(org.eclipse.leshan.core.ResponseCode.BAD_REQUEST);
4749

48-
Assert.assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode);
50+
assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode);
4951
}
5052

5153
@Test
5254
public void unknown_lwm2m_code_to_known_coap_code() {
5355
ResponseCode coapResponseCode = ResponseCodeUtil
5456
.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(503));
5557

56-
Assert.assertEquals(ResponseCode.SERVICE_UNAVAILABLE, coapResponseCode);
58+
assertEquals(ResponseCode.SERVICE_UNAVAILABLE, coapResponseCode);
5759
}
5860

59-
@Test(expected = IllegalArgumentException.class)
61+
@Test()
6062
public void unknown_lwm2m_code_to_invalid_coap_code() {
61-
ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(301));
63+
assertThrowsExactly(IllegalArgumentException.class, () -> {
64+
ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(301));
65+
});
6266
}
6367

64-
@Test(expected = IllegalArgumentException.class)
68+
@Test()
6569
public void unknown_lwm2m_code_to_invalid_coap_code2() {
66-
ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(441));
70+
assertThrowsExactly(IllegalArgumentException.class, () -> {
71+
ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(441));
72+
});
6773
}
6874

6975
@Test
@@ -73,15 +79,15 @@ public void unknown_lwm2m_code_to_unknown_coap_code() {
7379
// for success : code value is lost but we know we use an unknown code
7480
ResponseCode coapResponseCode = ResponseCodeUtil
7581
.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(206));
76-
Assert.assertEquals(ResponseCode._UNKNOWN_SUCCESS_CODE, coapResponseCode);
82+
assertEquals(ResponseCode._UNKNOWN_SUCCESS_CODE, coapResponseCode);
7783

7884
// for client error,: unknown code is replace by BAD REQUEST ...
7985
coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(425));
80-
Assert.assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode);
86+
assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode);
8187

8288
// for server error : unknown code is replace by INTERNAL SERVER ERROR ...
8389
coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(509));
84-
Assert.assertEquals(ResponseCode.INTERNAL_SERVER_ERROR, coapResponseCode);
90+
assertEquals(ResponseCode.INTERNAL_SERVER_ERROR, coapResponseCode);
8591

8692
}
8793
}

leshan-core-demo/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ Contributors:
5757

5858
<!-- test dependencies -->
5959
<dependency>
60-
<groupId>junit</groupId>
61-
<artifactId>junit</artifactId>
60+
<groupId>org.junit.jupiter</groupId>
61+
<artifactId>junit-jupiter-engine</artifactId>
6262
<scope>test</scope>
6363
</dependency>
6464
</dependencies>

leshan-core-demo/src/test/java/org/eclipse/leshan/core/demo/ValidateDemoModelsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.eclipse.leshan.core.model.InvalidDDFFileException;
2121
import org.eclipse.leshan.core.model.InvalidModelException;
2222
import org.eclipse.leshan.core.model.ObjectLoader;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
public class ValidateDemoModelsTest {
2626

0 commit comments

Comments
 (0)