Skip to content

Commit fff79ea

Browse files
authored
update(tests): migrate JUnit 4 code to JUnit 5 in core.base64 to core.sym (#1247)
1 parent 4e5f779 commit fff79ea

35 files changed

+643
-288
lines changed

src/test/java/com/fasterxml/jackson/core/JUnit5TestBase.java

+56
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,38 @@ public static IOContext testIOContext() {
243243
return TestSupport.testIOContext();
244244
}
245245

246+
protected void writeJsonDoc(JsonFactory f, String doc, JsonGenerator g) throws IOException
247+
{
248+
JsonParser p = f.createParser(a2q(doc));
249+
250+
while (p.nextToken() != null) {
251+
g.copyCurrentStructure(p);
252+
}
253+
p.close();
254+
g.close();
255+
}
256+
257+
protected String readAndWrite(JsonFactory f, JsonParser p) throws IOException
258+
{
259+
StringWriter sw = new StringWriter(100);
260+
JsonGenerator g = f.createGenerator(sw);
261+
g.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
262+
try {
263+
while (p.nextToken() != null) {
264+
g.copyCurrentEvent(p);
265+
}
266+
} catch (IOException e) {
267+
g.flush();
268+
throw new AssertionError(
269+
"Unexpected problem during `readAndWrite`. Output so far: '" +
270+
sw + "'; problem: " + e.getMessage(),
271+
e);
272+
}
273+
p.close();
274+
g.close();
275+
return sw.toString();
276+
}
277+
246278
/*
247279
/**********************************************************************
248280
/* Assertions
@@ -364,6 +396,30 @@ private static void fieldNameFor(StringBuilder sb, int index)
364396
}
365397
}
366398

399+
protected int[] calcQuads(String word) {
400+
return calcQuads(utf8Bytes(word));
401+
}
402+
403+
protected int[] calcQuads(byte[] wordBytes) {
404+
int blen = wordBytes.length;
405+
int[] result = new int[(blen + 3) / 4];
406+
for (int i = 0; i < blen; ++i) {
407+
int x = wordBytes[i] & 0xFF;
408+
409+
if (++i < blen) {
410+
x = (x << 8) | (wordBytes[i] & 0xFF);
411+
if (++i < blen) {
412+
x = (x << 8) | (wordBytes[i] & 0xFF);
413+
if (++i < blen) {
414+
x = (x << 8) | (wordBytes[i] & 0xFF);
415+
}
416+
}
417+
}
418+
result[i >> 2] = x;
419+
}
420+
return result;
421+
}
422+
367423
public static byte[] readResource(String ref)
368424
{
369425
ByteArrayOutputStream bytes = new ByteArrayOutputStream();

src/test/java/com/fasterxml/jackson/core/base64/Base64BinaryParsingTest.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88

99
import static org.junit.jupiter.api.Assertions.*;
1010

11-
public class Base64BinaryParsingTest
12-
extends JUnit5TestBase
11+
class Base64BinaryParsingTest
12+
extends JUnit5TestBase
1313
{
1414
private final JsonFactory JSON_F = newStreamFactory();
1515

1616
@Test
17-
public void testBase64UsingInputStream() throws Exception
17+
void base64UsingInputStream() throws Exception
1818
{
1919
_testBase64Text(MODE_INPUT_STREAM);
2020
_testBase64Text(MODE_INPUT_STREAM_THROTTLED);
2121
_testBase64Text(MODE_DATA_INPUT);
2222
}
2323

2424
@Test
25-
public void testBase64UsingReader() throws Exception
25+
void base64UsingReader() throws Exception
2626
{
2727
_testBase64Text(MODE_READER);
2828
}
2929

3030
@Test
31-
public void testStreaming() throws IOException
31+
void streaming() throws IOException
3232
{
3333
_testStreaming(MODE_INPUT_STREAM);
3434
_testStreaming(MODE_INPUT_STREAM_THROTTLED);
@@ -37,7 +37,7 @@ public void testStreaming() throws IOException
3737
}
3838

3939
@Test
40-
public void testSimple() throws IOException
40+
void simple() throws IOException
4141
{
4242
for (int mode : ALL_MODES) {
4343
// [core#414]: Allow leading/trailign white-space, ensure it is accepted
@@ -49,29 +49,29 @@ public void testSimple() throws IOException
4949
}
5050

5151
@Test
52-
public void testInArray() throws IOException
52+
void inArray() throws IOException
5353
{
5454
for (int mode : ALL_MODES) {
5555
_testInArray(mode);
5656
}
5757
}
5858

5959
@Test
60-
public void testWithEscaped() throws IOException {
60+
void withEscaped() throws IOException {
6161
for (int mode : ALL_MODES) {
6262
_testEscaped(mode);
6363
}
6464
}
6565

6666
@Test
67-
public void testWithEscapedPadding() throws IOException {
67+
void withEscapedPadding() throws IOException {
6868
for (int mode : ALL_MODES) {
6969
_testEscapedPadding(mode);
7070
}
7171
}
7272

7373
@Test
74-
public void testInvalidTokenForBase64() throws IOException
74+
void invalidTokenForBase64() throws IOException
7575
{
7676
for (int mode : ALL_MODES) {
7777

@@ -90,7 +90,7 @@ public void testInvalidTokenForBase64() throws IOException
9090
}
9191

9292
@Test
93-
public void testInvalidChar() throws IOException
93+
void invalidChar() throws IOException
9494
{
9595
for (int mode : ALL_MODES) {
9696

@@ -130,7 +130,7 @@ public void testInvalidChar() throws IOException
130130
}
131131

132132
@Test
133-
public void testOkMissingPadding() throws IOException {
133+
void okMissingPadding() throws IOException {
134134
final byte[] DOC1 = new byte[] { (byte) 0xAD };
135135
_testOkMissingPadding(DOC1, MODE_INPUT_STREAM);
136136
_testOkMissingPadding(DOC1, MODE_INPUT_STREAM_THROTTLED);
@@ -158,7 +158,7 @@ private void _testOkMissingPadding(byte[] input, int mode) throws IOException
158158
}
159159

160160
@Test
161-
public void testFailDueToMissingPadding() throws IOException {
161+
void failDueToMissingPadding() throws IOException {
162162
final String DOC1 = q("fQ"); // 1 bytes, no padding
163163
_testFailDueToMissingPadding(DOC1, MODE_INPUT_STREAM);
164164
_testFailDueToMissingPadding(DOC1, MODE_INPUT_STREAM_THROTTLED);

src/test/java/com/fasterxml/jackson/core/base64/Base64CodecTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
import static org.junit.jupiter.api.Assertions.*;
1010

11-
public class Base64CodecTest
12-
extends JUnit5TestBase
11+
class Base64CodecTest
12+
extends JUnit5TestBase
1313
{
1414
@Test
15-
public void testVariantAccess()
15+
void variantAccess()
1616
{
1717
for (Base64Variant var : new Base64Variant[] {
1818
Base64Variants.MIME,
@@ -32,7 +32,7 @@ public void testVariantAccess()
3232
}
3333

3434
@Test
35-
public void testProps()
35+
void props()
3636
{
3737
Base64Variant std = Base64Variants.MIME;
3838
// let's verify basic props of std cocec
@@ -47,7 +47,7 @@ public void testProps()
4747
}
4848

4949
@Test
50-
public void testCharEncoding() throws Exception
50+
void charEncoding() throws Exception
5151
{
5252
Base64Variant std = Base64Variants.MIME;
5353
assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char('?'));
@@ -82,7 +82,7 @@ public void testCharEncoding() throws Exception
8282
}
8383

8484
@Test
85-
public void testConvenienceMethods() throws Exception
85+
void convenienceMethods() throws Exception
8686
{
8787
final Base64Variant std = Base64Variants.MIME;
8888

@@ -105,7 +105,7 @@ public void testConvenienceMethods() throws Exception
105105
}
106106

107107
@Test
108-
public void testConvenienceMethodWithLFs() throws Exception
108+
void convenienceMethodWithLFs() throws Exception
109109
{
110110
final Base64Variant std = Base64Variants.MIME;
111111

@@ -133,7 +133,7 @@ public void testConvenienceMethodWithLFs() throws Exception
133133

134134
@SuppressWarnings("unused")
135135
@Test
136-
public void testErrors() throws Exception
136+
void errors() throws Exception
137137
{
138138
try {
139139
Base64Variant b = new Base64Variant("foobar", "xyz", false, '!', 24);
@@ -158,7 +158,7 @@ public void testErrors() throws Exception
158158
}
159159

160160
@Test
161-
public void testPaddingReadBehaviour() throws Exception {
161+
void paddingReadBehaviour() throws Exception {
162162

163163
for (Base64Variant variant: Arrays.asList(Base64Variants.MIME, Base64Variants.MIME_NO_LINEFEEDS, Base64Variants.PEM)) {
164164

src/test/java/com/fasterxml/jackson/core/base64/Base64GenerationTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import com.fasterxml.jackson.core.*;
88
import com.fasterxml.jackson.core.testsupport.ThrottledInputStream;
99

10-
import static org.junit.jupiter.api.Assertions.*;
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
1111

12-
public class Base64GenerationTest
13-
extends JUnit5TestBase
12+
class Base64GenerationTest
13+
extends JUnit5TestBase
1414
{
1515
/* The usual sample input string, from Thomas Hobbes's "Leviathan"
1616
* (via Wikipedia)
@@ -50,15 +50,15 @@ public class Base64GenerationTest
5050
private final JsonFactory JSON_F = new JsonFactory();
5151

5252
@Test
53-
public void testStreamingBinaryWrites() throws Exception
53+
void streamingBinaryWrites() throws Exception
5454
{
5555
_testStreamingWrites(JSON_F, true);
5656
_testStreamingWrites(JSON_F, false);
5757
}
5858

5959
// For [core#55]
6060
@Test
61-
public void testIssue55() throws Exception
61+
void issue55() throws Exception
6262
{
6363
final JsonFactory f = new JsonFactory();
6464

@@ -91,15 +91,15 @@ public void testIssue55() throws Exception
9191
* test things, as it does need writers to construct the data first.
9292
*/
9393
@Test
94-
public void testSimpleBinaryWrite() throws Exception
94+
void simpleBinaryWrite() throws Exception
9595
{
9696
_testSimpleBinaryWrite(false);
9797
_testSimpleBinaryWrite(true);
9898
}
9999

100100
// for [core#318]
101101
@Test
102-
public void testBinaryAsEmbeddedObject() throws Exception
102+
void binaryAsEmbeddedObject() throws Exception
103103
{
104104
JsonGenerator g;
105105

src/test/java/com/fasterxml/jackson/core/base64/Base64Padding912Test.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@
77
import static org.junit.jupiter.api.Assertions.assertEquals;
88
import static org.junit.jupiter.api.Assertions.assertNotNull;
99

10-
public class Base64Padding912Test
11-
extends JUnit5TestBase
10+
class Base64Padding912Test
11+
extends JUnit5TestBase
1212
{
1313
private final JsonFactory JSON_F = newStreamFactory();
1414

1515
@Test
16-
public void testPaddingUsingInputStream() throws Exception
16+
void paddingUsingInputStream() throws Exception
1717
{
1818
_testPadding(MODE_INPUT_STREAM);
1919
_testPadding(MODE_INPUT_STREAM_THROTTLED);
2020
}
2121

2222
@Test
23-
public void testPaddingUsingReader() throws Exception
23+
void paddingUsingReader() throws Exception
2424
{
2525
_testPadding(MODE_READER);
2626
}
2727

2828
@Test
29-
public void testPaddingUsingDataInput() throws Exception
29+
void paddingUsingDataInput() throws Exception
3030
{
3131
_testPadding(MODE_DATA_INPUT);
3232
}

src/test/java/com/fasterxml/jackson/core/constraints/DeeplyNestedContentReadTest.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
package com.fasterxml.jackson.core.constraints;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.fasterxml.jackson.core.*;
46
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
57

8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.fail;
10+
611
/**
712
* Unit test(s) for verifying handling of new (in 2.15) StreamReadConstraints
813
* wrt maximum nesting depth.
914
*/
10-
public class DeeplyNestedContentReadTest
11-
extends com.fasterxml.jackson.core.BaseTest
15+
class DeeplyNestedContentReadTest
16+
extends com.fasterxml.jackson.core.JUnit5TestBase
1217
{
1318
private final JsonFactory JSON_F = newStreamFactory();
1419

1520
private final int MAX_NESTING = StreamReadConstraints.DEFAULT_MAX_DEPTH;
1621

1722
private final int TESTED_NESTING = MAX_NESTING + 50;
18-
19-
public void testDeepNestingStreaming() throws Exception
23+
24+
@Test
25+
void deepNestingStreaming() throws Exception
2026
{
2127
final String DOC = createDeepNestedDoc(TESTED_NESTING);
2228
for (int mode : ALL_STREAMING_MODES) {
@@ -37,7 +43,8 @@ private void _testDeepNesting(JsonParser p) throws Exception
3743
}
3844
}
3945

40-
public void testLegacyConstraintSettingTest() throws Exception
46+
@Test
47+
void legacyConstraintSettingTest() throws Exception
4148
{
4249
final int LOWER_MAX = 40;
4350

0 commit comments

Comments
 (0)