Skip to content

Commit 6881775

Browse files
Chaitanya Garikipatidgollahon
authored andcommitted
Fix Address object serialization
- Fixes addresses field which previously contained null values for all address objects, due to missing @JsonProperty annotations. - Removes misleading @NotNull annotations which clearly were not true for all cases in which Address is used. - Changes the test candidate to only search for "John Bredenkemp" without extra information so that WatchlitHit items will actually be returned and the tests prove that addresses can be deserialized correctly. - Adds additional test assertions to prove that the change works necessary and to prevent regressions.
1 parent 686cab5 commit 6881775

File tree

2 files changed

+34
-53
lines changed

2 files changed

+34
-53
lines changed

src/main/java/com/blockscore/models/Address.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
package com.blockscore.models;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
35
import org.jetbrains.annotations.NotNull;
4-
import org.jetbrains.annotations.Nullable;
56

67
/**
78
* The address model.
89
*/
910
public class Address {
10-
@NotNull
11+
@JsonProperty("address_street1")
1112
private String street1;
12-
13-
@Nullable
13+
14+
@JsonProperty("address_street2")
1415
private String street2;
15-
16-
@NotNull
16+
17+
@JsonProperty("address_city")
1718
private String city;
1819

19-
@NotNull
20+
@JsonProperty("address_subdivision")
2021
private String subdivision;
2122

22-
@NotNull
23+
@JsonProperty("address_postal_code")
2324
private String postalCode;
24-
25-
@NotNull
25+
26+
@JsonProperty("address_country_code")
2627
private String countryCode;
2728

2829

@@ -40,9 +41,9 @@ public Address() {
4041
* @param postalCode the postal (ZIP) code
4142
* @param countryCode the country code
4243
*/
43-
public Address(@NotNull final String street1, @Nullable final String street2,
44-
@NotNull final String city, @NotNull final String subdivision,
45-
@NotNull final String postalCode, @NotNull final String countryCode) {
44+
public Address(final String street1, final String street2,
45+
final String city, final String subdivision,
46+
final String postalCode, final String countryCode) {
4647
this.street1 = street1;
4748
this.street2 = street2;
4849
this.city = city;
@@ -58,7 +59,7 @@ public Address(@NotNull final String street1, @Nullable final String street2,
5859
* @return this
5960
*/
6061
@NotNull
61-
public Address setStreet1(@NotNull final String street1) {
62+
public Address setStreet1(final String street1) {
6263
this.street1 = street1;
6364
return this;
6465
}
@@ -69,8 +70,8 @@ public Address setStreet1(@NotNull final String street1) {
6970
* @param street2 Street (Line 2)
7071
* @return this
7172
*/
72-
@Nullable
73-
public Address setStreet2(@NotNull final String street2) {
73+
@NotNull
74+
public Address setStreet2(final String street2) {
7475
this.street2 = street2;
7576
return this;
7677
}
@@ -82,7 +83,7 @@ public Address setStreet2(@NotNull final String street2) {
8283
* @return this
8384
*/
8485
@NotNull
85-
public Address setCity(@NotNull final String city) {
86+
public Address setCity(final String city) {
8687
this.city = city;
8788
return this;
8889
}
@@ -95,7 +96,7 @@ public Address setCity(@NotNull final String city) {
9596
* @return this
9697
*/
9798
@NotNull
98-
public Address setSubdivision(@NotNull final String subdivision) {
99+
public Address setSubdivision(final String subdivision) {
99100
this.subdivision = subdivision;
100101
return this;
101102
}
@@ -107,7 +108,7 @@ public Address setSubdivision(@NotNull final String subdivision) {
107108
* @return this
108109
*/
109110
@NotNull
110-
public Address setPostalCode(@NotNull final String postalCode) {
111+
public Address setPostalCode(final String postalCode) {
111112
this.postalCode = postalCode;
112113
return this;
113114
}
@@ -119,7 +120,7 @@ public Address setPostalCode(@NotNull final String postalCode) {
119120
* @return this
120121
*/
121122
@NotNull
122-
public Address setCountryCode(@NotNull final String countryCode) {
123+
public Address setCountryCode(final String countryCode) {
123124
this.countryCode = countryCode;
124125
return this;
125126
}
@@ -129,7 +130,6 @@ public Address setCountryCode(@NotNull final String countryCode) {
129130
*
130131
* @return Line 1 of the address
131132
*/
132-
@NotNull
133133
public String getStreet1() {
134134
return street1;
135135
}
@@ -139,7 +139,6 @@ public String getStreet1() {
139139
*
140140
* @return Line 2 of the address
141141
*/
142-
@Nullable
143142
public String getStreet2() {
144143
return street2;
145144
}
@@ -149,7 +148,6 @@ public String getStreet2() {
149148
*
150149
* @return the address city
151150
*/
152-
@NotNull
153151
public String getCity() {
154152
return city;
155153
}
@@ -159,7 +157,6 @@ public String getCity() {
159157
*
160158
* @return the address subdivision
161159
*/
162-
@NotNull
163160
public String getSubdivision() {
164161
return subdivision;
165162
}
@@ -169,7 +166,6 @@ public String getSubdivision() {
169166
*
170167
* @return the postal code
171168
*/
172-
@NotNull
173169
public String getPostalCode() {
174170
return postalCode;
175171
}
@@ -179,7 +175,6 @@ public String getPostalCode() {
179175
*
180176
* @return the country code
181177
*/
182-
@NotNull
183178
public String getCountryCode() {
184179
return countryCode;
185180
}

src/test/java/com/blockscore/models/CandidateTest.java

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static com.blockscore.models.TestUtils.assertBasicResponsesAreEquivalent;
77
import static com.blockscore.models.TestUtils.setupBlockscoreApiClient;
88
import static org.junit.Assert.assertEquals;
9+
import static org.junit.Assert.assertNotEquals;
910
import static org.junit.Assert.assertNotNull;
1011
import static org.junit.Assert.assertNull;
1112

@@ -234,27 +235,7 @@ public void testCandidateDeletion() {
234235
/*------------------*/
235236

236237
private Candidate createTestCandidate() {
237-
Address address = (new Address()).setStreet1("1 Infinite Loop")
238-
.setCity("Harare")
239-
.setCountryCode("ZW");
240-
241-
final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
242-
Date date = null;
243-
try {
244-
date = formatter.parse("1980-08-23");
245-
} catch (ParseException e) {
246-
e.printStackTrace();
247-
}
248-
249-
Candidate.Builder builder = new Candidate.Builder(client);
250-
builder.setNote("12341234")
251-
.setSsn("001")
252-
.setDateOfBirth(date)
253-
.setFirstName("John")
254-
.setLastName("BredenKamp")
255-
.setAddress(address);
256-
257-
return builder.create();
238+
return new Candidate.Builder(client).setFirstName("John").setLastName("BredenKamp").create();
258239
}
259240

260241
private Candidate createEmptyCandidate() {
@@ -308,12 +289,9 @@ private void assertCandidateUpdated(final Candidate candidate) {
308289
assertEquals("US", address.getCountryCode());
309290
}
310291

311-
// NOTE: Currently no actual data is being returned for a watchlist search.
312-
// The logic for asserting whether or not the hit is valid will have
313-
// to be modified when sample data is available.
314292
private void assertHitsAreValid(List<WatchlistHit> hits) {
315293
assertNotNull(hits);
316-
// assertNotEquals(hits.size(), 0); see above note
294+
assertNotEquals(hits.size(), 0);
317295
for (WatchlistHit hit : hits) {
318296
assertHitIsValid(hit);
319297
}
@@ -334,7 +312,10 @@ private void assertHitIsValid(WatchlistHit hit) {
334312
assertNotNull(hit.getDateOfBirth());
335313
assertNull(hit.getSsn());
336314
assertNotNull(hit.getPassports());
337-
assertAddressIsValid(hit.getAddress());
315+
assertNotNull(hit.getAddress());
316+
assertNotNull(hit.getAddress().getStreet1());
317+
assertNotNull(hit.getAddress().getCity());
318+
assertNotNull(hit.getAddress().getCountryCode());
338319
assertNotNull(hit.getRawAddress());
339320
assertNotNull(hit.getNames());
340321
assertEquals(hit.getNames().size(), 3);
@@ -343,7 +324,12 @@ private void assertHitIsValid(WatchlistHit hit) {
343324
assertNotNull(hit.getDocuments());
344325
assertEquals(hit.getDocuments().size(), 4);
345326
assertNotNull(hit.getAlternateNames());
346-
assertNotNull(hit.getAddresses());
327+
assertNotEquals(hit.getAddresses().size(), 0);
328+
for(Address address : hit.getAddresses()) {
329+
assertNotNull(address.getStreet1());
330+
assertNotNull(address.getCity());
331+
assertNotNull(address.getCountryCode());
332+
}
347333
assertDocumentsAreValid(hit.getDocuments());
348334
}
349335

0 commit comments

Comments
 (0)