3
3
import org .junit .jupiter .api .Test ;
4
4
5
5
import tools .jackson .databind .*;
6
+ import tools .jackson .databind .exc .UnrecognizedPropertyException ;
6
7
import tools .jackson .databind .testutil .DatabindTestUtil ;
7
8
8
9
import static org .junit .jupiter .api .Assertions .assertEquals ;
10
+ import static org .junit .jupiter .api .Assertions .fail ;
9
11
10
12
// Tests for [databind#653]
11
13
public class BeanNamingTest extends DatabindTestUtil
@@ -22,15 +24,55 @@ public int getA() {
22
24
}
23
25
}
24
26
27
+ // [databind#2882]
28
+ static class Bean2882 {
29
+ // These should NOT be detected as "getters" due to naming conventions
30
+ public boolean island () { return true ; }
31
+ public boolean is_bad () { return true ; }
32
+
33
+ public int get_value () { return -2 ; }
34
+ public int getter () { return -3 ; }
35
+
36
+ // This is regular and should be detected
37
+ public int getX () { return 1 ; }
38
+
39
+ // And bad "setter" too
40
+ public void setter (int x ) {
41
+ throw new IllegalStateException ("Should not get called" );
42
+ }
43
+ }
44
+
45
+ private final ObjectMapper MAPPER = newJsonMapper ();
46
+
25
47
// 24-Sep-2017, tatu: Used to test for `MapperFeature.USE_STD_BEAN_NAMING`, but with 3.x
26
48
// that is always enabled.
27
49
@ Test
28
50
public void testMultipleLeadingCapitalLetters () throws Exception
29
51
{
30
- ObjectMapper mapper = newJsonMapper ();
31
52
assertEquals (a2q ("{'URL':'http:'}" ),
32
- mapper .writeValueAsString (new URLBean ()));
53
+ MAPPER .writeValueAsString (new URLBean ()));
33
54
assertEquals (a2q ("{'a':3}" ),
34
- mapper .writeValueAsString (new ABean ()));
55
+ MAPPER .writeValueAsString (new ABean ()));
56
+ }
57
+
58
+ // [databind#2882]
59
+ @ Test
60
+ void testBadCasingForGetters () throws Exception
61
+ {
62
+ assertEquals (a2q ("{'x':1}" ),
63
+ MAPPER .writeValueAsString (new Bean2882 ()));
64
+ }
65
+
66
+ @ Test
67
+ void testBadCasingForSetters () throws Exception
68
+ {
69
+ try {
70
+ MAPPER .readerFor (Bean2882 .class )
71
+ .with (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
72
+ .readValue (a2q ("{'ter':1}" ));
73
+ fail ("Should not pass" );
74
+ } catch (UnrecognizedPropertyException e ) {
75
+ verifyException (e , "Unrecognized property \" ter\" " );
76
+ }
35
77
}
36
78
}
0 commit comments