Commit 2a6a49d6 authored by Deepak Prabhakar's avatar Deepak Prabhakar

Added few more tests for PostcodeLookup

parent e5f4a015
......@@ -66,7 +66,7 @@ public class Postcode {
* @throws MalformedURLException
*/
public PostcodeLookup build() throws MalformedURLException {
if (postcode != null) {
if (postcode != null && !postcode.trim().isEmpty()) {
return new PostcodeLookup(new URL(LOOKUP_URL.toString().concat(postcode)), postcode, postcodes);
} else if (postcode == null && postcodes != null) {
return new PostcodeLookup(new URL(LOOKUP_URL.toString()), postcode, postcodes);
......
......@@ -204,7 +204,7 @@ public class ReverseGeocoding {
return radius;
}
public static boolean isWideSearch() {
private static boolean isWideSearch() {
return wideSearch;
}
......
......@@ -49,7 +49,6 @@ public class PostcodeLookupTest {
.urlToJson(new File(System.getProperty("user.dir").concat("/src/test/resources/postcodeLookup.json"))
.toURI().toURL()),
PostcodeLookup.postcode("bs347np").asJson(), JSONCompareMode.STRICT);
}
@Test
......@@ -87,6 +86,13 @@ public class PostcodeLookupTest {
assertTrue(PostcodeLookup.reverseGeocoding(0.629834723775309, 51.7923246977375).asjson().has("status"));
assertTrue(
PostcodeLookup.reverseGeocoding(0.629834723775309, 51.7923246977375).asjson().getInt("status") == 200);
JSONAssert.assertEquals(
JsonFetcher.urlToJson(new File(
System.getProperty("user.dir").concat("/src/test/resources/reverseGeocodingWithAllParams.json"))
.toURI().toURL()),
PostcodeLookup.reverseGeocoding(0.629834723775309, 51.7923246977375).limit(100).radius(2000)
.wideSearch(true).asjson(),
JSONCompareMode.LENIENT);
}
}
\ No newline at end of file
package com.postcode.io.initializers;
import static org.junit.Assert.assertEquals;
import java.net.MalformedURLException;
import org.junit.Test;
public class PostcodeTest {
@Test
public void testBuild() throws MalformedURLException {
Postcode pc = new Postcode("");
try {
pc.build();
} catch (IllegalArgumentException e) {
assertEquals("postcode/postcodes are mandatory", e.getMessage());
}
}
}
{
"status": 200,
"result": [
{
"postcode": "CM8 1EF",
"quality": 1,
"eastings": 581459,
"northings": 213679,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.629805756141451,
"latitude": 51.7923253460324,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017F",
"msoa": "Braintree 017",
"incode": "1EF",
"outcode": "CM8",
"distance": 1.999933684,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham South",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010388",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1EU",
"quality": 1,
"eastings": 581508,
"northings": 213652,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.630501346634837,
"latitude": 51.7920669594304,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017F",
"msoa": "Braintree 017",
"incode": "1EU",
"outcode": "CM8",
"distance": 54.201577381,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham South",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010388",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1PH",
"quality": 1,
"eastings": 581421,
"northings": 213740,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.629287248592585,
"latitude": 51.792885536147,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017H",
"msoa": "Braintree 017",
"incode": "1PH",
"outcode": "CM8",
"distance": 72.942852885,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham Central",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010386",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1PQ",
"quality": 1,
"eastings": 581399,
"northings": 213755,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.628976438454592,
"latitude": 51.7930273886756,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017H",
"msoa": "Braintree 017",
"incode": "1PQ",
"outcode": "CM8",
"distance": 98.078477373,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham Central",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010386",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1DX",
"quality": 1,
"eastings": 581469,
"northings": 213561,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.629888915851468,
"latitude": 51.7912622833122,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017F",
"msoa": "Braintree 017",
"incode": "1DX",
"outcode": "CM8",
"distance": 118.266954986,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham South",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010388",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1EN",
"quality": 1,
"eastings": 581322,
"northings": 213693,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.627828782756308,
"latitude": 51.7924954789529,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 016A",
"msoa": "Braintree 016",
"incode": "1EN",
"outcode": "CM8",
"distance": 139.698703748,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham Central",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010386",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1ET",
"quality": 1,
"eastings": 581492,
"northings": 213820,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.630357436760122,
"latitude": 51.793581044085,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017H",
"msoa": "Braintree 017",
"incode": "1ET",
"outcode": "CM8",
"distance": 144.36268894,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham Central",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010386",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1XD",
"quality": 1,
"eastings": 581559,
"northings": 213570,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.631197134044156,
"latitude": 51.7913139362243,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017G",
"msoa": "Braintree 017",
"incode": "1XD",
"outcode": "CM8",
"distance": 146.572911495,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham South",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010388",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1FY",
"quality": 1,
"eastings": 581624,
"northings": 213738,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.632226449173734,
"latitude": 51.7928017472759,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017F",
"msoa": "Braintree 017",
"incode": "1FY",
"outcode": "CM8",
"distance": 173.343397689,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham South",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010388",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
},
{
"postcode": "CM8 1AN",
"quality": 1,
"eastings": 581412,
"northings": 213512,
"country": "England",
"nhs_ha": "East of England",
"longitude": 0.629037754187631,
"latitude": 51.7908406614415,
"parliamentary_constituency": "Witham",
"european_electoral_region": "Eastern",
"primary_care_trust": "Mid Essex",
"region": "East of England",
"lsoa": "Braintree 017G",
"msoa": "Braintree 017",
"incode": "1AN",
"outcode": "CM8",
"distance": 174.03432537,
"admin_district": "Braintree",
"parish": "Witham",
"admin_county": "Essex",
"admin_ward": "Witham South",
"ccg": "NHS Mid Essex",
"nuts": "Essex Haven Gateway",
"codes": {
"admin_district": "E07000067",
"admin_county": "E10000012",
"admin_ward": "E05010388",
"parish": "E04003939",
"ccg": "E38000106",
"nuts": "UKH34"
}
}
]
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment