Skip to content

Commit cdcfdad

Browse files
committed
Test cleanup
1 parent e1bb5ea commit cdcfdad

File tree

6 files changed

+15
-19
lines changed

6 files changed

+15
-19
lines changed

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ protected static byte[] utf8Bytes(String str) {
575575
return str.getBytes(StandardCharsets.UTF_8);
576576
}
577577

578-
protected static String fromUTF8(ByteArrayOutputStream bytes) {
578+
protected static String utf8String(ByteArrayOutputStream bytes) {
579579
return new String(bytes.toByteArray(), StandardCharsets.UTF_8);
580580
}
581581

@@ -623,11 +623,7 @@ protected String fieldNameFor(int index)
623623
}
624624

625625
protected int[] calcQuads(String word) {
626-
try {
627-
return calcQuads(word.getBytes("UTF-8"));
628-
} catch (IOException e) {
629-
throw new RuntimeException(e);
630-
}
626+
return calcQuads(utf8Bytes(word));
631627
}
632628

633629
protected int[] calcQuads(byte[] wordBytes) {

src/test/java/com/fasterxml/jackson/core/io/UTF8WriterTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void testSimple() throws Exception
3131
// and thus should have 3 times contents
3232
byte[] data = out.toByteArray();
3333
assertEquals(3*10, data.length);
34-
String act = out.toString("UTF-8");
34+
String act = utf8String(out);
3535
assertEquals(15, act.length());
3636

3737
assertEquals(3 * str.length(), act.length());
@@ -53,7 +53,7 @@ public void testSimpleAscii() throws Exception
5353
byte[] data = out.toByteArray();
5454
// one 2-byte encoded char
5555
assertEquals(ch.length+1, data.length);
56-
String act = out.toString("UTF-8");
56+
String act = utf8String(out);
5757
assertEquals(str, act);
5858
}
5959

src/test/java/com/fasterxml/jackson/core/json/GeneratorFeaturesTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void testBigDecimalAsPlainString() throws Exception
148148
g = f.createGenerator(bos);
149149
g.writeNumber(ENG);
150150
g.close();
151-
assertEquals(q("100"), bos.toString("UTF-8"));
151+
assertEquals(q("100"), utf8String(bos));
152152
}
153153

154154
// [core#315]
@@ -234,7 +234,7 @@ private String _writeNumbers(JsonFactory f, boolean useBytes) throws IOException
234234
g.writeEndArray();
235235
g.close();
236236

237-
return useBytes ? bytes.toString("UTF-8") : sw.toString();
237+
return useBytes ? utf8String(bytes) : sw.toString();
238238
}
239239

240240
// for [core#246]
@@ -283,7 +283,7 @@ private void _testFieldNameQuotingEnabled(JsonFactory f, boolean useBytes,
283283
gen.writeEndObject();
284284
gen.close();
285285

286-
String json = useBytes ? bytes.toString("UTF-8") : sw.toString();
286+
String json = useBytes ? utf8String(bytes) : sw.toString();
287287
assertEquals(exp, json);
288288
}
289289

@@ -390,7 +390,7 @@ private void _testHexOutput(JsonFactory f, boolean useBytes,
390390
g.flush();
391391
g.close();
392392

393-
String result = useBytes ? fromUTF8(bytes) : sw.toString();
393+
String result = useBytes ? utf8String(bytes) : sw.toString();
394394
assertEquals(exp, result);
395395

396396
g.close();

src/test/java/com/fasterxml/jackson/core/write/GeneratorBasicTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void testStringWrite() throws Exception
4545
JsonParser jp = JSON_F.createParser(new ByteArrayInputStream(bout.toByteArray()));
4646

4747
JsonToken t = jp.nextToken();
48-
assertNotNull("Document \""+bout.toString("UTF-8")+"\" yielded no tokens", t);
48+
assertNotNull("Document \""+utf8String(bout)+"\" yielded no tokens", t);
4949
assertEquals(JsonToken.VALUE_STRING, t);
5050
assertEquals(input, jp.getText());
5151
assertEquals(null, jp.nextToken());
@@ -149,7 +149,7 @@ private void _testRootIntsWrite(boolean useBytes) throws Exception
149149
gen.writeNumber(-13);
150150
gen.close();
151151

152-
String docStr = useBytes ? bytes.toString("UTF-8") : sw.toString();
152+
String docStr = useBytes ? utf8String(bytes) : sw.toString();
153153

154154
try {
155155
JsonParser jp = createParserUsingReader(docStr);
@@ -195,7 +195,7 @@ public void _testFieldValueWrites(boolean useBytes) throws Exception
195195
gen.writeEndObject();
196196
gen.close();
197197

198-
String docStr = useBytes ? bytes.toString("UTF-8") : sw.toString();
198+
String docStr = useBytes ? utf8String(bytes) : sw.toString();
199199

200200
assertEquals("{\"short\":3,\"int\":3,\"long\":3,\"big\":1707,\"double\":0.25,\"float\":-0.25,\"decimal\":17.07}",
201201
docStr.trim());
@@ -342,7 +342,7 @@ private void doTestIntValueWrite(boolean pad, boolean useBytes) throws Exception
342342
gen.writeRaw(" ");
343343
}
344344
gen.close();
345-
docStr = bytes.toString("UTF-8");
345+
docStr = utf8String(bytes);
346346
p = JSON_F.createParser(bytes.toByteArray());
347347
} else {
348348
StringWriter sw = new StringWriter();
@@ -398,7 +398,7 @@ private void doTestLongValueWrite(boolean pad, boolean useBytes) throws Exceptio
398398
gen.writeRaw(" ");
399399
}
400400
gen.close();
401-
docStr = bytes.toString("UTF-8");
401+
docStr = utf8String(bytes);
402402
p = JSON_F.createParser(bytes.toByteArray());
403403
} else {
404404
StringWriter sw = new StringWriter();

src/test/java/com/fasterxml/jackson/core/write/GeneratorMiscTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void testAsEmbedded() throws Exception
248248
g = JSON_F.createGenerator(bytes);
249249
g.writeEmbeddedObject(null);
250250
g.close();
251-
assertEquals("null", bytes.toString("UTF-8"));
251+
assertEquals("null", utf8String(bytes));
252252

253253
// also, for fun, try illegal unknown thingy
254254

src/test/java/com/fasterxml/jackson/core/write/UTF8GeneratorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void testFilteringWithEscapedChars() throws Exception
9696

9797
gen.writeFieldName("escapes");
9898

99-
final byte[] raw = SAMPLE_WITH_QUOTES.toString().getBytes("UTF-8");
99+
final byte[] raw = utf8Bytes(SAMPLE_WITH_QUOTES);
100100
gen.writeUTF8String(raw, 0, raw.length);
101101

102102
gen.writeEndObject();

0 commit comments

Comments
 (0)