Skip to content

Commit 0fd8452

Browse files
authored
Merge pull request #145 from spryslmatej/chore/sm/junit5
chore: Upgrade test framework to JUnit5
2 parents b2f7242 + 855faf6 commit 0fd8452

File tree

12 files changed

+723
-686
lines changed

12 files changed

+723
-686
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: 391 additions & 383 deletions
Large diffs are not rendered by default.

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

Lines changed: 191 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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
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

29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
2931
public class ArrayInputStreamTest {
3032
@Test
3133
public void testEmptyArray() throws java.io.IOException {
@@ -34,15 +36,15 @@ public void testEmptyArray() throws java.io.IOException {
3436

3537
// read() should return -1 at the end of the stream
3638
// https://docs.oracle.com/javase/7/docs/api/java/nio/channels/ReadableByteChannel.html
37-
Assert.assertEquals(stream.read(dst), -1);
39+
assertEquals(-1, stream.read(dst));
3840
}
3941

4042
@Test
4143
public void testRequestMoreBytesThanArePresent() throws java.io.IOException {
4244
byte[] oneByte = new byte[]{42};
4345
ArrayInputStream stream = new ArrayInputStream(ByteBuffer.wrap(oneByte));
4446
ByteBuffer dst = ByteBuffer.allocate(10);
45-
Assert.assertEquals(stream.read(dst), 1);
46-
Assert.assertEquals(stream.read(dst), -1); // end of stream
47+
assertEquals(1, stream.read(dst));
48+
assertEquals(-1, stream.read(dst)); // end of stream
4749
}
4850
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
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+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
57

68
public class DefaultAllocatorTest {
79
@Test
810
public void maxSegmentBytes() {
911
DefaultAllocator allocator = new DefaultAllocator();
10-
Assert.assertEquals(allocator.allocationStrategy,
11-
BuilderArena.AllocationStrategy.GROW_HEURISTICALLY);
12+
assertEquals(BuilderArena.AllocationStrategy.GROW_HEURISTICALLY, allocator.allocationStrategy);
1213
allocator.maxSegmentBytes = (1 << 25) - 1;
1314

1415
int allocationSize = 1 << 24;
1516
allocator.setNextAllocationSizeBytes(allocationSize);
1617

17-
Assert.assertEquals(allocationSize,
18+
assertEquals(allocationSize,
1819
allocator.allocateSegment(allocationSize).capacity());
1920

20-
Assert.assertEquals(allocator.maxSegmentBytes,
21+
assertEquals(allocator.maxSegmentBytes,
2122
allocator.allocateSegment(allocationSize).capacity());
2223

23-
Assert.assertEquals(allocator.maxSegmentBytes,
24+
assertEquals(allocator.maxSegmentBytes,
2425
allocator.allocateSegment(allocationSize).capacity());
2526
}
2627
}

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

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
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;
88

9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertThrows;
11+
912
public class LayoutTest {
1013

1114
private static final int MAX_NESTING_LIMIT = 0x7fffffff;
@@ -30,46 +33,46 @@ public void testSimpleRawDataStruct() {
3033

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

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

6972
/**
7073
* @see <a href="https://github.com/capnproto/capnproto-java/issues/122">#122</a>
7174
*/
72-
@Test(expected = DecodeException.class)
75+
@Test
7376
public void readStructPointerShouldThrowDecodeExceptionOnOutOfBoundsStructPointer() {
7477
byte[] brokenMSG = new byte[]{
7578
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, //declare word size of 7, with payload of only 6 words
@@ -86,7 +89,7 @@ public void readStructPointerShouldThrowDecodeExceptionOnOutOfBoundsStructPointe
8689

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

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

9295

@@ -100,7 +103,7 @@ public ListReader constructReader(SegmentReader segment, int ptr, int elementCou
100103
}
101104
}
102105

103-
@Test(expected = DecodeException.class)
106+
@Test
104107
public void readListPointerShouldThrowDecodeExceptionOnOutOfBoundsCompositeListPointer() {
105108
byte[] brokenMSG = {
106109
// 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 +117,7 @@ public void readListPointerShouldThrowDecodeExceptionOnOutOfBoundsCompositeListP
114117

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

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

120123
private class BareStructBuilder implements StructBuilder.Factory<StructBuilder> {
@@ -165,17 +168,17 @@ private void setUpStruct(StructBuilder builder) {
165168
}
166169

167170
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));
171+
assertEquals(0x1011121314151617L, builder._getLongField(0));
172+
assertEquals(0x20212223, builder._getIntField(2));
173+
assertEquals(0x3031, builder._getShortField(6));
174+
assertEquals(0x40, builder._getByteField(14));
175+
assertEquals(false, builder._getBooleanField(120));
176+
assertEquals(false, builder._getBooleanField(121));
177+
assertEquals(true, builder._getBooleanField(122));
178+
assertEquals(false, builder._getBooleanField(123));
179+
assertEquals(true, builder._getBooleanField(124));
180+
assertEquals(true, builder._getBooleanField(125));
181+
assertEquals(true, builder._getBooleanField(126));
182+
assertEquals(false, builder._getBooleanField(127));
180183
}
181184
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
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

8+
import static org.junit.jupiter.api.Assertions.assertThrows;
9+
710
public class ListBuilderTest {
811

9-
@Test(expected = IndexOutOfBoundsException.class)
12+
@Test
1013
public void _setBooleanElementShouldNotOverflowDuringPositionOffsetCalculation() {
1114
ByteBuffer buffer = ByteBuffer.allocate(10);
1215
BuilderArena builderArena = new BuilderArena(new DefaultAllocator());
1316
SegmentBuilder segmentBuilder = new SegmentBuilder(buffer, builderArena);
1417
ListBuilder listBuilder = new ListBuilder(segmentBuilder, 0, 0, 2, 0, (short) 0);
1518

16-
listBuilder._setBooleanElement(Integer.MAX_VALUE, true);
19+
assertThrows(IndexOutOfBoundsException.class, () -> listBuilder._setBooleanElement(Integer.MAX_VALUE, true));
1720
}
1821
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
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;
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
1111

1212
public class SegmentReaderTest {
1313

1414
@Test
1515
public void in_boundsCalculationShouldNotOverflow() {
1616
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
1717
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
18-
MatcherAssert.assertThat(segmentReader.isInBounds(0, Integer.MAX_VALUE), is(false));
18+
assertEquals(false, segmentReader.isInBounds(0, Integer.MAX_VALUE));
1919
}
2020

2121
@Test
2222
public void oneWordAtLastWordShouldBeInBounds() {
2323
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
2424
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
25-
MatcherAssert.assertThat(segmentReader.isInBounds(7, 1), is(true));
25+
assertEquals(true, segmentReader.isInBounds(7, 1));
2626
}
2727

2828
@Test
2929
public void twoWordsAtLastWordShouldNotBeInBounds() {
3030
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
3131
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
32-
MatcherAssert.assertThat(segmentReader.isInBounds(7, 2), is(false));
32+
assertEquals(false, segmentReader.isInBounds(7, 2));
3333
}
3434

3535
@Test
@@ -78,15 +78,15 @@ public void validSegmentWithNegativeOffsetShouldBeInBounds() {
7878
refTarget = WirePointer.target(refOffset, ref);
7979
dataSizeWords = StructPointer.dataSize(ref);
8080
wordSize = dataSizeWords + StructPointer.ptrCount(ref);
81-
MatcherAssert.assertThat(segment.isInBounds(refTarget, wordSize), is(true));
81+
assertEquals(true, segment.isInBounds(refTarget, wordSize));
8282

8383
/* Read inner Struct: ComObject. */
8484
refOffset = refTarget + dataSizeWords; /* At the inner STRUCT POINTER */
8585
ref = segment.get(refOffset);
8686
refTarget = WirePointer.target(refOffset, ref);
8787
dataSizeWords = StructPointer.dataSize(ref);
8888
wordSize = dataSizeWords + StructPointer.ptrCount(ref);
89-
MatcherAssert.assertThat(segment.isInBounds(refTarget, wordSize), is(true));
89+
assertEquals(true, segment.isInBounds(refTarget, wordSize));
9090
}
9191

9292
}

0 commit comments

Comments
 (0)