Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
postcodes-io-java
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
James Coyle
postcodes-io-java
Commits
83d46c9a
Commit
83d46c9a
authored
Sep 17, 2016
by
Deepak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed methods for better reading
parent
c3104765
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
10 deletions
+12
-10
src/main/java/com/postcode/io/initializers/PostcodeLookup.java
...ain/java/com/postcode/io/initializers/PostcodeLookup.java
+4
-2
src/main/java/com/postcode/io/initializers/ReverseGeocoding.java
...n/java/com/postcode/io/initializers/ReverseGeocoding.java
+1
-1
src/test/java/com/postcode/io/initializers/PostcodeLookupTest.java
...java/com/postcode/io/initializers/PostcodeLookupTest.java
+7
-7
No files found.
src/main/java/com/postcode/io/initializers/PostcodeLookup.java
View file @
83d46c9a
...
...
@@ -5,6 +5,7 @@ import java.util.List;
import
org.json.JSONException
;
import
com.mashape.unirest.http.Unirest
;
import
com.mashape.unirest.http.exceptions.UnirestException
;
import
com.postcode.io.initializers.ReverseGeocoding.Reverse
;
...
...
@@ -91,8 +92,9 @@ public class PostcodeLookup {
return
new
ReverseGeocoding
(
outcode
);
}
public
static
boolean
validate
(
String
postcode
)
throws
JSONException
,
UnirestException
{
return
Postcode
.
validatePostcode
(
postcode
);
public
static
boolean
isValid
(
String
postcode
)
throws
JSONException
,
UnirestException
{
return
Unirest
.
get
(
"https://api.postcodes.io/postcodes/"
.
concat
(
postcode
).
concat
(
"/validate"
)).
asJson
()
.
getBody
().
getObject
().
getBoolean
(
"result"
);
}
public
static
NearestPostcode
nearestPostcode
(
String
postcode
)
{
...
...
src/main/java/com/postcode/io/initializers/ReverseGeocoding.java
View file @
83d46c9a
...
...
@@ -87,7 +87,7 @@ public class ReverseGeocoding {
* @throws IOException
* @throws UnirestException
*/
public
JSONObject
as
j
son
()
throws
IOException
,
UnirestException
{
public
JSONObject
as
J
son
()
throws
IOException
,
UnirestException
{
if
(
random
)
{
return
Unirest
.
get
(
RANDOM_LOOKUP_URL
).
queryString
(
"outcode"
,
outcode
).
asJson
().
getBody
().
getObject
();
}
...
...
src/test/java/com/postcode/io/initializers/PostcodeLookupTest.java
View file @
83d46c9a
...
...
@@ -79,7 +79,7 @@ public class PostcodeLookupTest {
JsonFetcher
.
urlToJson
(
new
File
(
System
.
getProperty
(
"user.dir"
).
concat
(
"/src/test/resources/bulkReverseGeocoding.json"
))
.
toURI
().
toURL
()),
PostcodeLookup
.
reverseGeocodings
(
reverseList
).
as
j
son
(),
JSONCompareMode
.
LENIENT
);
PostcodeLookup
.
reverseGeocodings
(
reverseList
).
as
J
son
(),
JSONCompareMode
.
LENIENT
);
}
@Test
...
...
@@ -89,7 +89,7 @@ public class PostcodeLookupTest {
.
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
).
as
j
son
(),
.
wideSearch
(
true
).
as
J
son
(),
JSONCompareMode
.
STRICT
);
}
...
...
@@ -98,15 +98,15 @@ public class PostcodeLookupTest {
JSONAssert
.
assertEquals
(
Unirest
.
get
(
"https://api.postcodes.io/random/postcodes"
).
queryString
(
"outcode"
,
"bs347np"
).
asJson
()
.
getBody
().
getObject
(),
PostcodeLookup
.
randomPostcode
(
"bs347np"
).
as
j
son
(),
JSONCompareMode
.
LENIENT
);
assertTrue
(
PostcodeLookup
.
randomPostcode
().
as
j
son
().
has
(
"result"
));
assertEquals
(
200
,
PostcodeLookup
.
randomPostcode
().
as
j
son
().
getInt
(
"status"
));
PostcodeLookup
.
randomPostcode
(
"bs347np"
).
as
J
son
(),
JSONCompareMode
.
LENIENT
);
assertTrue
(
PostcodeLookup
.
randomPostcode
().
as
J
son
().
has
(
"result"
));
assertEquals
(
200
,
PostcodeLookup
.
randomPostcode
().
as
J
son
().
getInt
(
"status"
));
}
@Test
public
void
testPostcodeValidator
()
throws
JSONException
,
UnirestException
{
assertTrue
(
PostcodeLookup
.
validate
(
"ST42EU"
));
assertFalse
(
PostcodeLookup
.
validate
(
"ST4"
));
assertTrue
(
PostcodeLookup
.
isValid
(
"ST42EU"
));
assertFalse
(
PostcodeLookup
.
isValid
(
"ST4"
));
}
@Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment