Commit 57a473ae authored by Deepak Prabhakar's avatar Deepak Prabhakar

Removed unused code.

parent 5f0392d7
......@@ -98,16 +98,6 @@ public class PostCodeDetails {
private Codes() {
}
private Codes(String admin_district, String admin_county, String admin_ward, String parish, String ccg,
String nuts) {
this.admin_district = admin_district;
this.admin_county = admin_county;
this.admin_ward = admin_ward;
this.parish = parish;
this.ccg = ccg;
this.nuts = nuts;
}
/**
* <b>District.</b>The current district/unitary authority to which the postcode has been
* assigned.
......
......@@ -57,17 +57,6 @@ public class ReverseGeocoding {
return this;
}
public ReverseGeocoding json(JSONObject json) {
ReverseGeocoding.json = json;
return this;
}
public ReverseGeocoding json(List<Reverse> reverses) {
ReverseGeocoding.reverses = reverses;
ReverseGeocoding.json = createGeocodings(ReverseGeocoding.reverses);
return this;
}
/**
* (not required) Search up to 20km radius, but subject to a maximum of 10 results. Since
* lookups over a wide area can be very expensive, we've created this method to allow you choose
......@@ -82,6 +71,11 @@ public class ReverseGeocoding {
return this;
}
/**
* @return {@link JSONObject}
* @throws IOException
* @throws UnirestException
*/
public JSONObject asjson() throws IOException, UnirestException {
String url = "";
url = url.concat("lon=").concat(String.valueOf(longitude));
......@@ -92,9 +86,7 @@ public class ReverseGeocoding {
if (getRadius() != 0) {
url = url.concat("&radius=").concat(String.valueOf(radius));
}
if (isWideSearch()) {
url = url.concat("&widesearch=").concat(String.valueOf(wideSearch));
}
url = url.concat("&widesearch=").concat(String.valueOf(wideSearch));
try {
if (json != null) {
return JsonFetcher.postURLToJson(new URL(LOOKUP_URL), json);
......@@ -117,26 +109,24 @@ public class ReverseGeocoding {
}
private JSONObject createGeocodings(List<Reverse> reverses) {
JSONObject json = new JSONObject();
JSONObject tempJson;
JSONArray jsonArray = new JSONArray();
for (Reverse reverse : reverses) {
tempJson = new JSONObject();
tempJson.put("longitude", reverse.getLongitude());
tempJson.put("latitude", reverse.getLatitude());
tempJson.put("longitude", reverse.getLongitude().toString());
tempJson.put("latitude", reverse.getLatitude().toString());
if (reverse.getLimit() != 0) {
tempJson.put("limit", reverse.getLimit());
tempJson.put("limit", String.valueOf(reverse.getLimit()));
}
if (reverse.getRadius() != 0) {
tempJson.put("radius", reverse.getRadius());
tempJson.put("radius", String.valueOf(reverse.getRadius()));
}
if (reverse.isWideSearch()) {
tempJson.put("wideSearch", reverse.isWideSearch());
tempJson.put("wideSearch", String.valueOf(reverse.isWideSearch()));
}
jsonArray.put(tempJson);
tempJson = null;
}
return json.put("geolocations", jsonArray);
return new JSONObject().put("geolocations", jsonArray);
}
public class Reverse {
......@@ -203,14 +193,6 @@ public class ReverseGeocoding {
}
}
private static Double getLongitude() {
return longitude;
}
private static Double getLatitude() {
return latitude;
}
private static int getLimit() {
return limit;
}
......@@ -219,8 +201,4 @@ public class ReverseGeocoding {
return radius;
}
private static boolean isWideSearch() {
return wideSearch;
}
}
package com.postcode.io.initializers;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
......@@ -17,6 +15,7 @@ import org.skyscreamer.jsonassert.JSONCompareMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.postcode.io.initializers.ReverseGeocoding.Reverse;
import com.postcode.io.json.JsonFetcher;
......@@ -83,13 +82,10 @@ public class PostcodeLookupTest {
@Test
public void testReverseGeocoding() throws Exception {
assertTrue(PostcodeLookup.reverseGeocoding(0.629834723775309, 51.7923246977375).asjson().has("result"));
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 URL("https://api.postcodes.io/postcodes?lon=0.629834723775309&lat=51.7923246977375&limit=100&radius=2000&widesearch=true")),
Unirest.get("https://api.postcodes.io/postcodes").queryString("lon", 0.629834723775309)
.queryString("lat", 51.7923246977375).queryString("limit", 100).queryString("radius", 2000)
.queryString("widesearch", true).asJson().getBody().getObject(),
PostcodeLookup.reverseGeocoding(0.629834723775309, 51.7923246977375).limit(100).radius(2000)
.wideSearch(true).asjson(),
JSONCompareMode.STRICT);
......
......@@ -2,20 +2,23 @@ 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 {
public void testBuild() throws Exception {
Postcode pc = new Postcode("");
try {
pc.build();
} catch (IllegalArgumentException e) {
assertEquals("postcode/postcodes are mandatory", e.getMessage());
}
try {
pc.asJson();
} catch (IllegalArgumentException e) {
assertEquals("postcode/postcodes are mandatory", e.getMessage());
}
}
}
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