Skip to content

Commit ec58aab

Browse files
authored
[ JSTEP-10 ] Migrate smile module tests to JUnit 5 (#553)
1 parent 697797b commit ec58aab

File tree

81 files changed

+690
-260
lines changed

Some content is hidden

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

81 files changed

+690
-260
lines changed

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/BaseTestForSmile.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package com.fasterxml.jackson.dataformat.smile;
22

3-
import java.io.ByteArrayOutputStream;
4-
import java.io.IOException;
5-
import java.io.InputStream;
6-
import java.io.OutputStream;
3+
import java.io.*;
74
import java.util.Arrays;
85

9-
import org.junit.Assert;
10-
116
import com.fasterxml.jackson.core.*;
127
import com.fasterxml.jackson.core.io.ContentReference;
138
import com.fasterxml.jackson.core.io.IOContext;
149
import com.fasterxml.jackson.core.util.BufferRecycler;
1510
import com.fasterxml.jackson.dataformat.smile.databind.SmileMapper;
1611

12+
import static org.junit.jupiter.api.Assertions.*;
13+
1714
public abstract class BaseTestForSmile
18-
extends junit.framework.TestCase
1915
{
2016
// From JSON specification, sample doc...
2117
protected final static int SAMPLE_SPEC_VALUE_WIDTH = 800;
@@ -210,7 +206,7 @@ protected void verifyException(Throwable e, String... matches)
210206

211207
protected void _verifyBytes(byte[] actBytes, byte... expBytes)
212208
{
213-
Assert.assertArrayEquals(expBytes, actBytes);
209+
assertArrayEquals(expBytes, actBytes);
214210
}
215211

216212
/**
@@ -229,7 +225,7 @@ protected String getAndVerifyText(JsonParser p) throws IOException
229225
if (str.length() != actLen) {
230226
fail("Internal problem (p.token == "+p.getCurrentToken()+"): p.getText().length() ['"+str+"'] == "+str.length()+"; p.getTextLength() == "+actLen);
231227
}
232-
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
228+
assertEquals(str, str2, "String access via getText(), getTextXxx() must be the same");
233229

234230
return str;
235231
}

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/FloatPrecisionTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.fasterxml.jackson.dataformat.smile;
2+
23
import java.io.ByteArrayOutputStream;
34
import java.math.BigDecimal;
45

5-
import static org.junit.Assert.assertArrayEquals;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
69

710
// for [jackson-core#730]
811
public class FloatPrecisionTest extends BaseTestForSmile
912
{
1013
// for [jackson-core#730]
14+
@Test
1115
public void testFloatRoundtrips() throws Exception
1216
{
1317
ByteArrayOutputStream out = new ByteArrayOutputStream();

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/FormatDefaultsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.fasterxml.jackson.dataformat.smile;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.fasterxml.jackson.core.JsonParser;
46
import com.fasterxml.jackson.core.StreamReadCapability;
57
import com.fasterxml.jackson.databind.ObjectMapper;
68

9+
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
711
public class FormatDefaultsTest extends BaseTestForSmile
812
{
913
private final ObjectMapper MAPPER = smileMapper();
1014

15+
@Test
1116
public void testParserDefaults() throws Exception
1217
{
1318
try (JsonParser p = MAPPER.createParser(new byte[4])) {

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/ParserInternalsTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
import java.io.InputStream;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.core.exc.StreamReadException;
68
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
79
import com.fasterxml.jackson.dataformat.smile.testutil.ThrottledInputStream;
810

11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.fail;
13+
914
public class ParserInternalsTest extends BaseTestForSmile
1015
{
1116
private final ByteQuadsCanonicalizer ROOT_SYMBOLS = ByteQuadsCanonicalizer.createRoot();
1217

18+
@Test
1319
public void testPositiveVIntGoodCases() throws Exception
1420
{
1521
// First, couple of known good cases
@@ -20,6 +26,7 @@ public void testPositiveVIntGoodCases() throws Exception
2026
});
2127
}
2228

29+
@Test
2330
public void testPositiveVIntOverflows() throws Exception
2431
{
2532
// Bad: ends at 5th, but overflows

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/SmileFactoryPropertiesTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
import java.io.*;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.core.*;
68
import com.fasterxml.jackson.dataformat.smile.async.NonBlockingByteArrayParser;
79

8-
import static org.junit.Assert.assertArrayEquals;
10+
import static org.junit.jupiter.api.Assertions.*;
911

10-
/**
11-
* Miscellaneous tests for {@link SmileFactory}, and for some aspects
12-
* of generators and parsers it creates.
13-
*/
1412
public class SmileFactoryPropertiesTest extends BaseTestForSmile
1513
{
1614
private final static String SIMPLE_DOC_AS_JSON = "{\"simple\":[1,true,{}]}";
1715

1816
private final static SmileFactory SMILE_F = new SmileFactory();
17+
18+
@Test
1919
public void testFactoryDefaults() {
2020
SmileFactory f = new SmileFactory();
2121

@@ -30,6 +30,7 @@ public void testFactoryDefaults() {
3030
f.isEnabled(SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES));
3131
}
3232

33+
@Test
3334
public void testFactorySerializable() throws Exception
3435
{
3536
SmileFactory f = new SmileFactory();
@@ -44,6 +45,7 @@ public void testFactorySerializable() throws Exception
4445
assertArrayEquals(doc, docOut);
4546
}
4647

48+
@Test
4749
public void testFactoryCopy() throws Exception
4850
{
4951
SmileFactory f2 = SMILE_F.copy();
@@ -53,6 +55,7 @@ public void testFactoryCopy() throws Exception
5355
assertNotNull(doc);
5456
}
5557

58+
@Test
5659
public void testVersions() throws Exception
5760
{
5861
SmileFactory f = SMILE_F;
@@ -69,6 +72,7 @@ public void testVersions() throws Exception
6972
p.close();
7073
}
7174

75+
@Test
7276
public void testCapabilities() throws Exception
7377
{
7478
assertTrue(SMILE_F.canHandleBinaryNatively());
@@ -77,6 +81,7 @@ public void testCapabilities() throws Exception
7781
assertEquals(SmileGenerator.Feature.class, SMILE_F.getFormatWriteFeatureType());
7882
}
7983

84+
@Test
8085
public void testInabilityToReadChars() throws Exception
8186
{
8287
final String EXP = "for character-based";
@@ -100,6 +105,7 @@ public void testInabilityToReadChars() throws Exception
100105
}
101106
}
102107

108+
@Test
103109
public void testInabilityToWriteChars() throws Exception
104110
{
105111
try {
@@ -112,6 +118,7 @@ public void testInabilityToWriteChars() throws Exception
112118
}
113119

114120
// One lesser known feature is the ability to fall back to using JSON...
121+
@Test
115122
public void testFallbackReadFromJson() throws Exception
116123
{
117124
SmileFactory f = new SmileFactory();
@@ -122,6 +129,7 @@ public void testFallbackReadFromJson() throws Exception
122129
}
123130

124131
// One lesser known feature is the ability to fall back to using JSON...
132+
@Test
125133
public void testFallbackWriteAsJson() throws Exception
126134
{
127135
SmileFactory f = new SmileFactory();
@@ -135,6 +143,7 @@ public void testFallbackWriteAsJson() throws Exception
135143
assertEquals("[]", w.toString());
136144
}
137145

146+
@Test
138147
public void testCanonicalization() throws Exception
139148
{
140149
try (NonBlockingByteArrayParser parser = new SmileFactory()

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/SmileUtilTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package com.fasterxml.jackson.dataformat.smile;
22

3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
37
public class SmileUtilTest extends BaseTestForSmile
48
{
59
/**
610
* Verification of helper methods used to handle with zigzag encoding
711
*/
12+
@Test
813
public void testZigZagInt()
914
{
1015
// simple encode
@@ -26,6 +31,7 @@ public void testZigZagInt()
2631
assertEquals(Integer.MAX_VALUE, SmileUtil.zigzagDecode(SmileUtil.zigzagEncode(Integer.MAX_VALUE)));
2732
}
2833

34+
@Test
2935
public void testZigZagLong()
3036
{
3137
assertEquals(0L, SmileUtil.zigzagEncode(0L));

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/SymbolHandlingTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import java.io.IOException;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.core.JsonToken;
68
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
79

8-
// Tests that have to reside in this package, due to access restrictions
10+
import static org.junit.jupiter.api.Assertions.*;
11+
912
public class SymbolHandlingTest extends BaseTestForSmile
1013
{
14+
@Test
1115
public void testSymbolTable() throws IOException
1216
{
1317
final String STR1 = "a";

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/VersionsTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.fasterxml.jackson.dataformat.smile;
22

3-
import java.io.*;
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
5+
6+
import org.junit.jupiter.api.Test;
47

58
import com.fasterxml.jackson.core.Versioned;
69

7-
/**
8-
* Tests to verify [JACKSON-278]
9-
*/
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
1012
public class VersionsTest extends BaseTestForSmile
1113
{
14+
@Test
1215
public void testMapperVersions() throws IOException
1316
{
1417
SmileFactory f = new SmileFactory();

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/async/AsyncParserNamesTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
package com.fasterxml.jackson.dataformat.smile.async;
22

3-
import java.io.*;
3+
import java.io.IOException;
44
import java.util.Random;
55

6-
import com.fasterxml.jackson.core.*;
6+
import org.junit.jupiter.api.Test;
7+
8+
import com.fasterxml.jackson.core.JsonToken;
79
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
810
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
911

12+
import static org.junit.jupiter.api.Assertions.*;
13+
1014
public class AsyncParserNamesTest extends AsyncTestBase
1115
{
16+
@Test
1217
public void testLongNames() throws IOException
1318
{
1419
_testWithName(generateName(5000));
1520
}
1621

22+
@Test
1723
public void testEvenLongerName() throws Exception
1824
{
1925
StringBuilder nameBuf = new StringBuilder("longString");
@@ -25,6 +31,7 @@ public void testEvenLongerName() throws Exception
2531
_testWithName(name);
2632
}
2733

34+
@Test
2835
public void testSymbolTable() throws IOException
2936
{
3037
final String STR1 = "a";

0 commit comments

Comments
 (0)