-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestIt.java
116 lines (101 loc) · 3.37 KB
/
TestIt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.io.IOException;
import java.lang.reflect.Method;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Builder.Default;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
@ToString
public class TestIt {
@JsonProperty(value="withJsonProperty")
private boolean withJsonProperty;
@JsonProperty(value="isWithProperty")
private boolean isWithProperty; //Generate duplicates fields
@JsonProperty(value="withProp")
private Boolean withProp;
@JsonProperty(value="isUsingProp")
private Boolean isUsingProp;
@Default
@JsonProperty(value="withJsonPropertyAndDefault")
private boolean withJsonPropertyAndDefault= true;
@Default
@JsonProperty(value="isWithPropertyAndDefault")
private boolean isWithPropertyAndDefault= true; //Generate duplicates fields
@Default
@JsonProperty(value="withPropAndDefault")
private Boolean withPropAndDefault= true;
@Default
@JsonProperty(value="isUsingPropAndDefault")
private Boolean isUsingPropAndDefault= true;
@Default
private boolean isDefaultingToTrue= true; //does not work if set to false
@Default
private boolean defaultingToFalse= false;
@Default
private Boolean isDefaultedToTrue= true;
@Default
private Boolean defaultedToFalse= false;
@Default
@Accessors(fluent = true)
private Boolean isFluentWithDefaultFail = true; //does not work if set to false
private boolean online;
private boolean isBad; //does not work if set to true
@Accessors(fluent = true)
private boolean isBuggy; //does not work if set to true
private Boolean isCorrect;
private Boolean active;
@Accessors(fluent = true)
private Boolean isTestingNull; //does not work, I think I over test in this case.
public static void main(String[] args) throws IOException {
TestIt defaultTest= TestIt.builder().build();
for (Method m : defaultTest.getClass().getDeclaredMethods()) {
System.out.println("Method: " + m);
}
System.out.println("\n");
printTest(defaultTest); //Default is ok, who cares
testWith(true);
testWith(false);
}
private static void testWith(boolean bool) throws IOException {
System.out.println("\nTest with: " + bool);
TestIt in = TestIt.builder()
.withJsonProperty(bool)
.isWithProperty(bool)
.withProp(bool)
.isUsingProp(bool)
.withJsonPropertyAndDefault(bool)
.isWithPropertyAndDefault(bool)
.withPropAndDefault(bool)
.isUsingPropAndDefault(bool)
.online(bool)
.active(bool)
.isBad(bool)
.isCorrect(bool)
.isTestingNull(bool)
.isBuggy(bool)
.isDefaultedToTrue(bool)
.isDefaultingToTrue(bool)
.defaultedToFalse(bool)
.defaultingToFalse(bool)
.isFluentWithDefaultFail(bool)
.build();
printTest(in);
}
private static void printTest(TestIt defaultTest) throws IOException {
ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(defaultTest);
System.out.println(json);
TestIt out = objectMapper.readValue(json, TestIt.class);
System.out.println("In = " + defaultTest);
System.out.println("Out = " + out);
}
}