Skip to content

Commit 2933c6a

Browse files
committed
Test refactoring
1 parent e6df267 commit 2933c6a

File tree

3 files changed

+67
-81
lines changed

3 files changed

+67
-81
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeser1805Test.java

-78
This file was deleted.

src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeser2719Test.java

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
public class ReadOnlyDeser2719Test extends BaseMapTest
88
{
9-
109
// [databind#2719]
1110
static class UserWithReadOnly {
1211
@JsonProperty(value = "username", access = JsonProperty.Access.READ_ONLY)
@@ -49,7 +48,5 @@ public void testFailOnIgnore() throws Exception
4948
} catch (JsonMappingException e) {
5049
verifyException(e, "Ignored field");
5150
}
52-
5351
}
54-
5552
}

src/test/java/com/fasterxml/jackson/databind/deser/ReadOrWriteOnlyTest.java

+67
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.fasterxml.jackson.databind.deser;
22

33
import java.beans.ConstructorProperties;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.List;
47

8+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
59
import com.fasterxml.jackson.annotation.JsonProperty;
610
import com.fasterxml.jackson.databind.*;
711

@@ -66,6 +70,41 @@ public Foo1345(String id, String name) {
6670
protected Foo1345() { }
6771
}
6872

73+
// [databind#1382]
74+
static class Foo1382 {
75+
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
76+
private List<Long> list = new ArrayList<>();
77+
78+
List<Long> getList() {
79+
return list;
80+
}
81+
82+
public Foo1382 setList(List<Long> list) {
83+
this.list = list;
84+
return this;
85+
}
86+
}
87+
88+
// [databind#1805]
89+
static class UserWithReadOnly1805 {
90+
public String name;
91+
92+
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
93+
public List<String> getRoles() {
94+
return Arrays.asList("admin", "monitor");
95+
}
96+
}
97+
98+
// [databind#1805]
99+
@JsonIgnoreProperties(value={ "roles" }, allowGetters=true)
100+
static class UserAllowGetters1805 {
101+
public String name;
102+
103+
public List<String> getRoles() {
104+
return Arrays.asList("admin", "monitor");
105+
}
106+
}
107+
69108
/*
70109
/**********************************************************
71110
/* Test methods
@@ -93,11 +132,39 @@ public void testReadOnly935() throws Exception
93132
assertNotNull(result);
94133
}
95134

135+
// [databind#1345]
96136
public void testReadOnly1345() throws Exception
97137
{
98138
Foo1345 result = MAPPER.readValue("{\"name\":\"test\"}", Foo1345.class);
99139
assertNotNull(result);
100140
assertEquals("test", result.name);
101141
assertNull(result.id);
102142
}
143+
144+
// [databind#1382]
145+
public void testReadOnly1382() throws Exception
146+
{
147+
String payload = "{\"list\":[1,2,3,4]}";
148+
Foo1382 foo = MAPPER.readValue(payload, Foo1382.class);
149+
assertTrue("List should be empty", foo.getList().isEmpty());
150+
}
151+
152+
// [databind#1805]
153+
public void testViaReadOnly() throws Exception {
154+
UserWithReadOnly1805 user = new UserWithReadOnly1805();
155+
user.name = "foo";
156+
String json = MAPPER.writeValueAsString(user);
157+
UserWithReadOnly1805 result = MAPPER.readValue(json, UserWithReadOnly1805.class);
158+
assertNotNull(result);
159+
}
160+
161+
// [databind#1805]
162+
public void testUsingAllowGetters() throws Exception {
163+
UserAllowGetters1805 user = new UserAllowGetters1805();
164+
user.name = "foo";
165+
String json = MAPPER.writeValueAsString(user);
166+
assertTrue(json.contains("roles"));
167+
UserAllowGetters1805 result = MAPPER.readValue(json, UserAllowGetters1805.class);
168+
assertNotNull(result);
169+
}
103170
}

0 commit comments

Comments
 (0)