Skip to content

Commit 66ac874

Browse files
committed
Test refactoring
1 parent 1ede6c6 commit 66ac874

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.fasterxml.jackson.databind.jdk15;
2+
3+
import com.fasterxml.jackson.databind.BaseMapTest;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
6+
// for [databind#3305]
7+
public class CharSequenceDeser3305Test extends BaseMapTest
8+
{
9+
static final class AppId implements CharSequence {
10+
private final long value;
11+
12+
public AppId(long value) throws IllegalArgumentException {
13+
this.value = value;
14+
}
15+
16+
public static AppId valueOf(String value) throws IllegalArgumentException {
17+
if (value == null) {
18+
throw new IllegalArgumentException("value is null");
19+
}
20+
return new AppId(Long.parseLong(value));
21+
}
22+
23+
@Override
24+
public int length() {
25+
return toString().length();
26+
}
27+
28+
@Override
29+
public char charAt(int index) {
30+
return toString().charAt(index);
31+
}
32+
33+
@Override
34+
public CharSequence subSequence(int start, int end) {
35+
return toString().subSequence(start, end);
36+
}
37+
38+
// pay attention: no @JsonValue here
39+
@Override
40+
public String toString() {
41+
return Long.toString(value);
42+
}
43+
}
44+
45+
private static final String APP_ID = "3074457345618296002";
46+
47+
private final static ObjectMapper MAPPER = newJsonMapper();
48+
49+
public void testCharSequenceSerialization() throws Exception {
50+
AppId appId = AppId.valueOf(APP_ID);
51+
52+
String serialized = MAPPER.writeValueAsString(appId);
53+
54+
//Without a fix fails on JDK17 with
55+
//org.junit.ComparisonFailure:
56+
//Expected :{"empty":false}
57+
//Actual :"3074457345618296002"
58+
assertEquals("\"" + APP_ID + "\"", serialized);
59+
}
60+
}

src/test-jdk14/java/com/fasterxml/jackson/databind/failing/Java9ListsTest.java renamed to src/test-jdk14/java/com/fasterxml/jackson/databind/jdk9/Java9ListsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.databind.failing;
1+
package com.fasterxml.jackson.databind.jdk9;
22

33
import java.util.Collections;
44
import java.util.List;

0 commit comments

Comments
 (0)