-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
194 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/com/smartystreets/api/international_autocomplete_deprecated/CandidateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.smartystreets.api.international_autocomplete_deprecated; | ||
|
||
import com.smartystreets.api.SmartySerializer; | ||
import com.smartystreets.api.international_autocomplete_deprecated.Candidate; | ||
import com.smartystreets.api.international_autocomplete_deprecated.Result; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class CandidateTest { | ||
|
||
|
||
@Test | ||
public void testFullJSONDeserialization() throws Exception { | ||
|
||
String rawJSON = "{\n" + | ||
"\"candidates\": [\n" + | ||
"{\n" + | ||
"\"street\": \"12TH AV\",\n" + | ||
"\"locality\": \"OCEAN GROVE\",\n" + | ||
"\"administrative_area\": \"VIC\",\n" + | ||
"\"sub_administrative_area\": \"WHITTLESEA\"," + | ||
"\"postal_code\": \"3226\",\n" + | ||
"\"country_iso3\": \"AUS\"\n" + | ||
"},\n" + | ||
"{\n" + | ||
"\"street\": \"MONG FAT STREET\",\n" + | ||
"\"locality\": \"TUEN MUN\",\n" + | ||
"\"administrative_area\": \"TUEN MUN DISTRICT\",\n" + | ||
"\"super_administrative_area\": \"HONG KONG\",\n" + | ||
"\"country_iso3\": \"HKG\"\n" + | ||
"}\n" + | ||
"]\n" + | ||
"}"; | ||
|
||
byte[] bytes = rawJSON.getBytes(); | ||
|
||
Result result = new SmartySerializer().deserialize(bytes, Result.class); | ||
Candidate[] candidates = result.getCandidates(); | ||
|
||
assertEquals("12TH AV", candidates[0].getStreet()); | ||
assertEquals("OCEAN GROVE", candidates[0].getLocality()); | ||
assertEquals("VIC", candidates[0].getAdministrativeArea()); | ||
assertEquals("WHITTLESEA", candidates[0].getSubAdministrativeArea()); | ||
assertEquals("3226", candidates[0].getPostalCode()); | ||
assertEquals("AUS", candidates[0].getCountryISO3()); | ||
assertEquals("MONG FAT STREET", candidates[1].getStreet()); | ||
assertEquals("TUEN MUN", candidates[1].getLocality()); | ||
assertEquals("TUEN MUN DISTRICT", candidates[1].getAdministrativeArea()); | ||
assertEquals("HONG KONG", candidates[1].getSuperAdministrativeArea()); | ||
assertEquals("HKG", candidates[1].getCountryISO3()); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
src/test/java/com/smartystreets/api/international_autocomplete_deprecated/ClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.smartystreets.api.international_autocomplete_deprecated; | ||
|
||
import com.smartystreets.api.InternationalGeolocateType; | ||
import com.smartystreets.api.Response; | ||
import com.smartystreets.api.URLPrefixSender; | ||
import com.smartystreets.api.international_autocomplete_deprecated.Client; | ||
import com.smartystreets.api.international_autocomplete_deprecated.Lookup; | ||
import com.smartystreets.api.international_autocomplete_deprecated.Result; | ||
import com.smartystreets.api.mocks.FakeDeserializer; | ||
import com.smartystreets.api.mocks.FakeSerializer; | ||
import com.smartystreets.api.mocks.MockSender; | ||
import com.smartystreets.api.mocks.RequestCapturingSender; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ClientTest { | ||
//region [ Single Lookup ] | ||
|
||
@Test | ||
public void testSendingSinglePrefixOnlyLookup() throws Exception { | ||
RequestCapturingSender capturingSender = new RequestCapturingSender(); | ||
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender); | ||
FakeSerializer serializer = new FakeSerializer(new Result()); | ||
Client client = new Client(sender, serializer); | ||
|
||
client.send(new Lookup("1")); | ||
|
||
assertEquals("http://localhost/?search=1&max_results=5&distance=5", capturingSender.getRequest().getUrl()); | ||
} | ||
|
||
@Test | ||
public void testSendingSinglePartiallyPopulatedLookup() throws Exception { | ||
RequestCapturingSender capturingSender = new RequestCapturingSender(); | ||
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender); | ||
FakeSerializer serializer = new FakeSerializer(new Result()); | ||
Client client = new Client(sender, serializer); | ||
String expectedURL = "http://localhost/?country=1&search=2&max_results=5&distance=5&include_only_administrative_area=3&include_only_locality=4&include_only_postal_code=5"; | ||
Lookup lookup = new Lookup(); | ||
lookup.setCountry("1"); | ||
lookup.setSearch("2"); | ||
lookup.setAdministrativeArea("3"); | ||
lookup.setLocality("4"); | ||
lookup.setPostalCode("5"); | ||
|
||
client.send(lookup); | ||
|
||
assertEquals(expectedURL, capturingSender.getRequest().getUrl()); | ||
} | ||
|
||
@Test | ||
public void testSendingSingleFullyPopulatedLookup() throws Exception { | ||
RequestCapturingSender capturingSender = new RequestCapturingSender(); | ||
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender); | ||
FakeSerializer serializer = new FakeSerializer(new Result()); | ||
Client client = new Client(sender, serializer); | ||
String expectedURL = "http://localhost/?country=1&search=2&max_results=10&distance=8&geolocation=postalcode&include_only_administrative_area=3&include_only_locality=4&include_only_postal_code=5&latitude=10.1&longitude=11.2"; | ||
Lookup lookup = new Lookup(); | ||
lookup.setCountry("1"); | ||
lookup.setSearch("2"); | ||
lookup.setMaxResults(10); | ||
lookup.setDistance(8); | ||
lookup.setGeolocation(InternationalGeolocateType.POSTAL_CODE); | ||
lookup.setAdministrativeArea("3"); | ||
lookup.setLocality("4"); | ||
lookup.setPostalCode("5"); | ||
lookup.setLatitude(10.1f); | ||
lookup.setLongitude(11.2f); | ||
|
||
client.send(lookup); | ||
|
||
assertEquals(expectedURL, capturingSender.getRequest().getUrl()); | ||
} | ||
|
||
//endregion | ||
|
||
//region [ Response Handling ] | ||
|
||
@Test | ||
public void testDeserializeCalledWithResponseBody() throws Exception { | ||
Response response = new Response(0, "Hello, World!".getBytes()); | ||
MockSender mockSender = new MockSender(response); | ||
URLPrefixSender sender = new URLPrefixSender("http://localhost/", mockSender); | ||
FakeDeserializer deserializer = new FakeDeserializer(new Result()); | ||
Client client = new Client(sender, deserializer); | ||
|
||
client.send(new Lookup("1")); | ||
|
||
assertEquals(response.getPayload(), deserializer.getPayload()); | ||
} | ||
|
||
@Test | ||
public void testResultCorrectlyAssignedToCorrespondingLookup() throws Exception { | ||
Lookup lookup = new Lookup("1"); | ||
Result expectedResult = new Result(); | ||
|
||
MockSender mockSender = new MockSender(new Response(0, "{[]}".getBytes())); | ||
URLPrefixSender sender = new URLPrefixSender("http://localhost/", mockSender); | ||
FakeDeserializer deserializer = new FakeDeserializer(expectedResult); | ||
Client client = new Client(sender, deserializer); | ||
|
||
client.send(lookup); | ||
|
||
assertArrayEquals(expectedResult.getCandidates(), lookup.getResult()); | ||
} | ||
|
||
//endregion | ||
} |