Skip to content

Commit aca3f56

Browse files
committed
More test refactoring
1 parent db9bab8 commit aca3f56

File tree

3 files changed

+115
-27
lines changed

3 files changed

+115
-27
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package tools.jackson.core.unittest.tofix;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import tools.jackson.core.JsonParser;
6+
import tools.jackson.core.JsonToken;
7+
import tools.jackson.core.exc.StreamReadException;
8+
import tools.jackson.core.unittest.testutil.failure.JacksonTestFailureExpected;
9+
10+
import static org.junit.jupiter.api.Assertions.fail;
11+
12+
// Failing tests for non-root-token problem
13+
class ParserErrorHandlingBytes105Test
14+
extends tools.jackson.core.unittest.JacksonCoreTestBase
15+
{
16+
// Tests for [core#105] ("eager number parsing misses errors")
17+
@JacksonTestFailureExpected
18+
@Test
19+
void mangledIntsBytes() throws Exception {
20+
_testMangledNonRootInts(MODE_INPUT_STREAM);
21+
_testMangledNonRootInts(MODE_INPUT_STREAM_THROTTLED);
22+
}
23+
24+
@JacksonTestFailureExpected
25+
@Test
26+
void mangledFloatsBytes() throws Exception {
27+
_testMangledNonRootFloats(MODE_INPUT_STREAM);
28+
_testMangledNonRootFloats(MODE_INPUT_STREAM_THROTTLED);
29+
}
30+
31+
/*
32+
/**********************************************************
33+
/* Helper methods
34+
/**********************************************************
35+
*/
36+
37+
private void _testMangledNonRootInts(int mode)
38+
{
39+
try (JsonParser p = createParser(mode, "[ 123true ]")) {
40+
assertToken(JsonToken.START_ARRAY, p.nextToken());
41+
JsonToken t = p.nextToken();
42+
fail("Should have gotten an exception; instead got token: "+t);
43+
} catch (StreamReadException e) {
44+
verifyException(e, "expected space");
45+
}
46+
}
47+
48+
private void _testMangledNonRootFloats(int mode)
49+
{
50+
try (JsonParser p = createParser(mode, "[ 1.5false ]")) {
51+
assertToken(JsonToken.START_ARRAY, p.nextToken());
52+
JsonToken t = p.nextToken();
53+
fail("Should have gotten an exception; instead got token: "+t);
54+
} catch (StreamReadException e) {
55+
verifyException(e, "expected space");
56+
}
57+
}
58+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package tools.jackson.core.unittest.tofix;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import tools.jackson.core.JsonParser;
6+
import tools.jackson.core.JsonToken;
7+
import tools.jackson.core.exc.StreamReadException;
8+
import tools.jackson.core.unittest.testutil.failure.JacksonTestFailureExpected;
9+
10+
import static org.junit.jupiter.api.Assertions.fail;
11+
12+
// Failing tests for non-root-token problem
13+
class ParserErrorHandlingChars105Test
14+
extends tools.jackson.core.unittest.JacksonCoreTestBase
15+
{
16+
// Tests for [core#105] ("eager number parsing misses errors")
17+
@JacksonTestFailureExpected
18+
@Test
19+
void mangledIntsChars() throws Exception {
20+
_testMangledNonRootInts(MODE_READER);
21+
}
22+
23+
@JacksonTestFailureExpected
24+
@Test
25+
void mangledFloatsChars() throws Exception {
26+
_testMangledNonRootFloats(MODE_READER);
27+
}
28+
29+
/*
30+
/**********************************************************
31+
/* Helper methods
32+
/**********************************************************
33+
*/
34+
35+
private void _testMangledNonRootInts(int mode)
36+
{
37+
try (JsonParser p = createParser(mode, "[ 123true ]")) {
38+
assertToken(JsonToken.START_ARRAY, p.nextToken());
39+
JsonToken t = p.nextToken();
40+
fail("Should have gotten an exception; instead got token: "+t);
41+
} catch (StreamReadException e) {
42+
verifyException(e, "expected space");
43+
}
44+
}
45+
46+
private void _testMangledNonRootFloats(int mode)
47+
{
48+
try (JsonParser p = createParser(mode, "[ 1.5false ]")) {
49+
assertToken(JsonToken.START_ARRAY, p.nextToken());
50+
JsonToken t = p.nextToken();
51+
fail("Should have gotten an exception; instead got token: "+t);
52+
} catch (StreamReadException e) {
53+
verifyException(e, "expected space");
54+
}
55+
}
56+
}

src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandling105Test.java renamed to src/test/java/tools/jackson/core/unittest/tofix/ParserErrorHandlingDataInput105Test.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,10 @@
1010
import static org.junit.jupiter.api.Assertions.fail;
1111

1212
// Failing tests for non-root-token problem
13-
class ParserErrorHandling105Test
13+
class ParserErrorHandlingDataInput105Test
1414
extends tools.jackson.core.unittest.JacksonCoreTestBase
1515
{
1616
// Tests for [core#105] ("eager number parsing misses errors")
17-
@JacksonTestFailureExpected
18-
@Test
19-
void mangledIntsBytes() throws Exception {
20-
_testMangledNonRootInts(MODE_INPUT_STREAM);
21-
_testMangledNonRootInts(MODE_INPUT_STREAM_THROTTLED);
22-
}
23-
2417
@JacksonTestFailureExpected
2518
@Test
2619
void mangledIntsDataInput() throws Exception {
@@ -29,31 +22,12 @@ void mangledIntsDataInput() throws Exception {
2922
_testMangledNonRootInts(MODE_DATA_INPUT);
3023
}
3124

32-
@JacksonTestFailureExpected
33-
@Test
34-
void mangledIntsChars() throws Exception {
35-
_testMangledNonRootInts(MODE_READER);
36-
}
37-
38-
@JacksonTestFailureExpected
39-
@Test
40-
void mangledFloatsBytes() throws Exception {
41-
_testMangledNonRootFloats(MODE_INPUT_STREAM);
42-
_testMangledNonRootFloats(MODE_INPUT_STREAM_THROTTLED);
43-
}
44-
4525
@JacksonTestFailureExpected
4626
@Test
4727
void mangledFloatsDataInput() throws Exception {
4828
_testMangledNonRootFloats(MODE_DATA_INPUT);
4929
}
5030

51-
@JacksonTestFailureExpected
52-
@Test
53-
void mangledFloatsChars() throws Exception {
54-
_testMangledNonRootFloats(MODE_READER);
55-
}
56-
5731
/*
5832
/**********************************************************
5933
/* Helper methods

0 commit comments

Comments
 (0)