Skip to content

Commit efbb39e

Browse files
committed
chore/test: Replace qualifications with imports
1 parent e57fa9f commit efbb39e

File tree

10 files changed

+518
-480
lines changed

10 files changed

+518
-480
lines changed

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

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

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

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

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
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-
Assertions.assertEquals(stream.read(dst), -1);
39+
assertEquals(stream.read(dst), -1);
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-
Assertions.assertEquals(stream.read(dst), 1);
46-
Assertions.assertEquals(stream.read(dst), -1); // end of stream
47+
assertEquals(stream.read(dst), 1);
48+
assertEquals(stream.read(dst), -1); // end of stream
4749
}
4850
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
import org.junit.jupiter.api.Assertions;
44
import org.junit.jupiter.api.Test;
55

6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
68
public class DefaultAllocatorTest {
79
@Test
810
public void maxSegmentBytes() {
911
DefaultAllocator allocator = new DefaultAllocator();
10-
Assertions.assertEquals(allocator.allocationStrategy,
12+
assertEquals(allocator.allocationStrategy,
1113
BuilderArena.AllocationStrategy.GROW_HEURISTICALLY);
1214
allocator.maxSegmentBytes = (1 << 25) - 1;
1315

1416
int allocationSize = 1 << 24;
1517
allocator.setNextAllocationSizeBytes(allocationSize);
1618

17-
Assertions.assertEquals(allocationSize,
19+
assertEquals(allocationSize,
1820
allocator.allocateSegment(allocationSize).capacity());
1921

20-
Assertions.assertEquals(allocator.maxSegmentBytes,
22+
assertEquals(allocator.maxSegmentBytes,
2123
allocator.allocateSegment(allocationSize).capacity());
2224

23-
Assertions.assertEquals(allocator.maxSegmentBytes,
25+
assertEquals(allocator.maxSegmentBytes,
2426
allocator.allocateSegment(allocationSize).capacity());
2527
}
2628
}

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

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
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,40 +33,40 @@ public void testSimpleRawDataStruct() {
3033

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

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

6972
/**
@@ -86,7 +89,7 @@ public void readStructPointerShouldThrowDecodeExceptionOnOutOfBoundsStructPointe
8689

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

89-
Assertions.assertThrows(DecodeException.class, () -> 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

@@ -114,7 +117,7 @@ public void readListPointerShouldThrowDecodeExceptionOnOutOfBoundsCompositeListP
114117

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

117-
Assertions.assertThrows(DecodeException.class, () -> 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-
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));
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
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import java.nio.ByteBuffer;
77

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

1012
@Test
@@ -14,6 +16,6 @@ public void _setBooleanElementShouldNotOverflowDuringPositionOffsetCalculation()
1416
SegmentBuilder segmentBuilder = new SegmentBuilder(buffer, builderArena);
1517
ListBuilder listBuilder = new ListBuilder(segmentBuilder, 0, 0, 2, 0, (short) 0);
1618

17-
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> listBuilder._setBooleanElement(Integer.MAX_VALUE, true));
19+
assertThrows(IndexOutOfBoundsException.class, () -> listBuilder._setBooleanElement(Integer.MAX_VALUE, true));
1820
}
1921
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,29 @@
77
import java.nio.ByteBuffer;
88
import java.nio.ByteOrder;
99

10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
1012
public class SegmentReaderTest {
1113

1214
@Test
1315
public void in_boundsCalculationShouldNotOverflow() {
1416
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
1517
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
16-
Assertions.assertEquals(segmentReader.isInBounds(0, Integer.MAX_VALUE), false);
18+
assertEquals(segmentReader.isInBounds(0, Integer.MAX_VALUE), false);
1719
}
1820

1921
@Test
2022
public void oneWordAtLastWordShouldBeInBounds() {
2123
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
2224
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
23-
Assertions.assertEquals(segmentReader.isInBounds(7, 1), true);
25+
assertEquals(segmentReader.isInBounds(7, 1), true);
2426
}
2527

2628
@Test
2729
public void twoWordsAtLastWordShouldNotBeInBounds() {
2830
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
2931
SegmentReader segmentReader = new SegmentReader(byteBuffer, null);
30-
Assertions.assertEquals(segmentReader.isInBounds(7, 2), false);
32+
assertEquals(segmentReader.isInBounds(7, 2), false);
3133
}
3234

3335
@Test
@@ -76,15 +78,15 @@ public void validSegmentWithNegativeOffsetShouldBeInBounds() {
7678
refTarget = WirePointer.target(refOffset, ref);
7779
dataSizeWords = StructPointer.dataSize(ref);
7880
wordSize = dataSizeWords + StructPointer.ptrCount(ref);
79-
Assertions.assertEquals(segment.isInBounds(refTarget, wordSize), true);
81+
assertEquals(segment.isInBounds(refTarget, wordSize), true);
8082

8183
/* Read inner Struct: ComObject. */
8284
refOffset = refTarget + dataSizeWords; /* At the inner STRUCT POINTER */
8385
ref = segment.get(refOffset);
8486
refTarget = WirePointer.target(refOffset, ref);
8587
dataSizeWords = StructPointer.dataSize(ref);
8688
wordSize = dataSizeWords + StructPointer.ptrCount(ref);
87-
Assertions.assertEquals(segment.isInBounds(refTarget, wordSize), true);
89+
assertEquals(segment.isInBounds(refTarget, wordSize), true);
8890
}
8991

9092
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import java.util.Arrays;
1010
import java.util.concurrent.TimeUnit;
1111

12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertThrows;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
import static org.junit.jupiter.api.Assertions.fail;
16+
1217
public class SerializePackedTest {
1318

1419
@Test
@@ -63,10 +68,10 @@ private void assertPacksTo(byte[] unpacked, byte[] packed) {
6368
try {
6469
packedOutputStream.write(ByteBuffer.wrap(unpacked));
6570
} catch (IOException e) {
66-
Assertions.fail("Failed writing to PackedOutputStream");
71+
fail("Failed writing to PackedOutputStream");
6772
}
6873

69-
Assertions.assertTrue(Arrays.equals(bytes, packed));
74+
assertTrue(Arrays.equals(bytes, packed));
7075
}
7176

7277
{
@@ -77,25 +82,25 @@ private void assertPacksTo(byte[] unpacked, byte[] packed) {
7782
try {
7883
n = stream.read(ByteBuffer.wrap(bytes));
7984
} catch (IOException e) {
80-
Assertions.fail("Failed reading from PackedInputStream");
85+
fail("Failed reading from PackedInputStream");
8186
}
8287

83-
Assertions.assertEquals(n, unpacked.length);
84-
Assertions.assertTrue(Arrays.equals(bytes, unpacked));
88+
assertEquals(n, unpacked.length);
89+
assertTrue(Arrays.equals(bytes, unpacked));
8590
}
8691
}
8792

8893
@Test
8994
@Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
9095
public void read_shouldThrowDecodingExceptionOnEmptyArrayInputStream() throws IOException {
9196
byte[] emptyByteArray = {};
92-
Assertions.assertThrows(DecodeException.class, () -> SerializePacked.read(new ArrayInputStream(ByteBuffer.wrap(emptyByteArray)), ReaderOptions.DEFAULT_READER_OPTIONS));
97+
assertThrows(DecodeException.class, () -> SerializePacked.read(new ArrayInputStream(ByteBuffer.wrap(emptyByteArray)), ReaderOptions.DEFAULT_READER_OPTIONS));
9398
}
9499

95100
@Test
96101
@Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
97102
public void read_shouldThrowDecodingExceptionWhenTryingToReadMoreThanAvailableFromArrayInputStream() throws IOException {
98103
byte[] bytes = {17, 0, 127, 0, 0, 0, 0}; //segment0 size of 127 words, which is way larger than the tiny 7 byte input
99-
Assertions.assertThrows(DecodeException.class, () -> SerializePacked.read(new ArrayInputStream(ByteBuffer.wrap(bytes)), ReaderOptions.DEFAULT_READER_OPTIONS));
104+
assertThrows(DecodeException.class, () -> SerializePacked.read(new ArrayInputStream(ByteBuffer.wrap(bytes)), ReaderOptions.DEFAULT_READER_OPTIONS));
100105
}
101106
}

0 commit comments

Comments
 (0)