-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestAddressParser.java
More file actions
59 lines (48 loc) · 2.12 KB
/
TestAddressParser.java
File metadata and controls
59 lines (48 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.mapzen.jpostal;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class TestAddressParser {
private static void testParse(String address, ParsedComponent... expectedOutput) {
AddressParser parser = AddressParser.getInstance();
ParsedComponent[] parsedComponents = parser.parseAddress(address);
assertTrue(parsedComponents.length == expectedOutput.length);
for (int i = 0; i < parsedComponents.length; i++) {
ParsedComponent c1 = parsedComponents[i];
ParsedComponent c2 = expectedOutput[i];
assertEquals(c1.getLabel(), c2.getLabel());
assertEquals(c1.getValue(), c2.getValue());
}
}
@Test
public void testParseNull() {
AddressParser parser = AddressParser.getInstance();
ParserOptions options = new ParserOptions.Builder().build();
try {
parser.parseAddress(null);
fail("Should throw NullPointerException to protect JNI");
} catch (NullPointerException e) {}
try {
parser.parseAddressWithOptions(null, options);
fail("Should throw NullPointerException to protect JNI");
} catch (NullPointerException e) {}
try {
parser.parseAddressWithOptions("address", null);
fail("Should throw NullPointerException to protect JNI");
} catch (NullPointerException e) {}
}
@Test
public void testParseUSAddress() {
testParse("781 Franklin Ave Crown Heights Brooklyn NYC NY 11216 USA",
new ParsedComponent("781", "house_number"),
new ParsedComponent("franklin ave", "road"),
new ParsedComponent("crown heights", "suburb"),
new ParsedComponent("brooklyn", "city_district"),
new ParsedComponent("nyc", "city"),
new ParsedComponent("ny", "state"),
new ParsedComponent("11216", "postcode"),
new ParsedComponent("usa", "country")
);
}
}