Skip to content

Commit e57fa9f

Browse files
committed
chore/test: Upgrade JUnit4 to JUnit5
1 parent b2f7242 commit e57fa9f

File tree

12 files changed

+687
-687
lines changed

12 files changed

+687
-687
lines changed

compiler/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
</properties>
3737
<dependencies>
3838
<dependency>
39-
<groupId>junit</groupId>
40-
<artifactId>junit</artifactId>
41-
<version>4.13.1</version>
39+
<groupId>org.junit.jupiter</groupId>
40+
<artifactId>junit-jupiter</artifactId>
41+
<version>5.11.4</version>
4242
<scope>test</scope>
4343
</dependency>
4444

compiler/src/test/java/org/capnproto/test/EncodingTest.java

Lines changed: 383 additions & 383 deletions
Large diffs are not rendered by default.

compiler/src/test/java/org/capnproto/test/TestUtil.java

Lines changed: 185 additions & 185 deletions
Large diffs are not rendered by default.

runtime/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
</properties>
3737
<dependencies>
3838
<dependency>
39-
<groupId>junit</groupId>
40-
<artifactId>junit</artifactId>
41-
<version>4.13.1</version>
39+
<groupId>org.junit.jupiter</groupId>
40+
<artifactId>junit-jupiter</artifactId>
41+
<version>5.11.4</version>
4242
<scope>test</scope>
4343
</dependency>
4444
</dependencies>

runtime/src/test/java/org/capnproto/ArrayInputStreamTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
package org.capnproto;
2323

24-
import org.junit.Assert;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.api.Test;
2626

2727
import java.nio.ByteBuffer;
2828

@@ -34,15 +34,15 @@ public void testEmptyArray() throws java.io.IOException {
3434

3535
// read() should return -1 at the end of the stream
3636
// https://docs.oracle.com/javase/7/docs/api/java/nio/channels/ReadableByteChannel.html
37-
Assert.assertEquals(stream.read(dst), -1);
37+
Assertions.assertEquals(stream.read(dst), -1);
3838
}
3939

4040
@Test
4141
public void testRequestMoreBytesThanArePresent() throws java.io.IOException {
4242
byte[] oneByte = new byte[]{42};
4343
ArrayInputStream stream = new ArrayInputStream(ByteBuffer.wrap(oneByte));
4444
ByteBuffer dst = ByteBuffer.allocate(10);
45-
Assert.assertEquals(stream.read(dst), 1);
46-
Assert.assertEquals(stream.read(dst), -1); // end of stream
45+
Assertions.assertEquals(stream.read(dst), 1);
46+
Assertions.assertEquals(stream.read(dst), -1); // end of stream
4747
}
4848
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
package org.capnproto;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
55

66
public class DefaultAllocatorTest {
77
@Test
88
public void maxSegmentBytes() {
99
DefaultAllocator allocator = new DefaultAllocator();
10-
Assert.assertEquals(allocator.allocationStrategy,
10+
Assertions.assertEquals(allocator.allocationStrategy,
1111
BuilderArena.AllocationStrategy.GROW_HEURISTICALLY);
1212
allocator.maxSegmentBytes = (1 << 25) - 1;
1313

1414
int allocationSize = 1 << 24;
1515
allocator.setNextAllocationSizeBytes(allocationSize);
1616

17-
Assert.assertEquals(allocationSize,
17+
Assertions.assertEquals(allocationSize,
1818
allocator.allocateSegment(allocationSize).capacity());
1919

20-
Assert.assertEquals(allocator.maxSegmentBytes,
20+
Assertions.assertEquals(allocator.maxSegmentBytes,
2121
allocator.allocateSegment(allocationSize).capacity());
2222

23-
Assert.assertEquals(allocator.maxSegmentBytes,
23+
Assertions.assertEquals(allocator.maxSegmentBytes,
2424
allocator.allocateSegment(allocationSize).capacity());
2525
}
2626
}

runtime/src/test/java/org/capnproto/LayoutTest.java

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.capnproto;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
55

66
import java.nio.ByteBuffer;
77
import java.nio.ByteOrder;
@@ -30,46 +30,46 @@ public void testSimpleRawDataStruct() {
3030

3131
StructReader reader = WireHelpers.readStructPointer(new BareStructReader(), arena.tryGetSegment(0), 0, null, 0, MAX_NESTING_LIMIT);
3232

33-
Assert.assertEquals(reader._getLongField(0), 0xefcdab8967452301L);
34-
Assert.assertEquals(reader._getLongField(1), 0L);
35-
36-
Assert.assertEquals(reader._getIntField(0), 0x67452301);
37-
Assert.assertEquals(reader._getIntField(1), 0xefcdab89);
38-
Assert.assertEquals(reader._getIntField(2), 0);
39-
40-
Assert.assertEquals(reader._getShortField(0), (short)0x2301);
41-
Assert.assertEquals(reader._getShortField(1), (short)0x6745);
42-
Assert.assertEquals(reader._getShortField(2), (short)0xab89);
43-
Assert.assertEquals(reader._getShortField(3), (short)0xefcd);
44-
Assert.assertEquals(reader._getShortField(4), (short)0);
45-
46-
Assert.assertEquals(reader._getBooleanField(0), true);
47-
Assert.assertEquals(reader._getBooleanField(1), false);
48-
Assert.assertEquals(reader._getBooleanField(2), false);
49-
50-
Assert.assertEquals(reader._getBooleanField(3), false);
51-
Assert.assertEquals(reader._getBooleanField(4), false);
52-
Assert.assertEquals(reader._getBooleanField(5), false);
53-
Assert.assertEquals(reader._getBooleanField(6), false);
54-
Assert.assertEquals(reader._getBooleanField(7), false);
55-
56-
Assert.assertEquals(reader._getBooleanField(8), true);
57-
Assert.assertEquals(reader._getBooleanField(9), true);
58-
Assert.assertEquals(reader._getBooleanField(10), false);
59-
Assert.assertEquals(reader._getBooleanField(11), false);
60-
Assert.assertEquals(reader._getBooleanField(12), false);
61-
Assert.assertEquals(reader._getBooleanField(13), true);
62-
Assert.assertEquals(reader._getBooleanField(14), false);
63-
Assert.assertEquals(reader._getBooleanField(15), false);
64-
65-
Assert.assertEquals(reader._getBooleanField(63), true);
66-
Assert.assertEquals(reader._getBooleanField(64), false);
33+
Assertions.assertEquals(reader._getLongField(0), 0xefcdab8967452301L);
34+
Assertions.assertEquals(reader._getLongField(1), 0L);
35+
36+
Assertions.assertEquals(reader._getIntField(0), 0x67452301);
37+
Assertions.assertEquals(reader._getIntField(1), 0xefcdab89);
38+
Assertions.assertEquals(reader._getIntField(2), 0);
39+
40+
Assertions.assertEquals(reader._getShortField(0), (short)0x2301);
41+
Assertions.assertEquals(reader._getShortField(1), (short)0x6745);
42+
Assertions.assertEquals(reader._getShortField(2), (short)0xab89);
43+
Assertions.assertEquals(reader._getShortField(3), (short)0xefcd);
44+
Assertions.assertEquals(reader._getShortField(4), (short)0);
45+
46+
Assertions.assertEquals(reader._getBooleanField(0), true);
47+
Assertions.assertEquals(reader._getBooleanField(1), false);
48+
Assertions.assertEquals(reader._getBooleanField(2), false);
49+
50+
Assertions.assertEquals(reader._getBooleanField(3), false);
51+
Assertions.assertEquals(reader._getBooleanField(4), false);
52+
Assertions.assertEquals(reader._getBooleanField(5), false);
53+
Assertions.assertEquals(reader._getBooleanField(6), false);
54+
Assertions.assertEquals(reader._getBooleanField(7), false);
55+
56+
Assertions.assertEquals(reader._getBooleanField(8), true);
57+
Assertions.assertEquals(reader._getBooleanField(9), true);
58+
Assertions.assertEquals(reader._getBooleanField(10), false);
59+
Assertions.assertEquals(reader._getBooleanField(11), false);
60+
Assertions.assertEquals(reader._getBooleanField(12), false);
61+
Assertions.assertEquals(reader._getBooleanField(13), true);
62+
Assertions.assertEquals(reader._getBooleanField(14), false);
63+
Assertions.assertEquals(reader._getBooleanField(15), false);
64+
65+
Assertions.assertEquals(reader._getBooleanField(63), true);
66+
Assertions.assertEquals(reader._getBooleanField(64), false);
6767
}
6868

6969
/**
7070
* @see <a href="https://github.com/capnproto/capnproto-java/issues/122">#122</a>
7171
*/
72-
@Test(expected = DecodeException.class)
72+
@Test
7373
public void readStructPointerShouldThrowDecodeExceptionOnOutOfBoundsStructPointer() {
7474
byte[] brokenMSG = new byte[]{
7575
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, //declare word size of 7, with payload of only 6 words
@@ -86,7 +86,7 @@ public void readStructPointerShouldThrowDecodeExceptionOnOutOfBoundsStructPointe
8686

8787
ReaderArena arena = new ReaderArena(new ByteBuffer[]{ buffer }, 0x7fffffffffffffffL);
8888

89-
StructReader reader = WireHelpers.readStructPointer(new BareStructReader(), arena.tryGetSegment(0), 0, null, 0, MAX_NESTING_LIMIT);
89+
Assertions.assertThrows(DecodeException.class, () -> WireHelpers.readStructPointer(new BareStructReader(), arena.tryGetSegment(0), 0, null, 0, MAX_NESTING_LIMIT));
9090
}
9191

9292

@@ -100,7 +100,7 @@ public ListReader constructReader(SegmentReader segment, int ptr, int elementCou
100100
}
101101
}
102102

103-
@Test(expected = DecodeException.class)
103+
@Test
104104
public void readListPointerShouldThrowDecodeExceptionOnOutOfBoundsCompositeListPointer() {
105105
byte[] brokenMSG = {
106106
// set list pointer bits to 1, elementSize to 7 to indicate composite list and number of words in the list (minus tag) to 0x1FFFFFFF (max value possible in 29b limit)
@@ -114,7 +114,7 @@ public void readListPointerShouldThrowDecodeExceptionOnOutOfBoundsCompositeListP
114114

115115
ReaderArena arena = new ReaderArena(new ByteBuffer[]{buffer}, 0x7fffffffffffffffL);
116116

117-
ListReader reader = WireHelpers.readListPointer(new BareListReader(), arena.tryGetSegment(0), 0, null, 0, (byte) 0, MAX_NESTING_LIMIT);
117+
Assertions.assertThrows(DecodeException.class, () -> WireHelpers.readListPointer(new BareListReader(), arena.tryGetSegment(0), 0, null, 0, (byte) 0, MAX_NESTING_LIMIT));
118118
}
119119

120120
private class BareStructBuilder implements StructBuilder.Factory<StructBuilder> {
@@ -165,17 +165,17 @@ private void setUpStruct(StructBuilder builder) {
165165
}
166166

167167
private void checkStruct(StructBuilder builder) {
168-
Assert.assertEquals(0x1011121314151617L, builder._getLongField(0));
169-
Assert.assertEquals(0x20212223, builder._getIntField(2));
170-
Assert.assertEquals(0x3031, builder._getShortField(6));
171-
Assert.assertEquals(0x40, builder._getByteField(14));
172-
Assert.assertEquals(false, builder._getBooleanField(120));
173-
Assert.assertEquals(false, builder._getBooleanField(121));
174-
Assert.assertEquals(true, builder._getBooleanField(122));
175-
Assert.assertEquals(false, builder._getBooleanField(123));
176-
Assert.assertEquals(true, builder._getBooleanField(124));
177-
Assert.assertEquals(true, builder._getBooleanField(125));
178-
Assert.assertEquals(true, builder._getBooleanField(126));
179-
Assert.assertEquals(false, builder._getBooleanField(127));
168+
Assertions.assertEquals(0x1011121314151617L, builder._getLongField(0));
169+
Assertions.assertEquals(0x20212223, builder._getIntField(2));
170+
Assertions.assertEquals(0x3031, builder._getShortField(6));
171+
Assertions.assertEquals(0x40, builder._getByteField(14));
172+
Assertions.assertEquals(false, builder._getBooleanField(120));
173+
Assertions.assertEquals(false, builder._getBooleanField(121));
174+
Assertions.assertEquals(true, builder._getBooleanField(122));
175+
Assertions.assertEquals(false, builder._getBooleanField(123));
176+
Assertions.assertEquals(true, builder._getBooleanField(124));
177+
Assertions.assertEquals(true, builder._getBooleanField(125));
178+
Assertions.assertEquals(true, builder._getBooleanField(126));
179+
Assertions.assertEquals(false, builder._getBooleanField(127));
180180
}
181181
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package org.capnproto;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
45

56
import java.nio.ByteBuffer;
67

78
public class ListBuilderTest {
89

9-
@Test(expected = IndexOutOfBoundsException.class)
10+
@Test
1011
public void _setBooleanElementShouldNotOverflowDuringPositionOffsetCalculation() {
1112
ByteBuffer buffer = ByteBuffer.allocate(10);
1213
BuilderArena builderArena = new BuilderArena(new DefaultAllocator());
1314
SegmentBuilder segmentBuilder = new SegmentBuilder(buffer, builderArena);
1415
ListBuilder listBuilder = new ListBuilder(segmentBuilder, 0, 0, 2, 0, (short) 0);
1516

16-
listBuilder._setBooleanElement(Integer.MAX_VALUE, true);
17+
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> listBuilder._setBooleanElement(Integer.MAX_VALUE, true));
1718
}
1819
}

runtime/src/test/java/org/capnproto/SegmentReaderTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
package org.capnproto;
22

33
import org.capnproto.WireHelpers.FollowFarsResult;
4-
import org.hamcrest.MatcherAssert;
5-
import org.junit.Test;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
66

77
import java.nio.ByteBuffer;
88
import java.nio.ByteOrder;
99

10-
import static org.hamcrest.CoreMatchers.is;
11-
1210
public class SegmentReaderTest {
1311

1412
@Test
1513
public void in_boundsCalculationShouldNotOverflow() {
1614
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
1715
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
18-
MatcherAssert.assertThat(segmentReader.isInBounds(0, Integer.MAX_VALUE), is(false));
16+
Assertions.assertEquals(segmentReader.isInBounds(0, Integer.MAX_VALUE), false);
1917
}
2018

2119
@Test
2220
public void oneWordAtLastWordShouldBeInBounds() {
2321
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
2422
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
25-
MatcherAssert.assertThat(segmentReader.isInBounds(7, 1), is(true));
23+
Assertions.assertEquals(segmentReader.isInBounds(7, 1), true);
2624
}
2725

2826
@Test
2927
public void twoWordsAtLastWordShouldNotBeInBounds() {
3028
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
3129
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
32-
MatcherAssert.assertThat(segmentReader.isInBounds(7, 2), is(false));
30+
Assertions.assertEquals(segmentReader.isInBounds(7, 2), false);
3331
}
3432

3533
@Test
@@ -78,15 +76,15 @@ public void validSegmentWithNegativeOffsetShouldBeInBounds() {
7876
refTarget = WirePointer.target(refOffset, ref);
7977
dataSizeWords = StructPointer.dataSize(ref);
8078
wordSize = dataSizeWords + StructPointer.ptrCount(ref);
81-
MatcherAssert.assertThat(segment.isInBounds(refTarget, wordSize), is(true));
79+
Assertions.assertEquals(segment.isInBounds(refTarget, wordSize), true);
8280

8381
/* Read inner Struct: ComObject. */
8482
refOffset = refTarget + dataSizeWords; /* At the inner STRUCT POINTER */
8583
ref = segment.get(refOffset);
8684
refTarget = WirePointer.target(refOffset, ref);
8785
dataSizeWords = StructPointer.dataSize(ref);
8886
wordSize = dataSizeWords + StructPointer.ptrCount(ref);
89-
MatcherAssert.assertThat(segment.isInBounds(refTarget, wordSize), is(true));
87+
Assertions.assertEquals(segment.isInBounds(refTarget, wordSize), true);
9088
}
9189

9290
}

runtime/src/test/java/org/capnproto/SerializePackedTest.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.capnproto;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.api.Timeout;
56

67
import java.io.IOException;
78
import java.nio.ByteBuffer;
89
import java.util.Arrays;
10+
import java.util.concurrent.TimeUnit;
911

1012
public class SerializePackedTest {
1113

@@ -61,10 +63,10 @@ private void assertPacksTo(byte[] unpacked, byte[] packed) {
6163
try {
6264
packedOutputStream.write(ByteBuffer.wrap(unpacked));
6365
} catch (IOException e) {
64-
Assert.fail("Failed writing to PackedOutputStream");
66+
Assertions.fail("Failed writing to PackedOutputStream");
6567
}
6668

67-
Assert.assertTrue(Arrays.equals(bytes, packed));
69+
Assertions.assertTrue(Arrays.equals(bytes, packed));
6870
}
6971

7072
{
@@ -75,23 +77,25 @@ private void assertPacksTo(byte[] unpacked, byte[] packed) {
7577
try {
7678
n = stream.read(ByteBuffer.wrap(bytes));
7779
} catch (IOException e) {
78-
Assert.fail("Failed reading from PackedInputStream");
80+
Assertions.fail("Failed reading from PackedInputStream");
7981
}
8082

81-
Assert.assertEquals(n, unpacked.length);
82-
Assert.assertTrue(Arrays.equals(bytes, unpacked));
83+
Assertions.assertEquals(n, unpacked.length);
84+
Assertions.assertTrue(Arrays.equals(bytes, unpacked));
8385
}
8486
}
8587

86-
@Test(timeout = 1000, expected = DecodeException.class)
88+
@Test
89+
@Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
8790
public void read_shouldThrowDecodingExceptionOnEmptyArrayInputStream() throws IOException {
8891
byte[] emptyByteArray = {};
89-
MessageReader reader = SerializePacked.read(new ArrayInputStream(ByteBuffer.wrap(emptyByteArray)), ReaderOptions.DEFAULT_READER_OPTIONS);
92+
Assertions.assertThrows(DecodeException.class, () -> SerializePacked.read(new ArrayInputStream(ByteBuffer.wrap(emptyByteArray)), ReaderOptions.DEFAULT_READER_OPTIONS));
9093
}
9194

92-
@Test(timeout = 1000, expected = DecodeException.class)
95+
@Test
96+
@Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
9397
public void read_shouldThrowDecodingExceptionWhenTryingToReadMoreThanAvailableFromArrayInputStream() throws IOException {
9498
byte[] bytes = {17, 0, 127, 0, 0, 0, 0}; //segment0 size of 127 words, which is way larger than the tiny 7 byte input
95-
MessageReader reader = SerializePacked.read(new ArrayInputStream(ByteBuffer.wrap(bytes)), ReaderOptions.DEFAULT_READER_OPTIONS);
99+
Assertions.assertThrows(DecodeException.class, () -> SerializePacked.read(new ArrayInputStream(ByteBuffer.wrap(bytes)), ReaderOptions.DEFAULT_READER_OPTIONS));
96100
}
97101
}

0 commit comments

Comments
 (0)