-
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
1 parent
254134b
commit e0b2823
Showing
9 changed files
with
166 additions
and
46 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
2 changes: 1 addition & 1 deletion
2
src/test/java/com/smartystreets/api/us_autocomplete/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
83 changes: 83 additions & 0 deletions
83
src/test/java/com/smartystreets/api/us_autocomplete_pro/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,83 @@ | ||
package com.smartystreets.api.us_autocomplete_pro; | ||
|
||
import com.smartystreets.api.GeolocateType; | ||
import com.smartystreets.api.Response; | ||
import com.smartystreets.api.URLPrefixSender; | ||
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&prefer_geolocation=city", 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/?search=1&max_results=2&include_only_cities=3&include_only_states=4&prefer_ratio=60.0&prefer_geolocation=state"; | ||
Lookup lookup = new Lookup(); | ||
lookup.setSearch("1"); | ||
lookup.setMaxSuggestions(2); | ||
lookup.addCityFilter("3"); | ||
lookup.addStateFilter("4"); | ||
lookup.setPreferRatio(60); | ||
lookup.setGeolocateType(GeolocateType.STATE); | ||
|
||
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.getSuggestions(), lookup.getResult()); | ||
} | ||
|
||
//endregion | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/com/smartystreets/api/us_autocomplete_pro/SuggestionTest.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,24 @@ | ||
package com.smartystreets.api.us_autocomplete_pro; | ||
|
||
|
||
import com.smartystreets.api.GoogleSerializer; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class SuggestionTest { | ||
private final GoogleSerializer googleSerializer = new GoogleSerializer(); | ||
private static final String responsePayload = "{\"suggestions\":[{\"street_line\":\"2\",\"city\":\"3\",\"state\":\"4\"}]}"; | ||
|
||
@Test | ||
public void testAllFieldGetFilledInCorrectly() throws IOException { | ||
Result result = googleSerializer.deserialize(responsePayload.getBytes(), Result.class); | ||
|
||
assertNotNull(result.getSuggestions()[0]); | ||
assertEquals("2", result.getSuggestion(0).getStreetLine()); | ||
assertEquals("3", result.getSuggestion(0).getCity()); | ||
assertEquals("4", result.getSuggestion(0).getState()); | ||
} | ||
} |