aboutsummaryrefslogtreecommitdiff
path: root/java/test/com/android/i18n
diff options
context:
space:
mode:
Diffstat (limited to 'java/test/com/android/i18n')
-rw-r--r--java/test/com/android/i18n/addressinput/AddressDataTest.java72
-rw-r--r--java/test/com/android/i18n/addressinput/AddressFieldTest.java12
-rw-r--r--java/test/com/android/i18n/addressinput/AddressProblemsTest.java22
-rw-r--r--java/test/com/android/i18n/addressinput/AddressVerificationDataTest.java144
-rw-r--r--java/test/com/android/i18n/addressinput/AddressWidgetUiComponentProviderTest.java210
-rw-r--r--java/test/com/android/i18n/addressinput/AsyncTestCaseTest.java88
-rw-r--r--java/test/com/android/i18n/addressinput/CacheDataTest.java534
-rw-r--r--java/test/com/android/i18n/addressinput/ClientDataTest.java90
-rw-r--r--java/test/com/android/i18n/addressinput/FieldVerifierTest.java527
-rw-r--r--java/test/com/android/i18n/addressinput/FormControllerTest.java244
-rw-r--r--java/test/com/android/i18n/addressinput/FormOptionsTest.java34
-rw-r--r--java/test/com/android/i18n/addressinput/FormatInterpreterTest.java350
-rw-r--r--java/test/com/android/i18n/addressinput/JsoMapTest.java376
-rw-r--r--java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java240
-rw-r--r--java/test/com/android/i18n/addressinput/LookupKeyTest.java386
-rw-r--r--java/test/com/android/i18n/addressinput/RegionDataConstantsTest.java32
-rw-r--r--java/test/com/android/i18n/addressinput/RegionDataTest.java44
-rw-r--r--java/test/com/android/i18n/addressinput/StandardAddressVerifierTest.java462
-rw-r--r--java/test/com/android/i18n/addressinput/UtilTest.java230
19 files changed, 2069 insertions, 2028 deletions
diff --git a/java/test/com/android/i18n/addressinput/AddressDataTest.java b/java/test/com/android/i18n/addressinput/AddressDataTest.java
index 7b211b4..870b318 100644
--- a/java/test/com/android/i18n/addressinput/AddressDataTest.java
+++ b/java/test/com/android/i18n/addressinput/AddressDataTest.java
@@ -22,45 +22,45 @@ import junit.framework.TestCase;
* Tests for the AddressData class.
*/
public class AddressDataTest extends TestCase {
- private static final String ADDRESS_LINE = "First address line";
+ private static final String ADDRESS_LINE = "First address line";
- public void testSetAddressLine() {
- AddressData.Builder builder = new AddressData.Builder();
- builder = builder.setAddress("\n " + ADDRESS_LINE);
- AddressData ad = builder.build();
- assertEquals(ADDRESS_LINE, ad.getAddressLine1());
- assertEquals(null, ad.getAddressLine2());
- }
+ public void testSetAddressLine() {
+ AddressData.Builder builder = new AddressData.Builder();
+ builder = builder.setAddress("\n " + ADDRESS_LINE);
+ AddressData ad = builder.build();
+ assertEquals(ADDRESS_LINE, ad.getAddressLine1());
+ assertEquals(null, ad.getAddressLine2());
+ }
- public void testAddressLineNormalisation() {
- AddressData address = new AddressData.Builder().setAddressLine1(null)
- .setAddressLine2(ADDRESS_LINE).build();
- AddressData copiedAddress = new AddressData.Builder(address).build();
- assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine1());
- assertEquals(null, copiedAddress.getAddressLine2());
- }
+ public void testAddressLineNormalisation() {
+ AddressData address = new AddressData.Builder().setAddressLine1(null)
+ .setAddressLine2(ADDRESS_LINE).build();
+ AddressData copiedAddress = new AddressData.Builder(address).build();
+ assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine1());
+ assertEquals(null, copiedAddress.getAddressLine2());
+ }
- public void testAddressLineNormalisationWithNewLineCharacters() {
- AddressData address =
- new AddressData.Builder().setAddressLine1(ADDRESS_LINE + "\n" + ADDRESS_LINE).build();
- AddressData copiedAddress = new AddressData.Builder(address).build();
- assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine1());
- assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine2());
- }
+ public void testAddressLineNormalisationWithNewLineCharacters() {
+ AddressData address =
+ new AddressData.Builder().setAddressLine1(ADDRESS_LINE + "\n" + ADDRESS_LINE).build();
+ AddressData copiedAddress = new AddressData.Builder(address).build();
+ assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine1());
+ assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine2());
+ }
- public void testNoAdminArea() {
- AddressData address = new AddressData.Builder().build();
- assertEquals(null, address.getAdministrativeArea());
- }
+ public void testNoAdminArea() {
+ AddressData address = new AddressData.Builder().build();
+ assertEquals(null, address.getAdministrativeArea());
+ }
- public void testSetLanguageCode() throws Exception {
- AddressData address = new AddressData.Builder().setCountry("TW")
- // Taipei City
- .setAdminArea("\u53F0\u5317\u5E02")
- // Da-an District
- .setLocality("\u5927\u5B89\u5340")
- .build();
- address = new AddressData.Builder(address).setLanguageCode("zh-latn").build();
- assertEquals("zh-latn", address.getLanguageCode());
- }
+ public void testSetLanguageCode() throws Exception {
+ AddressData address = new AddressData.Builder().setCountry("TW")
+ // Taipei City
+ .setAdminArea("\u53F0\u5317\u5E02")
+ // Da-an District
+ .setLocality("\u5927\u5B89\u5340")
+ .build();
+ address = new AddressData.Builder(address).setLanguageCode("zh-latn").build();
+ assertEquals("zh-latn", address.getLanguageCode());
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/AddressFieldTest.java b/java/test/com/android/i18n/addressinput/AddressFieldTest.java
index aa0a741..8009bd5 100644
--- a/java/test/com/android/i18n/addressinput/AddressFieldTest.java
+++ b/java/test/com/android/i18n/addressinput/AddressFieldTest.java
@@ -23,11 +23,11 @@ import junit.framework.TestCase;
*/
public class AddressFieldTest extends TestCase {
- public void testOf() throws Exception {
- assertEquals(AddressField.COUNTRY, AddressField.of('R'));
- }
+ public void testOf() throws Exception {
+ assertEquals(AddressField.COUNTRY, AddressField.of('R'));
+ }
- public void testGetChar() throws Exception {
- assertEquals('R', AddressField.COUNTRY.getChar());
- }
+ public void testGetChar() throws Exception {
+ assertEquals('R', AddressField.COUNTRY.getChar());
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/AddressProblemsTest.java b/java/test/com/android/i18n/addressinput/AddressProblemsTest.java
index 14cef05..8f6740b 100644
--- a/java/test/com/android/i18n/addressinput/AddressProblemsTest.java
+++ b/java/test/com/android/i18n/addressinput/AddressProblemsTest.java
@@ -22,16 +22,16 @@ import junit.framework.TestCase;
* Tests for the AddressProblems class.
*/
public class AddressProblemsTest extends TestCase {
- public void testAddError() {
- AddressProblems ap = new AddressProblems();
- ap.add(AddressField.POSTAL_CODE, AddressProblemType.MISSING_REQUIRED_FIELD);
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- ap.getProblem(AddressField.POSTAL_CODE));
- }
+ public void testAddError() {
+ AddressProblems ap = new AddressProblems();
+ ap.add(AddressField.POSTAL_CODE, AddressProblemType.MISSING_REQUIRED_FIELD);
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ ap.getProblem(AddressField.POSTAL_CODE));
+ }
- public void testEmptyErrorList() {
- AddressProblems ap = new AddressProblems();
- assertNull(ap.getProblem(AddressField.POSTAL_CODE));
- assertTrue(ap.isEmpty());
- }
+ public void testEmptyErrorList() {
+ AddressProblems ap = new AddressProblems();
+ assertNull(ap.getProblem(AddressField.POSTAL_CODE));
+ assertTrue(ap.isEmpty());
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/AddressVerificationDataTest.java b/java/test/com/android/i18n/addressinput/AddressVerificationDataTest.java
index b57955a..40521ab 100644
--- a/java/test/com/android/i18n/addressinput/AddressVerificationDataTest.java
+++ b/java/test/com/android/i18n/addressinput/AddressVerificationDataTest.java
@@ -25,80 +25,80 @@ import junit.framework.TestCase;
*/
public class AddressVerificationDataTest extends TestCase {
- private static final AddressVerificationData ADDRESS_DATA =
- new AddressVerificationData(AddressDataMapLoader.DATA);
-
- public void testParseAllData() {
- for (String key : ADDRESS_DATA.keys()) {
- AddressVerificationNodeData nodeData = ADDRESS_DATA.get(key);
- assertNotNull(key + " maps to null value.", nodeData);
- assertNotNull("Id is required", nodeData.get(AddressDataKey.ID));
- }
- }
-
- public void testLoadingCountries() {
- AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data");
- String[] countries = nodeData.get(AddressDataKey.COUNTRIES).split("~");
- assertTrue(countries.length > 0);
- }
-
- public void testUsData() {
- AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/US");
- assertEquals("data/US", nodeData.get(AddressDataKey.ID));
- assertNotNull(nodeData.get(AddressDataKey.SUB_KEYS));
- assertNotNull(nodeData.get(AddressDataKey.SUB_NAMES));
- assertEquals("en", nodeData.get(AddressDataKey.LANG));
+ private static final AddressVerificationData ADDRESS_DATA =
+ new AddressVerificationData(AddressDataMapLoader.DATA);
+
+ public void testParseAllData() {
+ for (String key : ADDRESS_DATA.keys()) {
+ AddressVerificationNodeData nodeData = ADDRESS_DATA.get(key);
+ assertNotNull(key + " maps to null value.", nodeData);
+ assertNotNull("Id is required", nodeData.get(AddressDataKey.ID));
}
-
- public void testCaData() {
- AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/CA");
- String names = nodeData.get(AddressDataKey.SUB_NAMES);
- String keys = nodeData.get(AddressDataKey.SUB_KEYS);
-
- assertEquals("data/CA", nodeData.get(AddressDataKey.ID));
- assertEquals("en", nodeData.get(AddressDataKey.LANG));
-
- assertEquals("AB~BC~MB~NB~NL~NT~NS~NU~ON~PE~QC~SK~YT", keys);
- assertEquals("Alberta~British Columbia~Manitoba~New Brunswick" +
- "~Newfoundland and Labrador~Northwest Territories~Nova Scotia~Nunavut" +
- "~Ontario~Prince Edward Island~Quebec~Saskatchewan~Yukon",
- names);
- }
-
- public void testCaFrenchData() {
- AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/CA--fr");
- String names = nodeData.get(AddressDataKey.SUB_NAMES);
- String keys = nodeData.get(AddressDataKey.SUB_KEYS);
-
- assertEquals("data/CA--fr", nodeData.get(AddressDataKey.ID));
- assertEquals("fr", nodeData.get(AddressDataKey.LANG));
- assertEquals("AB~BC~PE~MB~NB~NS~NU~ON~QC~SK~NL~NT~YT", keys);
- assertTrue(names.contains("Colombie"));
- }
-
- public void testBackSlashUnEscaped() {
- for (String lookupKey : ADDRESS_DATA.keys()) {
- AddressVerificationNodeData nodeData = ADDRESS_DATA.get(lookupKey);
- for (AddressDataKey dataKey : AddressDataKey.values()) {
- String val = nodeData.get(dataKey);
- if (val != null) {
- assertFalse("Backslashes need to be unescaped: " + val, val.contains("\\\\"));
- }
- }
+ }
+
+ public void testLoadingCountries() {
+ AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data");
+ String[] countries = nodeData.get(AddressDataKey.COUNTRIES).split("~");
+ assertTrue(countries.length > 0);
+ }
+
+ public void testUsData() {
+ AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/US");
+ assertEquals("data/US", nodeData.get(AddressDataKey.ID));
+ assertNotNull(nodeData.get(AddressDataKey.SUB_KEYS));
+ assertNotNull(nodeData.get(AddressDataKey.SUB_NAMES));
+ assertEquals("en", nodeData.get(AddressDataKey.LANG));
+ }
+
+ public void testCaData() {
+ AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/CA");
+ String names = nodeData.get(AddressDataKey.SUB_NAMES);
+ String keys = nodeData.get(AddressDataKey.SUB_KEYS);
+
+ assertEquals("data/CA", nodeData.get(AddressDataKey.ID));
+ assertEquals("en", nodeData.get(AddressDataKey.LANG));
+
+ assertEquals("AB~BC~MB~NB~NL~NT~NS~NU~ON~PE~QC~SK~YT", keys);
+ assertEquals("Alberta~British Columbia~Manitoba~New Brunswick" +
+ "~Newfoundland and Labrador~Northwest Territories~Nova Scotia~Nunavut" +
+ "~Ontario~Prince Edward Island~Quebec~Saskatchewan~Yukon",
+ names);
+ }
+
+ public void testCaFrenchData() {
+ AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/CA--fr");
+ String names = nodeData.get(AddressDataKey.SUB_NAMES);
+ String keys = nodeData.get(AddressDataKey.SUB_KEYS);
+
+ assertEquals("data/CA--fr", nodeData.get(AddressDataKey.ID));
+ assertEquals("fr", nodeData.get(AddressDataKey.LANG));
+ assertEquals("AB~BC~PE~MB~NB~NS~NU~ON~QC~SK~NL~NT~YT", keys);
+ assertTrue(names.contains("Colombie"));
+ }
+
+ public void testBackSlashUnEscaped() {
+ for (String lookupKey : ADDRESS_DATA.keys()) {
+ AddressVerificationNodeData nodeData = ADDRESS_DATA.get(lookupKey);
+ for (AddressDataKey dataKey : AddressDataKey.values()) {
+ String val = nodeData.get(dataKey);
+ if (val != null) {
+ assertFalse("Backslashes need to be unescaped: " + val, val.contains("\\\\"));
}
-
- // Spot check.
- assertEquals("Kazhakstan's postal code pattern mismatched", "\\d{6}",
- ADDRESS_DATA.get("data/KZ").get(AddressDataKey.ZIP));
+ }
}
- public void testExampleData() {
- assertNotNull("Expects example data.", AddressDataMapLoader.DATA.get("examples"));
- assertNotNull("Expects example US address.",
- AddressDataMapLoader.DATA.get("examples/US/local/en"));
- assertEquals("'examples/TW/local/zh_Hant' and 'examples/TW/local/_default' should " +
- "return same value.",
- AddressDataMapLoader.DATA.get("examples/TW/local/zh_Hant"),
- AddressDataMapLoader.DATA.get("examples/TW/local/_default"));
- }
+ // Spot check.
+ assertEquals("Kazhakstan's postal code pattern mismatched", "\\d{6}",
+ ADDRESS_DATA.get("data/KZ").get(AddressDataKey.ZIP));
+ }
+
+ public void testExampleData() {
+ assertNotNull("Expects example data.", AddressDataMapLoader.DATA.get("examples"));
+ assertNotNull("Expects example US address.",
+ AddressDataMapLoader.DATA.get("examples/US/local/en"));
+ assertEquals("'examples/TW/local/zh_Hant' and 'examples/TW/local/_default' should " +
+ "return same value.",
+ AddressDataMapLoader.DATA.get("examples/TW/local/zh_Hant"),
+ AddressDataMapLoader.DATA.get("examples/TW/local/_default"));
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/AddressWidgetUiComponentProviderTest.java b/java/test/com/android/i18n/addressinput/AddressWidgetUiComponentProviderTest.java
index b9c08bd..d519728 100644
--- a/java/test/com/android/i18n/addressinput/AddressWidgetUiComponentProviderTest.java
+++ b/java/test/com/android/i18n/addressinput/AddressWidgetUiComponentProviderTest.java
@@ -34,120 +34,118 @@ import junit.framework.Assert;
/**
* Test class for {@link AddressWidgetUiComponentProvider}.
*/
-public class AddressWidgetUiComponentProviderTest
- extends ActivityInstrumentationTestCase2<TestActivity> {
- private AddressWidget widget;
- private AddressWidgetUiComponentProvider componentProvider;
- private LinearLayout container;
- private AddressData address;
- private Context context;
- private int customTextViewCounter;
- private int customProgressDialogCounter;
-
- public AddressWidgetUiComponentProviderTest() {
- super(TestActivity.class);
+public class AddressWidgetUiComponentProviderTest
+ extends ActivityInstrumentationTestCase2<TestActivity> {
+ private AddressWidget widget;
+ private AddressWidgetUiComponentProvider componentProvider;
+ private LinearLayout container;
+ private AddressData address;
+ private Context context;
+ private int customTextViewCounter;
+ private int customProgressDialogCounter;
+
+ public AddressWidgetUiComponentProviderTest() {
+ super(TestActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ AddressData.Builder builder = new AddressData.Builder()
+ .setCountry("US")
+ .setLanguageCode("en")
+ .setAddressLine1("1098 Alta Ave")
+ .setAdminArea("CA");
+ address = builder.build();
+ context = getActivity();
+ container = new LinearLayout(context);
+ }
+
+ public void testCustomWidgets() {
+ customTextViewCounter = 0;
+ customProgressDialogCounter = 0;
+ componentProvider = new TestComponentProvider(context);
+ widget = new AddressWidget(context, container, new FormOptions.Builder().build(),
+ new SimpleClientCacheManager(), componentProvider);
+ widget.renderFormWithSavedAddress(address);
+
+ for (AddressField field : AddressField.values()) {
+ if (field.equals(AddressField.COUNTRY)) {
+ continue;
+ }
+
+ View view = widget.getViewForField(field);
+ if (view instanceof EditText) {
+ assertTrue("Field " + field + " does not use customized edit text widget.",
+ view instanceof CustomEditText);
+ } else if (view instanceof Spinner) {
+ assertTrue("Field " + field + " does not use customized spinner widget.",
+ view instanceof CustomSpinner);
+ assertTrue("Field " + field + " does not use customized ArrayAdapter.",
+ ((Spinner) view).getAdapter() instanceof CustomArrayAdapter);
+ }
}
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- AddressData.Builder builder = new AddressData.Builder()
- .setCountry("US")
- .setLanguageCode("en")
- .setAddressLine1("1098 Alta Ave")
- .setAdminArea("CA");
- address = builder.build();
- context = getActivity();
- container = new LinearLayout(context);
+
+ assertTrue("Custom TextView label not used.", customTextViewCounter > 0);
+ assertTrue("Custom ProgressDialog not used.", customProgressDialogCounter > 0);
+ }
+
+ private void increaseTextViewCounter() {
+ customTextViewCounter++;
+ }
+
+ private void increaseProgressDialogCounter() {
+ customProgressDialogCounter++;
+ }
+
+ private class CustomEditText extends EditText {
+ CustomEditText(Context context) {
+ super(context);
}
-
- public void testCustomWidgets() {
- customTextViewCounter = 0;
- customProgressDialogCounter = 0;
- componentProvider = new TestComponentProvider(context);
- widget = new AddressWidget(context, container, new FormOptions.Builder().build(),
- new SimpleClientCacheManager(), componentProvider);
- widget.renderFormWithSavedAddress(address);
-
- for (AddressField field : AddressField.values()) {
- if (field.equals(AddressField.COUNTRY)) {
- continue;
- }
-
- View view = widget.getViewForField(field);
- if (view instanceof EditText) {
- assertTrue("Field " + field + " does not use customized edit text widget.",
- view instanceof CustomEditText);
- } else if (view instanceof Spinner) {
- assertTrue("Field " + field + " does not use customized spinner widget.",
- view instanceof CustomSpinner);
- assertTrue("Field " + field + " does not use customized ArrayAdapter.",
- ((Spinner) view).getAdapter() instanceof CustomArrayAdapter);
- }
- }
-
- assertTrue("Custom TextView label not used.", customTextViewCounter > 0);
- assertTrue("Custom ProgressDialog not used.", customProgressDialogCounter > 0);
+ }
+
+ private class CustomSpinner extends Spinner {
+ CustomSpinner(Context context) {
+ super(context);
+ }
+ }
+
+ private class CustomArrayAdapter<String> extends ArrayAdapter {
+ CustomArrayAdapter(Context context, int id) {
+ super(context, id);
}
-
- private void increaseTextViewCounter() {
- customTextViewCounter++;
+ }
+
+ private class TestComponentProvider extends AddressWidgetUiComponentProvider {
+ TestComponentProvider(Context context) {
+ super(context);
}
-
- private void increaseProgressDialogCounter() {
- customProgressDialogCounter++;
+
+ protected TextView createUiLabel(CharSequence label, AddressField.WidthType widthType) {
+ TextView result = new TextView(mContext);
+ result.setText(label);
+ AddressWidgetUiComponentProviderTest.this.increaseTextViewCounter();
+ return result;
}
-
- private class CustomEditText extends EditText {
- CustomEditText(Context context) {
- super(context);
- }
+
+ protected EditText createUiTextField(AddressField.WidthType widthType) {
+ return new CustomEditText(mContext);
}
- private class CustomSpinner extends Spinner {
- CustomSpinner(Context context) {
- super(context);
- }
+ protected Spinner createUiPickerSpinner(AddressField.WidthType widthType) {
+ return new CustomSpinner(mContext);
}
-
- private class CustomArrayAdapter<String> extends ArrayAdapter {
- CustomArrayAdapter(Context context, int id) {
- super(context, id);
- }
+
+ protected ArrayAdapter<String> createUiPickerAdapter(AddressField.WidthType widthType) {
+ ArrayAdapter<String> result = new CustomArrayAdapter<String>(
+ context, android.R.layout.simple_spinner_item);
+ result.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ return result;
}
-
- private class TestComponentProvider extends AddressWidgetUiComponentProvider {
- TestComponentProvider(Context context) {
- super(context);
- }
-
- protected TextView createUiLabel(CharSequence label, AddressField.WidthType widthType) {
- TextView result = new TextView(mContext);
- result.setText(label);
- AddressWidgetUiComponentProviderTest.this.increaseTextViewCounter();
- return result;
- }
-
- protected EditText createUiTextField(AddressField.WidthType widthType) {
- return new CustomEditText(mContext);
- }
-
- protected Spinner createUiPickerSpinner(AddressField.WidthType widthType) {
- return new CustomSpinner(mContext);
- }
-
- protected ArrayAdapter<String> createUiPickerAdapter(AddressField.WidthType widthType) {
- ArrayAdapter<String> result =
- new CustomArrayAdapter<String>(
- mContext, android.R.layout.simple_spinner_item);
- result.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- return result;
- }
-
- protected ProgressDialog getUiActivityIndicatorView() {
- AddressWidgetUiComponentProviderTest.this.increaseProgressDialogCounter();
- return super.getUiActivityIndicatorView();
- }
+
+ protected ProgressDialog getUiActivityIndicatorView() {
+ AddressWidgetUiComponentProviderTest.this.increaseProgressDialogCounter();
+ return super.getUiActivityIndicatorView();
}
+ }
}
- \ No newline at end of file
diff --git a/java/test/com/android/i18n/addressinput/AsyncTestCaseTest.java b/java/test/com/android/i18n/addressinput/AsyncTestCaseTest.java
index 23fad88..36833b8 100644
--- a/java/test/com/android/i18n/addressinput/AsyncTestCaseTest.java
+++ b/java/test/com/android/i18n/addressinput/AsyncTestCaseTest.java
@@ -25,41 +25,41 @@ import java.util.concurrent.TimeoutException;
public class AsyncTestCaseTest extends AsyncTestCase {
public void testSuccess() {
- delayTestFinish(1000);
- AsyncCallback.execute(500, new Runnable() {
- @Override
- public void run() {
- finishTest();
- }
- });
+ delayTestFinish(1000);
+ AsyncCallback.execute(500, new Runnable() {
+ @Override
+ public void run() {
+ finishTest();
+ }
+ });
}
public void testFailure() {
- expectTimeout = true;
- delayTestFinish(1000);
- AsyncCallback.execute(1500, new Runnable() {
- @Override
- public void run() {
- finishTest();
- }
- });
+ expectTimeout = true;
+ delayTestFinish(1000);
+ AsyncCallback.execute(1500, new Runnable() {
+ @Override
+ public void run() {
+ finishTest();
+ }
+ });
}
@Override
protected void runTest() throws Throwable {
- expectTimeout = false;
- try {
- super.runTest();
- } catch (TimeoutException e) {
- if (expectTimeout) {
- return;
- } else {
- throw e;
- }
- }
+ expectTimeout = false;
+ try {
+ super.runTest();
+ } catch (TimeoutException e) {
if (expectTimeout) {
- throw new AssertionFailedError("Test case did not time out.");
+ return;
+ } else {
+ throw e;
}
+ }
+ if (expectTimeout) {
+ throw new AssertionFailedError("Test case did not time out.");
+ }
}
private boolean expectTimeout;
@@ -68,28 +68,28 @@ public class AsyncTestCaseTest extends AsyncTestCase {
* Helper class to perform an asynchronous callback after a specified delay.
*/
private static class AsyncCallback extends Thread {
- public static void execute(long waitMillis, Runnable callback) {
- (new AsyncCallback(waitMillis, callback)).start();
- }
+ private long waitMillis;
+ private Runnable callback;
- @Override
- public void run() {
- try {
- synchronized (this) {
- wait(mWaitMillis);
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- mCallback.run();
+ private AsyncCallback(long waitMillis, Runnable callback) {
+ this.waitMillis = waitMillis;
+ this.callback = callback;
}
- private AsyncCallback(long waitMillis, Runnable callback) {
- this.mWaitMillis = waitMillis;
- this.mCallback = callback;
+ public static void execute(long waitMillis, Runnable callback) {
+ (new AsyncCallback(waitMillis, callback)).start();
}
- private long mWaitMillis;
- private Runnable mCallback;
+ @Override
+ public void run() {
+ try {
+ synchronized (this) {
+ wait(this.waitMillis);
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ this.callback.run();
+ }
}
}
diff --git a/java/test/com/android/i18n/addressinput/CacheDataTest.java b/java/test/com/android/i18n/addressinput/CacheDataTest.java
index c346882..7b72e47 100644
--- a/java/test/com/android/i18n/addressinput/CacheDataTest.java
+++ b/java/test/com/android/i18n/addressinput/CacheDataTest.java
@@ -23,304 +23,304 @@ import org.json.JSONException;
import org.json.JSONObject;
public class CacheDataTest extends AsyncTestCase {
- private CacheData cache;
+ private CacheData cache;
- private static final String DELIM = "~";
+ private static final String DELIM = "~";
- private static final String CANADA_KEY = "data/CA";
+ private static final String CANADA_KEY = "data/CA";
- private static final String US_KEY = "data/US";
+ private static final String US_KEY = "data/US";
- private static final String CALIFORNIA_KEY = "data/US/CA";
+ private static final String CALIFORNIA_KEY = "data/US/CA";
- private static final String RANDOM_COUNTRY_KEY = "data/asIOSDxcowW";
+ private static final String RANDOM_COUNTRY_KEY = "data/asIOSDxcowW";
- private static final String EXAMPLE_LOCAL_US_KEY = "examples/US/local/_default";
+ private static final String EXAMPLE_LOCAL_US_KEY = "examples/US/local/_default";
- // Data key for Da-an District, Taipei Taiwan
- private static final String TW_KEY = "data/TW/\u53F0\u5317\u5E02/\u5927\u5B89\u5340";
+ // Data key for Da-an District, Taipei Taiwan
+ private static final String TW_KEY = "data/TW/\u53F0\u5317\u5E02/\u5927\u5B89\u5340";
- private static final String FRANCE_KEY = "data/FR";
+ private static final String FRANCE_KEY = "data/FR";
- private static Integer listenerInvokeCount = 0;
+ private static Integer listenerInvokeCount = 0;
- private static boolean reachedMaxCount = false;
+ private static boolean reachedMaxCount = false;
- @Override
- public void setUp() {
- cache = new CacheData();
- }
-
- public void testJsonConstructor() {
- // Creating cache with content.
- String id = "data/CA";
- JSONObject jsonObject = null;
- try {
- jsonObject = new JSONObject(AddressDataMapLoader.DATA.get(id));
- } catch (JSONException jsonException) {
- // If this throws an exception the test fails.
- fail("Can't parse json object");
- }
- cache.addToJsoMap(id, jsonObject);
- String toBackup = cache.getJsonString();
-
- // Creating cache from saved data.
- cache = new CacheData(toBackup);
- assertTrue(cache.containsKey(id));
- }
-
- public void testJsonConstructorTruncatedProperString() {
- // Creating cache with content.
- String id = "data/CA";
- try {
- JSONObject jsonObject = new JSONObject(AddressDataMapLoader.DATA.get(id));
- String jsonString = jsonObject.toString();
- jsonString = jsonString.substring(0, jsonString.length() / 2);
-
- cache = new CacheData(jsonString);
- assertTrue(cache.toString(), cache.isEmpty());
- } catch (JSONException jsonException) {
- // If this throws an exception the test fails.
- fail("Can't parse json object");
- }
- }
-
- public void testSimpleFetching() {
- final LookupKey key = new LookupKey.Builder(CANADA_KEY).build();
-
- delayTestFinish(10000);
-
- cache.fetchDynamicData(key, null, new DataLoadListener() {
- boolean beginCalled = false;
-
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called", beginCalled);
- JsoMap map = cache.getObj(CANADA_KEY);
-
- assertTrue(map.containsKey(AddressDataKey.ID.name().toLowerCase()));
- assertTrue(map.containsKey(AddressDataKey.LANG.name().toLowerCase()));
- assertTrue(map.containsKey(AddressDataKey.ZIP.name().toLowerCase()));
- assertTrue(map.containsKey(AddressDataKey.FMT.name().toLowerCase()));
- assertTrue(map.containsKey(AddressDataKey.SUB_KEYS.name().toLowerCase()));
- assertTrue(map.containsKey(AddressDataKey.SUB_NAMES.name().toLowerCase()));
- assertFalse(map.containsKey(AddressDataKey.SUB_LNAMES.name().toLowerCase()));
-
- int namesSize =
- map.get(AddressDataKey.SUB_NAMES.name().toLowerCase()).split(DELIM).length;
- int keysSize =
- map.get(AddressDataKey.SUB_KEYS.name().toLowerCase()).split(DELIM).length;
-
- assertEquals("Expect 13 states in Canada.", 13, namesSize);
- assertEquals(namesSize, keysSize);
- finishTest();
- }
- });
- }
-
- public void testFetchingTaiwanData() {
- final LookupKey key = new LookupKey.Builder(TW_KEY).build();
-
- delayTestFinish(10000);
-
- cache.fetchDynamicData(key, null, new DataLoadListener() {
- boolean beginCalled = false;
-
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called", beginCalled);
-
- JsoMap map = cache.getObj(TW_KEY);
-
- assertTrue(map.containsKey(AddressDataKey.ID.name().toLowerCase()));
- assertTrue(map.containsKey(AddressDataKey.KEY.name().toLowerCase()));
- assertTrue(map.containsKey(AddressDataKey.LANG.name().toLowerCase()));
- assertTrue(map.containsKey(AddressDataKey.ZIP.name().toLowerCase()));
- assertFalse(map.containsKey(AddressDataKey.FMT.name().toLowerCase()));
- assertFalse(map.containsKey(AddressDataKey.SUB_KEYS.name().toLowerCase()));
- assertFalse(map.containsKey(AddressDataKey.SUB_NAMES.name().toLowerCase()));
- assertFalse(map.containsKey(AddressDataKey.SUB_LNAMES.name().toLowerCase()));
-
- // Da-an district.
- assertEquals("\u5927\u5B89\u5340",
- map.get(AddressDataKey.KEY.name().toLowerCase()));
+ @Override
+ public void setUp() {
+ cache = new CacheData();
+ }
- assertEquals("zh-hant", map.get(AddressDataKey.LANG.name().toLowerCase()));
-
- finishTest();
- }
- });
+ public void testJsonConstructor() {
+ // Creating cache with content.
+ String id = "data/CA";
+ JSONObject jsonObject = null;
+ try {
+ jsonObject = new JSONObject(AddressDataMapLoader.DATA.get(id));
+ } catch (JSONException jsonException) {
+ // If this throws an exception the test fails.
+ fail("Can't parse json object");
}
-
- public void testFetchingExamples() {
- final LookupKey key = new LookupKey.Builder(EXAMPLE_LOCAL_US_KEY).build();
-
- delayTestFinish(10000);
-
- cache.fetchDynamicData(key, null, new DataLoadListener() {
- boolean beginCalled = false;
-
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called", beginCalled);
-
- JsoMap map = cache.getObj(EXAMPLE_LOCAL_US_KEY);
- assertTrue(map.containsKey("name"));
- finishTest();
- }
- });
+ cache.addToJsoMap(id, jsonObject);
+ String toBackup = cache.getJsonString();
+
+ // Creating cache from saved data.
+ cache = new CacheData(toBackup);
+ assertTrue(cache.containsKey(id));
+ }
+
+ public void testJsonConstructorTruncatedProperString() {
+ // Creating cache with content.
+ String id = "data/CA";
+ try {
+ JSONObject jsonObject = new JSONObject(AddressDataMapLoader.DATA.get(id));
+ String jsonString = jsonObject.toString();
+ jsonString = jsonString.substring(0, jsonString.length() / 2);
+
+ cache = new CacheData(jsonString);
+ assertTrue(cache.toString(), cache.isEmpty());
+ } catch (JSONException jsonException) {
+ // If this throws an exception the test fails.
+ fail("Can't parse json object");
}
+ }
+
+ public void testSimpleFetching() {
+ final LookupKey key = new LookupKey.Builder(CANADA_KEY).build();
+
+ delayTestFinish(10000);
- public void testFetchingOneKeyManyTimes() {
- final LookupKey key = new LookupKey.Builder(CALIFORNIA_KEY).build();
- final int maxCount = 10;
-
- class CounterListener implements DataLoadListener {
- @Override
- public void dataLoadingBegin() {
- listenerInvokeCount++;
- if (listenerInvokeCount == maxCount) {
- reachedMaxCount = true;
- }
- assertTrue("CounterListener's dataLoadingBegin should not be invoked for more " +
- "than " + maxCount + " times",
- listenerInvokeCount <= maxCount);
- }
-
- @Override
- public void dataLoadingEnd() {
- listenerInvokeCount--;
- assertTrue(listenerInvokeCount >= 0);
- if (listenerInvokeCount == 0) {
- assertTrue("Expect to see key " + key + " cached when CounterListener's " +
- " dataLoadingEnd is invoked",
- cache.containsKey(key.toString()));
- assertTrue("Expect CounterListener's dataLoadingEnd to be triggered " +
- maxCount + " times in total", reachedMaxCount);
- finishTest();
- }
- }
+ cache.fetchDynamicData(key, null, new DataLoadListener() {
+ boolean beginCalled = false;
+
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called", beginCalled);
+ JsoMap map = cache.getObj(CANADA_KEY);
+
+ assertTrue(map.containsKey(AddressDataKey.ID.name().toLowerCase()));
+ assertTrue(map.containsKey(AddressDataKey.LANG.name().toLowerCase()));
+ assertTrue(map.containsKey(AddressDataKey.ZIP.name().toLowerCase()));
+ assertTrue(map.containsKey(AddressDataKey.FMT.name().toLowerCase()));
+ assertTrue(map.containsKey(AddressDataKey.SUB_KEYS.name().toLowerCase()));
+ assertTrue(map.containsKey(AddressDataKey.SUB_NAMES.name().toLowerCase()));
+ assertFalse(map.containsKey(AddressDataKey.SUB_LNAMES.name().toLowerCase()));
+
+ int namesSize =
+ map.get(AddressDataKey.SUB_NAMES.name().toLowerCase()).split(DELIM).length;
+ int keysSize =
+ map.get(AddressDataKey.SUB_KEYS.name().toLowerCase()).split(DELIM).length;
+
+ assertEquals("Expect 13 states in Canada.", 13, namesSize);
+ assertEquals(namesSize, keysSize);
+ finishTest();
+ }
+ });
+ }
+
+ public void testFetchingTaiwanData() {
+ final LookupKey key = new LookupKey.Builder(TW_KEY).build();
+
+ delayTestFinish(10000);
+
+ cache.fetchDynamicData(key, null, new DataLoadListener() {
+ boolean beginCalled = false;
+
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called", beginCalled);
+
+ JsoMap map = cache.getObj(TW_KEY);
+
+ assertTrue(map.containsKey(AddressDataKey.ID.name().toLowerCase()));
+ assertTrue(map.containsKey(AddressDataKey.KEY.name().toLowerCase()));
+ assertTrue(map.containsKey(AddressDataKey.LANG.name().toLowerCase()));
+ assertTrue(map.containsKey(AddressDataKey.ZIP.name().toLowerCase()));
+ assertFalse(map.containsKey(AddressDataKey.FMT.name().toLowerCase()));
+ assertFalse(map.containsKey(AddressDataKey.SUB_KEYS.name().toLowerCase()));
+ assertFalse(map.containsKey(AddressDataKey.SUB_NAMES.name().toLowerCase()));
+ assertFalse(map.containsKey(AddressDataKey.SUB_LNAMES.name().toLowerCase()));
+
+ // Da-an district.
+ assertEquals("\u5927\u5B89\u5340",
+ map.get(AddressDataKey.KEY.name().toLowerCase()));
+
+ assertEquals("zh-hant", map.get(AddressDataKey.LANG.name().toLowerCase()));
+
+ finishTest();
+ }
+ });
+ }
+
+ public void testFetchingExamples() {
+ final LookupKey key = new LookupKey.Builder(EXAMPLE_LOCAL_US_KEY).build();
+
+ delayTestFinish(10000);
+
+ cache.fetchDynamicData(key, null, new DataLoadListener() {
+ boolean beginCalled = false;
+
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called", beginCalled);
+
+ JsoMap map = cache.getObj(EXAMPLE_LOCAL_US_KEY);
+ assertTrue(map.containsKey("name"));
+ finishTest();
+ }
+ });
+ }
+
+ public void testFetchingOneKeyManyTimes() {
+ final LookupKey key = new LookupKey.Builder(CALIFORNIA_KEY).build();
+ final int maxCount = 10;
+
+ class CounterListener implements DataLoadListener {
+ @Override
+ public void dataLoadingBegin() {
+ listenerInvokeCount++;
+ if (listenerInvokeCount == maxCount) {
+ reachedMaxCount = true;
}
-
- delayTestFinish(10000);
-
- for (int i = 0; i < maxCount; ++i) {
- cache.fetchDynamicData(key, null, new CounterListener());
+ assertTrue("CounterListener's dataLoadingBegin should not be invoked for more " +
+ "than " + maxCount + " times",
+ listenerInvokeCount <= maxCount);
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ listenerInvokeCount--;
+ assertTrue(listenerInvokeCount >= 0);
+ if (listenerInvokeCount == 0) {
+ assertTrue("Expect to see key " + key + " cached when CounterListener's " +
+ " dataLoadingEnd is invoked",
+ cache.containsKey(key.toString()));
+ assertTrue("Expect CounterListener's dataLoadingEnd to be triggered " +
+ maxCount + " times in total", reachedMaxCount);
+ finishTest();
}
-
- // Null listeners should not affect results.
- cache.fetchDynamicData(key, null, null);
- cache.fetchDynamicData(key, null, null);
- cache.fetchDynamicData(key, null, null);
+ }
}
- public void testFetchAgainRightAfterOneFetchStart() {
- final LookupKey key = new LookupKey.Builder(US_KEY).build();
+ delayTestFinish(10000);
- delayTestFinish(10000);
+ for (int i = 0; i < maxCount; ++i) {
+ cache.fetchDynamicData(key, null, new CounterListener());
+ }
- cache.fetchDynamicData(key, null, null);
+ // Null listeners should not affect results.
+ cache.fetchDynamicData(key, null, null);
+ cache.fetchDynamicData(key, null, null);
+ cache.fetchDynamicData(key, null, null);
+ }
- cache.fetchDynamicData(key, null, new DataLoadListener() {
- boolean beginCalled = false;
-
- @Override
- public void dataLoadingBegin() {
- assertFalse("data for key " + key + " should not be fetched yet",
- cache.containsKey(key.toString()));
- beginCalled = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called", beginCalled);
-
- assertTrue(cache.containsKey(key.toString()));
-
- cache.fetchDynamicData(key, null, new DataLoadListener() {
- boolean beginCalled2 = false;
-
- @Override
- public void dataLoadingBegin() {
- beginCalled2 = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called", beginCalled2);
-
- assertTrue(cache.containsKey(key.toString()));
- finishTest();
- }
- });
- }
- });
- }
+ public void testFetchAgainRightAfterOneFetchStart() {
+ final LookupKey key = new LookupKey.Builder(US_KEY).build();
- public void testInvalidKey() {
- final LookupKey key = new LookupKey.Builder(RANDOM_COUNTRY_KEY).build();
+ delayTestFinish(10000);
- delayTestFinish(15000);
+ cache.fetchDynamicData(key, null, null);
- cache.fetchDynamicData(key, null, new DataLoadListener() {
- boolean beginCalled = false;
+ cache.fetchDynamicData(key, null, new DataLoadListener() {
+ boolean beginCalled = false;
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
+ @Override
+ public void dataLoadingBegin() {
+ assertFalse("data for key " + key + " should not be fetched yet",
+ cache.containsKey(key.toString()));
+ beginCalled = true;
+ }
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called", beginCalled);
- assertFalse(cache.containsKey(key.toString()));
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called", beginCalled);
- finishTest();
- }
- });
- }
+ assertTrue(cache.containsKey(key.toString()));
- public void testSetUrl() {
- final LookupKey key = new LookupKey.Builder(FRANCE_KEY).build();
- final String originalUrl = cache.getUrl();
+ cache.fetchDynamicData(key, null, new DataLoadListener() {
+ boolean beginCalled2 = false;
- assertFalse(FRANCE_KEY + " should not be in the cache. Do you request it before this test?",
- cache.containsKey(key.toString()));
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled2 = true;
+ }
- delayTestFinish(10000);
- // Something that is not an URL.
- cache.setUrl("FDSSfdfdsfasdfadsf");
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called", beginCalled2);
- cache.fetchDynamicData(key, null, new DataLoadListener() {
- boolean beginCalled = false;
-
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called", beginCalled);
- assertFalse(cache.containsKey(key.toString()));
- cache.setUrl(originalUrl);
- finishTest();
- }
+ assertTrue(cache.containsKey(key.toString()));
+ finishTest();
+ }
});
- }
+ }
+ });
+ }
+
+ public void testInvalidKey() {
+ final LookupKey key = new LookupKey.Builder(RANDOM_COUNTRY_KEY).build();
+
+ delayTestFinish(15000);
+
+ cache.fetchDynamicData(key, null, new DataLoadListener() {
+ boolean beginCalled = false;
+
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called", beginCalled);
+ assertFalse(cache.containsKey(key.toString()));
+
+ finishTest();
+ }
+ });
+ }
+
+ public void testSetUrl() {
+ final LookupKey key = new LookupKey.Builder(FRANCE_KEY).build();
+ final String originalUrl = cache.getUrl();
+
+ assertFalse(FRANCE_KEY + " should not be in the cache. Do you request it before this test?",
+ cache.containsKey(key.toString()));
+
+ delayTestFinish(10000);
+ // Something that is not an URL.
+ cache.setUrl("FDSSfdfdsfasdfadsf");
+
+ cache.fetchDynamicData(key, null, new DataLoadListener() {
+ boolean beginCalled = false;
+
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called", beginCalled);
+ assertFalse(cache.containsKey(key.toString()));
+ cache.setUrl(originalUrl);
+ finishTest();
+ }
+ });
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/ClientDataTest.java b/java/test/com/android/i18n/addressinput/ClientDataTest.java
index b18d726..c665a3b 100644
--- a/java/test/com/android/i18n/addressinput/ClientDataTest.java
+++ b/java/test/com/android/i18n/addressinput/ClientDataTest.java
@@ -23,61 +23,61 @@ import com.android.i18n.addressinput.testing.AsyncTestCase;
* server and recovers if no data is present.
*/
public class ClientDataTest extends AsyncTestCase {
- private ClientData client;
+ private ClientData client;
- @Override
- public void setUp() {
- client = new ClientData(new CacheData());
- }
+ @Override
+ public void setUp() {
+ client = new ClientData(new CacheData());
+ }
- public void testGet() {
- AddressVerificationNodeData data = client.get("data");
- assertNotNull(data);
- }
+ public void testGet() {
+ AddressVerificationNodeData data = client.get("data");
+ assertNotNull(data);
+ }
- public void testGet2() {
- AddressVerificationNodeData data;
+ public void testGet2() {
+ AddressVerificationNodeData data;
- data = client.get("data");
- assertNotNull(data);
+ data = client.get("data");
+ assertNotNull(data);
- data = client.get("data");
- assertNotNull(data);
- }
+ data = client.get("data");
+ assertNotNull(data);
+ }
- public void testPrefetchCountry() {
- delayTestFinish(60000);
+ public void testPrefetchCountry() {
+ delayTestFinish(60000);
- client.prefetchCountry("TW", new DataLoadListener() {
- boolean beginCalled = false;
+ client.prefetchCountry("TW", new DataLoadListener() {
+ boolean beginCalled = false;
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called", beginCalled);
- // Currently this test only tests that the execution doesn't crash and eventually
- // terminates. TODO: Write test cases to verify that correct data is loaded.
- finishTest();
- }
- });
- }
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called", beginCalled);
+ // Currently this test only tests that the execution doesn't crash and eventually
+ // terminates. TODO: Write test cases to verify that correct data is loaded.
+ finishTest();
+ }
+ });
+ }
- public void testFetchDataWithBadServer() {
- CacheData badCache = new CacheData();
- badCache.setUrl("http://www.google.com");
- ClientData badServerClient = new ClientData(badCache);
+ public void testFetchDataWithBadServer() {
+ CacheData badCache = new CacheData();
+ badCache.setUrl("http://www.google.com");
+ ClientData badServerClient = new ClientData(badCache);
- AddressVerificationNodeData data = badServerClient.get("data/US");
+ AddressVerificationNodeData data = badServerClient.get("data/US");
- // No data was available on the server or in the cache - it should check
- // that there is nothing in region data constants, and should return the
- // data from there.
- assertNotNull(data);
- String unitedStatesFormatInfo = data.get(AddressDataKey.FMT);
- assertEquals("%N%n%O%n%A%n%C, %S %Z", unitedStatesFormatInfo);
- }
+ // No data was available on the server or in the cache - it should check
+ // that there is nothing in region data constants, and should return the
+ // data from there.
+ assertNotNull(data);
+ String unitedStatesFormatInfo = data.get(AddressDataKey.FMT);
+ assertEquals("%N%n%O%n%A%n%C, %S %Z", unitedStatesFormatInfo);
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/FieldVerifierTest.java b/java/test/com/android/i18n/addressinput/FieldVerifierTest.java
index 6521a5a..2988691 100644
--- a/java/test/com/android/i18n/addressinput/FieldVerifierTest.java
+++ b/java/test/com/android/i18n/addressinput/FieldVerifierTest.java
@@ -20,252 +20,295 @@ import com.android.i18n.addressinput.testing.AddressDataMapLoader;
import junit.framework.TestCase;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.Map;
+import java.util.Set;
+
/**
* Spot check the standard data set for various cases of interest. This is not an exhaustive test.
*/
public class FieldVerifierTest extends TestCase {
- private static final StandardAddressVerifier VERIFIER =
- new StandardAddressVerifier(new FieldVerifier(
- new AddressVerificationData(AddressDataMapLoader.DATA)));
-
- private AddressProblems problems = new AddressProblems();
-
- @Override
- protected void setUp() {
- problems.clear();
- }
-
- public void testUnitedStatesOk() {
- AddressData addr = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mountain View")
- .setAddress("1234 Somewhere")
- .setPostalCode("94025").build();
- VERIFIER.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty()); // no mismatch
- }
-
- public void testUnitedStatesZipMismatch() {
- AddressData addr = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mountain View")
- .setPostalCode("12345").build();
- VERIFIER.verify(addr, problems);
-
- assertEquals(AddressProblemType.MISMATCHING_VALUE,
- problems.getProblem(AddressField.POSTAL_CODE));
- }
-
- public void testUnitedStatesNotOk() {
- AddressData addr = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality(null)
- .setDependentLocality("Foo Bar")
- .setPostalCode("12345").build();
- VERIFIER.verify(addr, problems);
-
- assertEquals(AddressProblemType.MISMATCHING_VALUE,
- problems.getProblem(AddressField.POSTAL_CODE));
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- problems.getProblem(AddressField.LOCALITY));
- }
-
- public void testChinaOk() {
- AddressData addr = new AddressData.Builder().setCountry("CN")
- .setAdminArea("Beijing Shi")
- .setLocality("Xicheng Qu")
- .setAddress("Yitiao Lu")
- .setPostalCode("123456").build();
- VERIFIER.verify(addr, problems);
- assertTrue(problems.isEmpty());
- }
-
- public void testGermanAddress() {
- AddressData addr = new AddressData.Builder().setCountry("DE")
- .setLocality("Berlin")
- .setAddress("Huttenstr. 50")
- .setPostalCode("10553")
- .setOrganization("BMW AG Niederkassung Berlin")
- .setRecipient("Herr Diefendorf").build();
-
- VERIFIER.verify(addr, problems);
- assertTrue(problems.isEmpty());
-
- // Clones address but leave city empty.
- addr = new AddressData.Builder().set(addr).setLocality(null).build();
-
- VERIFIER.verify(addr, problems);
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- problems.getProblem(AddressField.LOCALITY));
- }
-
- public void testIrishAddress() {
- AddressData addr = new AddressData.Builder().setCountry("IE")
- .setLocality("Dublin")
- .setAdminArea("Co. Dublin")
- .setAddress("7424 118 Avenue NW")
- .setRecipient("Conan O'Brien").build();
-
- VERIFIER.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
-
- // Clones address but leave county empty. This address should be valid
- // since county is not required.
- addr = new AddressData.Builder().set(addr).setAdminArea(null).build();
-
- VERIFIER.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
- }
-
- public void testChinaPostalCodeBadFormat() {
- AddressData addr = new AddressData.Builder().setCountry("CN")
- .setAdminArea("Beijing Shi")
- .setLocality("Xicheng Qu")
- .setPostalCode("12345").build();
- VERIFIER.verify(addr, problems);
-
- assertEquals(AddressProblemType.UNRECOGNIZED_FORMAT,
- problems.getProblem(AddressField.POSTAL_CODE));
- }
-
- /**
- * If there is a postal code pattern for a certain country, and the input postal code is empty,
- * it should not be reported as bad postal code format. Whether empty postal code is ok should
- * be determined by checks for required fields.
- */
- public void testEmptyPostalCodeReportedAsGoodFormat() {
- // Chilean address has a postal code format pattern, but does not require
- // postal code. The following address is valid.
- AddressData addr = new AddressData.Builder().setCountry("CL")
- .setAddressLine1("GUSTAVO LE PAIGE ST #159")
- .setAdminArea("Atacama")
- .setLocality("San Pedro")
- .setPostalCode("")
- .build();
- VERIFIER.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
-
- problems.clear();
-
- // Now check for US addresses, which require a postal code. The following
- // address's postal code is wrong because it is missing a required field, not
- // because it doesn't match the expected postal code pattern.
- addr = new AddressData.Builder().setCountry("US").setPostalCode("").build();
- problems.clear();
- VERIFIER.verify(addr, problems);
-
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- problems.getProblem(AddressField.POSTAL_CODE));
- }
-
- public void testChinaTaiwanOk() {
- AddressData addr = new AddressData.Builder().setCountry("CN")
- .setAdminArea("Taiwan")
- .setLocality("Taichung City")
- .setDependentLocality("Situn District")
- .setAddress("12345 Yitiao Lu")
- .setPostalCode("407").build();
- VERIFIER.verify(addr, problems);
- assertTrue(problems.isEmpty());
- }
-
- public void testChinaTaiwanUnknownDistrict() {
- AddressData addr = new AddressData.Builder().setCountry("CN")
- .setAdminArea("Taiwan")
- .setLocality("Taichung City")
- .setDependentLocality("Foo Bar")
- .setPostalCode("400").build();
- VERIFIER.verify(addr, problems);
-
- assertEquals(AddressProblemType.UNKNOWN_VALUE,
- problems.getProblem(AddressField.DEPENDENT_LOCALITY));
- }
-
- public void testStreetVerification() {
- // Missing street address
- AddressData addr = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mountain View")
- .setPostalCode("94025").build();
-
- assertNull(addr.getAddressLine1());
- assertNull(addr.getAddressLine2());
-
- VERIFIER.verify(addr, problems);
-
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- problems.getProblem(AddressField.STREET_ADDRESS));
- }
-
- // Tests The Bahamas' address
- public void failingtestBahamas() {
- final AddressData address =
- new AddressData.Builder().setAddress("Abaco Beach Resort & Boat Habour")
- .setLocality("Treasure Cay")
- .setAdminArea("Abaco")
- .setCountry("BS").build();
- VERIFIER.verify(address, problems);
- assertTrue(problems.isEmpty());
- }
-
- public void testJapan() {
- // Added AdminArea since address verification can't infer it from Kyoto City
- // Commented out dependent locality since we don't have the data for this and in fact say
- // that it shouldn't be used for Japan.
- // TODO: support inference of higher levels from lower ones
- final AddressData address = new AddressData.Builder()
- .setRecipient("\u5BAE\u672C \u8302") // SHIGERU_MIYAMOTO
- .setAddress("\u4E0A\u9CE5\u7FBD\u927E\u7ACB\u753A11\u756A\u5730")
- .setAdminArea("\u4eac\u90fd\u5e9c") // Kyoto prefecture, added
- .setLocality("\u4EAC\u90FD\u5E02") // Kyoto city
- // .setDependentLocality("\u5357\u533A")
- .setCountry("JP")
- .setPostalCode("601-8501").build();
- VERIFIER.verify(address, problems);
- assertTrue(problems.toString(), problems.isEmpty());
- }
-
- public void testJapanLatin() {
- // added AdminArea since address verification can't infer it from Kyoto City
- // commented out dependent locality since address verification doesn't use it
- final AddressData address = new AddressData.Builder()
- .setRecipient("Shigeru Miyamoto") // SHIGERU_MIYAMOTO_ENGLISH
- .setAddress("11-1 Kamitoba-hokotate-cho")
- .setAdminArea("KYOTO") // added
- .setLocality("Kyoto")
- // .setDependentLocality("Minami-ku")
- .setLanguageCode("ja_Latn")
- .setCountry("JP")
- .setPostalCode("601-8501").build();
- VERIFIER.verify(address, problems);
- assertTrue(problems.isEmpty());
- }
-
- public void testJapanLatinInvalidAdmin() {
- final AddressData address = new AddressData.Builder()
- .setRecipient("Shigeru Miyamoto") // SHIGERU_MIYAMOTO_ENGLISH
- .setAddress("11-1 Kamitoba-hokotate-cho")
- .setAdminArea("Fake Admin")
- .setLocality("Kyoto")
- .setLanguageCode("ja_Latn")
- .setCountry("JP")
- .setPostalCode("601-8501").build();
- VERIFIER.verify(address, problems);
- assertFalse(problems.isEmpty());
- assertEquals(AddressProblemType.UNKNOWN_VALUE,
- problems.getProblem(AddressField.ADMIN_AREA));
- }
-
- public void testCanadaMixedCasePostcode() {
- final AddressData address = new AddressData.Builder()
- .setRecipient("Joe Bloggs")
- .setAddress("11 East St")
- .setLocality("Montreal")
- .setAdminArea("Quebec")
- .setCountry("CA")
- .setPostalCode("H2b 2y5").build();
- VERIFIER.verify(address, problems);
- assertTrue(problems.isEmpty());
+ private static final StandardAddressVerifier VERIFIER =
+ new StandardAddressVerifier(new FieldVerifier(
+ new AddressVerificationData(AddressDataMapLoader.DATA)));
+
+ private AddressProblems problems = new AddressProblems();
+
+ @Override
+ protected void setUp() {
+ problems.clear();
+ }
+
+ public void testUnitedStatesOk() {
+ AddressData addr = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mountain View")
+ .setAddress("1234 Somewhere")
+ .setPostalCode("94025").build();
+ VERIFIER.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty()); // no mismatch
+ }
+
+ public void testUnitedStatesZipMismatch() {
+ AddressData addr = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mountain View")
+ .setPostalCode("12345").build();
+ VERIFIER.verify(addr, problems);
+
+ assertEquals(AddressProblemType.MISMATCHING_VALUE,
+ problems.getProblem(AddressField.POSTAL_CODE));
+ }
+
+ public void testUnitedStatesNotOk() {
+ AddressData addr = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality(null)
+ .setDependentLocality("Foo Bar")
+ .setPostalCode("12345").build();
+ VERIFIER.verify(addr, problems);
+
+ assertEquals(AddressProblemType.MISMATCHING_VALUE,
+ problems.getProblem(AddressField.POSTAL_CODE));
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ problems.getProblem(AddressField.LOCALITY));
+ }
+
+ public void testChinaOk() {
+ AddressData addr = new AddressData.Builder().setCountry("CN")
+ .setAdminArea("Beijing Shi")
+ .setLocality("Xicheng Qu")
+ .setAddress("Yitiao Lu")
+ .setPostalCode("123456").build();
+ VERIFIER.verify(addr, problems);
+ assertTrue(problems.isEmpty());
+ }
+
+ public void testGermanAddress() {
+ AddressData addr = new AddressData.Builder().setCountry("DE")
+ .setLocality("Berlin")
+ .setAddress("Huttenstr. 50")
+ .setPostalCode("10553")
+ .setOrganization("BMW AG Niederkassung Berlin")
+ .setRecipient("Herr Diefendorf").build();
+
+ VERIFIER.verify(addr, problems);
+ assertTrue(problems.isEmpty());
+
+ // Clones address but leave city empty.
+ addr = new AddressData.Builder().set(addr).setLocality(null).build();
+
+ VERIFIER.verify(addr, problems);
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ problems.getProblem(AddressField.LOCALITY));
+ }
+
+ public void testIrishAddress() {
+ AddressData addr = new AddressData.Builder().setCountry("IE")
+ .setLocality("Dublin")
+ .setAdminArea("Co. Dublin")
+ .setAddress("7424 118 Avenue NW")
+ .setRecipient("Conan O'Brien").build();
+
+ VERIFIER.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+
+ // Clones address but leave county empty. This address should be valid
+ // since county is not required.
+ addr = new AddressData.Builder().set(addr).setAdminArea(null).build();
+
+ VERIFIER.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+ }
+
+ public void testChinaPostalCodeBadFormat() {
+ AddressData addr = new AddressData.Builder().setCountry("CN")
+ .setAdminArea("Beijing Shi")
+ .setLocality("Xicheng Qu")
+ .setPostalCode("12345").build();
+ VERIFIER.verify(addr, problems);
+
+ assertEquals(AddressProblemType.UNRECOGNIZED_FORMAT,
+ problems.getProblem(AddressField.POSTAL_CODE));
+ }
+
+ /**
+ * If there is a postal code pattern for a certain country, and the input postal code is empty,
+ * it should not be reported as bad postal code format. Whether empty postal code is ok should
+ * be determined by checks for required fields.
+ */
+ public void testEmptyPostalCodeReportedAsGoodFormat() {
+ // Chilean address has a postal code format pattern, but does not require
+ // postal code. The following address is valid.
+ AddressData addr = new AddressData.Builder().setCountry("CL")
+ .setAddressLine1("GUSTAVO LE PAIGE ST #159")
+ .setAdminArea("Atacama")
+ .setLocality("San Pedro")
+ .setPostalCode("")
+ .build();
+ VERIFIER.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+
+ problems.clear();
+
+ // Now check for US addresses, which require a postal code. The following
+ // address's postal code is wrong because it is missing a required field, not
+ // because it doesn't match the expected postal code pattern.
+ addr = new AddressData.Builder().setCountry("US").setPostalCode("").build();
+ problems.clear();
+ VERIFIER.verify(addr, problems);
+
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ problems.getProblem(AddressField.POSTAL_CODE));
+ }
+
+ public void testChinaTaiwanOk() {
+ AddressData addr = new AddressData.Builder().setCountry("CN")
+ .setAdminArea("Taiwan")
+ .setLocality("Taichung City")
+ .setDependentLocality("Situn District")
+ .setAddress("12345 Yitiao Lu")
+ .setPostalCode("407").build();
+ VERIFIER.verify(addr, problems);
+ assertTrue(problems.isEmpty());
+ }
+
+ public void testChinaTaiwanUnknownDistrict() {
+ AddressData addr = new AddressData.Builder().setCountry("CN")
+ .setAdminArea("Taiwan")
+ .setLocality("Taichung City")
+ .setDependentLocality("Foo Bar")
+ .setPostalCode("400").build();
+ VERIFIER.verify(addr, problems);
+
+ assertEquals(AddressProblemType.UNKNOWN_VALUE,
+ problems.getProblem(AddressField.DEPENDENT_LOCALITY));
+ }
+
+ public void testStreetVerification() {
+ // Missing street address
+ AddressData addr = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mountain View")
+ .setPostalCode("94025").build();
+
+ assertNull(addr.getAddressLine1());
+ assertNull(addr.getAddressLine2());
+
+ VERIFIER.verify(addr, problems);
+
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ problems.getProblem(AddressField.STREET_ADDRESS));
+ }
+
+ // Tests The Bahamas' address
+ public void failingtestBahamas() {
+ final AddressData address =
+ new AddressData.Builder().setAddress("Abaco Beach Resort & Boat Habour")
+ .setLocality("Treasure Cay")
+ .setAdminArea("Abaco")
+ .setCountry("BS").build();
+ VERIFIER.verify(address, problems);
+ assertTrue(problems.isEmpty());
+ }
+
+ public void testJapan() {
+ // Added AdminArea since address verification can't infer it from Kyoto City
+ // Commented out dependent locality since we don't have the data for this and in fact say
+ // that it shouldn't be used for Japan.
+ // TODO: support inference of higher levels from lower ones
+ final AddressData address = new AddressData.Builder()
+ .setRecipient("\u5BAE\u672C \u8302") // SHIGERU_MIYAMOTO
+ .setAddress("\u4E0A\u9CE5\u7FBD\u927E\u7ACB\u753A11\u756A\u5730")
+ .setAdminArea("\u4eac\u90fd\u5e9c") // Kyoto prefecture, added
+ .setLocality("\u4EAC\u90FD\u5E02") // Kyoto city
+ // .setDependentLocality("\u5357\u533A")
+ .setCountry("JP")
+ .setPostalCode("601-8501").build();
+ VERIFIER.verify(address, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+ }
+
+ public void testJapanLatin() {
+ // added AdminArea since address verification can't infer it from Kyoto City
+ // commented out dependent locality since address verification doesn't use it
+ final AddressData address = new AddressData.Builder()
+ .setRecipient("Shigeru Miyamoto") // SHIGERU_MIYAMOTO_ENGLISH
+ .setAddress("11-1 Kamitoba-hokotate-cho")
+ .setAdminArea("KYOTO") // added
+ .setLocality("Kyoto")
+ // .setDependentLocality("Minami-ku")
+ .setLanguageCode("ja_Latn")
+ .setCountry("JP")
+ .setPostalCode("601-8501").build();
+ VERIFIER.verify(address, problems);
+ assertTrue(problems.isEmpty());
+ }
+
+ public void testJapanLatinInvalidAdmin() {
+ final AddressData address = new AddressData.Builder()
+ .setRecipient("Shigeru Miyamoto") // SHIGERU_MIYAMOTO_ENGLISH
+ .setAddress("11-1 Kamitoba-hokotate-cho")
+ .setAdminArea("Fake Admin")
+ .setLocality("Kyoto")
+ .setLanguageCode("ja_Latn")
+ .setCountry("JP")
+ .setPostalCode("601-8501").build();
+ VERIFIER.verify(address, problems);
+ assertFalse(problems.isEmpty());
+ assertEquals(AddressProblemType.UNKNOWN_VALUE,
+ problems.getProblem(AddressField.ADMIN_AREA));
+ }
+
+ public void testCanadaMixedCasePostcode() {
+ final AddressData address = new AddressData.Builder()
+ .setRecipient("Joe Bloggs")
+ .setAddress("11 East St")
+ .setLocality("Montreal")
+ .setAdminArea("Quebec")
+ .setCountry("CA")
+ .setPostalCode("H2b 2y5").build();
+ VERIFIER.verify(address, problems);
+ assertTrue(problems.isEmpty());
+ }
+
+ public void testMultipleAddressLines() {
+ final AddressData address = new AddressData.Builder()
+ .setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mountain View")
+ .setAddressLine1("Somewhere")
+ .setAddressLine2("1234")
+ .setPostalCode("94025").build();
+ VERIFIER.verify(address, problems);
+ assertTrue(problems.isEmpty());
+ }
+
+ public void testFieldVerifierUsesRegionDataConstantsForFmtAndRequire() {
+ Map<AddressDataKey, String> map = new EnumMap<AddressDataKey, String>(AddressDataKey.class);
+ // Values for format and require are deliberately different from RegionDataConstants so that
+ // we can test that the RDC's version is preferred.
+ map.put(AddressDataKey.FMT, "%N%n%O");
+ map.put(AddressDataKey.REQUIRE, "A");
+ map.put(AddressDataKey.SUB_KEYS, "Test");
+ map.put(AddressDataKey.ID, "data/FM");
+ AddressVerificationNodeData testNode = new AddressVerificationNodeData(map);
+ FieldVerifier fieldVerifier = new FieldVerifier(VERIFIER.rootVerifier, testNode);
+
+ // Used and required obtained from RegionDataConstants for FM.
+ Set<AddressField> expectedPossibleFields = EnumSet.of(AddressField.RECIPIENT,
+ AddressField.ORGANIZATION, AddressField.STREET_ADDRESS, AddressField.LOCALITY,
+ AddressField.ADMIN_AREA, AddressField.POSTAL_CODE, AddressField.COUNTRY);
+ Set<AddressField> expectedRequiredField = EnumSet.of(AddressField.STREET_ADDRESS,
+ AddressField.LOCALITY, AddressField.ADMIN_AREA, AddressField.POSTAL_CODE,
+ AddressField.COUNTRY);
+ assertEquals(expectedPossibleFields, fieldVerifier.possiblyUsedFields);
+ assertEquals(expectedRequiredField, fieldVerifier.required);
+ assertEquals("data/FM", fieldVerifier.id);
+ // Keys should be populated from the test node.
+ assertEquals("[Test]", Arrays.toString(fieldVerifier.keys));
}
}
diff --git a/java/test/com/android/i18n/addressinput/FormControllerTest.java b/java/test/com/android/i18n/addressinput/FormControllerTest.java
index 23b798f..c0fa877 100644
--- a/java/test/com/android/i18n/addressinput/FormControllerTest.java
+++ b/java/test/com/android/i18n/addressinput/FormControllerTest.java
@@ -26,126 +26,126 @@ import java.util.List;
*/
public class FormControllerTest extends AsyncTestCase {
- private static final AddressData US_CA_ADDRESS;
- private static final AddressData US_ADDRESS;
- private ClientData clientData;
-
- static {
- US_CA_ADDRESS = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mt View")
- .setAddressLine1("1098 Alta Ave")
- .setPostalCode("94043")
- .build();
- US_ADDRESS = new AddressData.Builder().setCountry("US").build();
- }
-
- @Override
- public void setUp() {
- clientData = new ClientData(new CacheData());
- }
-
- public void testRequestDataForAddress() {
- final FormController controller = new FormController(clientData, "en", "US");
-
- delayTestFinish(15000);
-
- controller.requestDataForAddress(US_CA_ADDRESS, new DataLoadListener() {
- boolean beginCalled = false;
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called before dataLoadingEnd",
- beginCalled);
- LookupKey usCaMtvKey = new LookupKey.Builder(KeyType.DATA)
- .setAddressData(US_CA_ADDRESS).build();
- LookupKey usKey = usCaMtvKey.getKeyForUpperLevelField(
- AddressField.COUNTRY);
- LookupKey usCaKey = usCaMtvKey.getKeyForUpperLevelField(
- AddressField.ADMIN_AREA);
- assertNotNull("key should be data/US/CA", usCaKey);
- assertNotNull("key should be data/US/CA/Mt View", usCaMtvKey);
- assertNotNull(clientData.get(usKey.toString()));
- assertNotNull(clientData.get(usCaKey.toString()));
- assertNull(clientData.get(usCaMtvKey.toString()));
- finishTest();
- }
- });
- }
-
- public void testRequestDataForBadAddress() {
- final AddressData address = new AddressData.Builder(US_CA_ADDRESS)
- .setAdminArea("FOOBAR")
- .setLocality("KarKar")
- .build();
-
- final FormController controller = new FormController(clientData, "en", "US");
-
- delayTestFinish(15000);
-
- controller.requestDataForAddress(address, new DataLoadListener() {
- boolean beginCalled = false;
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called before dataLoadingEnd",
- beginCalled);
- LookupKey badKey = new LookupKey.Builder(KeyType.DATA)
- .setAddressData(address).build();
- LookupKey usKey = badKey.getKeyForUpperLevelField(AddressField.COUNTRY);
-
- List<RegionData> rdata = controller.getRegionData(usKey);
- assertTrue(rdata.size() > 0);
- String subkey = rdata.get(0).getKey();
- assertNotNull("Should be the first US state", subkey);
- LookupKey usFirstStateKey =
- new LookupKey.Builder(usKey.toString() + "/" + subkey).build();
-
- assertNotNull(clientData.get(usKey.toString()));
- assertNotNull(clientData.get(usFirstStateKey.toString()));
- assertNull(clientData.get(badKey.toString()));
- finishTest();
- }
- });
- }
-
- public void testRequestDataForCountry() {
- final FormController controller = new FormController(clientData, "en", "US");
-
- delayTestFinish(15000);
-
- controller.requestDataForAddress(US_ADDRESS, new DataLoadListener() {
- boolean beginCalled = false;
- @Override
- public void dataLoadingBegin() {
- beginCalled = true;
- }
-
- @Override
- public void dataLoadingEnd() {
- assertTrue("dataLoadingBegin should be called before dataLoadingEnd",
- beginCalled);
- LookupKey usKey = new LookupKey.Builder(KeyType.DATA)
- .setAddressData(US_ADDRESS).build();
- assertNotNull("key should be data/US", usKey);
- List<RegionData> rdata = controller.getRegionData(usKey);
- assertTrue(rdata.size() > 0);
- String subkey = rdata.get(0).getKey();
- assertNotNull("Should be the first US state", subkey);
- LookupKey usFirstStateKey =
- new LookupKey.Builder(usKey.toString() + "/" + subkey).build();
- assertNotNull(clientData.get(usKey.toString()));
- assertNotNull(clientData.get(usFirstStateKey.toString()));
- finishTest();
- }
- });
- }
+ private static final AddressData US_CA_ADDRESS;
+ private static final AddressData US_ADDRESS;
+ private ClientData clientData;
+
+ static {
+ US_CA_ADDRESS = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mt View")
+ .setAddressLine1("1098 Alta Ave")
+ .setPostalCode("94043")
+ .build();
+ US_ADDRESS = new AddressData.Builder().setCountry("US").build();
+ }
+
+ @Override
+ public void setUp() {
+ clientData = new ClientData(new CacheData());
+ }
+
+ public void testRequestDataForAddress() {
+ final FormController controller = new FormController(clientData, "en", "US");
+
+ delayTestFinish(15000);
+
+ controller.requestDataForAddress(US_CA_ADDRESS, new DataLoadListener() {
+ boolean beginCalled = false;
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called before dataLoadingEnd",
+ beginCalled);
+ LookupKey usCaMtvKey = new LookupKey.Builder(KeyType.DATA)
+ .setAddressData(US_CA_ADDRESS).build();
+ LookupKey usKey = usCaMtvKey.getKeyForUpperLevelField(
+ AddressField.COUNTRY);
+ LookupKey usCaKey = usCaMtvKey.getKeyForUpperLevelField(
+ AddressField.ADMIN_AREA);
+ assertNotNull("key should be data/US/CA", usCaKey);
+ assertNotNull("key should be data/US/CA/Mt View", usCaMtvKey);
+ assertNotNull(clientData.get(usKey.toString()));
+ assertNotNull(clientData.get(usCaKey.toString()));
+ assertNull(clientData.get(usCaMtvKey.toString()));
+ finishTest();
+ }
+ });
+ }
+
+ public void testRequestDataForBadAddress() {
+ final AddressData address = new AddressData.Builder(US_CA_ADDRESS)
+ .setAdminArea("FOOBAR")
+ .setLocality("KarKar")
+ .build();
+
+ final FormController controller = new FormController(clientData, "en", "US");
+
+ delayTestFinish(15000);
+
+ controller.requestDataForAddress(address, new DataLoadListener() {
+ boolean beginCalled = false;
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called before dataLoadingEnd",
+ beginCalled);
+ LookupKey badKey = new LookupKey.Builder(KeyType.DATA)
+ .setAddressData(address).build();
+ LookupKey usKey = badKey.getKeyForUpperLevelField(AddressField.COUNTRY);
+
+ List<RegionData> rdata = controller.getRegionData(usKey);
+ assertTrue(rdata.size() > 0);
+ String subkey = rdata.get(0).getKey();
+ assertNotNull("Should be the first US state", subkey);
+ LookupKey usFirstStateKey =
+ new LookupKey.Builder(usKey.toString() + "/" + subkey).build();
+
+ assertNotNull(clientData.get(usKey.toString()));
+ assertNotNull(clientData.get(usFirstStateKey.toString()));
+ assertNull(clientData.get(badKey.toString()));
+ finishTest();
+ }
+ });
+ }
+
+ public void testRequestDataForCountry() {
+ final FormController controller = new FormController(clientData, "en", "US");
+
+ delayTestFinish(15000);
+
+ controller.requestDataForAddress(US_ADDRESS, new DataLoadListener() {
+ boolean beginCalled = false;
+ @Override
+ public void dataLoadingBegin() {
+ beginCalled = true;
+ }
+
+ @Override
+ public void dataLoadingEnd() {
+ assertTrue("dataLoadingBegin should be called before dataLoadingEnd",
+ beginCalled);
+ LookupKey usKey = new LookupKey.Builder(KeyType.DATA)
+ .setAddressData(US_ADDRESS).build();
+ assertNotNull("key should be data/US", usKey);
+ List<RegionData> rdata = controller.getRegionData(usKey);
+ assertTrue(rdata.size() > 0);
+ String subkey = rdata.get(0).getKey();
+ assertNotNull("Should be the first US state", subkey);
+ LookupKey usFirstStateKey =
+ new LookupKey.Builder(usKey.toString() + "/" + subkey).build();
+ assertNotNull(clientData.get(usKey.toString()));
+ assertNotNull(clientData.get(usFirstStateKey.toString()));
+ finishTest();
+ }
+ });
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/FormOptionsTest.java b/java/test/com/android/i18n/addressinput/FormOptionsTest.java
index 5f8e8c3..5e4fc6e 100644
--- a/java/test/com/android/i18n/addressinput/FormOptionsTest.java
+++ b/java/test/com/android/i18n/addressinput/FormOptionsTest.java
@@ -22,23 +22,23 @@ import junit.framework.TestCase;
* Test for building form options.
*/
public class FormOptionsTest extends TestCase {
- public void testRequiredField() throws Exception {
- FormOptions options = new FormOptions.Builder().required(AddressField.COUNTRY).build();
- assertTrue(options.isRequired(AddressField.COUNTRY));
- assertFalse(options.isRequired(AddressField.LOCALITY));
- assertTrue(options.getRequiredFields().contains(AddressField.COUNTRY));
- assertFalse(options.getRequiredFields().contains(AddressField.LOCALITY));
- }
+ public void testRequiredField() throws Exception {
+ FormOptions options = new FormOptions.Builder().required(AddressField.COUNTRY).build();
+ assertTrue(options.isRequired(AddressField.COUNTRY));
+ assertFalse(options.isRequired(AddressField.LOCALITY));
+ assertTrue(options.getRequiredFields().contains(AddressField.COUNTRY));
+ assertFalse(options.getRequiredFields().contains(AddressField.LOCALITY));
+ }
- public void testReadonlyField() throws Exception {
- FormOptions options = new FormOptions.Builder().readonly(AddressField.COUNTRY).build();
- assertTrue(options.isReadonly(AddressField.COUNTRY));
- assertFalse(options.isReadonly(AddressField.LOCALITY));
- }
+ public void testReadonlyField() throws Exception {
+ FormOptions options = new FormOptions.Builder().readonly(AddressField.COUNTRY).build();
+ assertTrue(options.isReadonly(AddressField.COUNTRY));
+ assertFalse(options.isReadonly(AddressField.LOCALITY));
+ }
- public void testHiddenField() throws Exception {
- FormOptions options = new FormOptions.Builder().hide(AddressField.COUNTRY).build();
- assertTrue(options.isHidden(AddressField.COUNTRY));
- assertFalse(options.isHidden(AddressField.LOCALITY));
- }
+ public void testHiddenField() throws Exception {
+ FormOptions options = new FormOptions.Builder().hide(AddressField.COUNTRY).build();
+ assertTrue(options.isHidden(AddressField.COUNTRY));
+ assertFalse(options.isHidden(AddressField.LOCALITY));
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/FormatInterpreterTest.java b/java/test/com/android/i18n/addressinput/FormatInterpreterTest.java
index f5bac79..3efd37b 100644
--- a/java/test/com/android/i18n/addressinput/FormatInterpreterTest.java
+++ b/java/test/com/android/i18n/addressinput/FormatInterpreterTest.java
@@ -27,206 +27,206 @@ import junit.framework.TestCase;
* Tests for the FormatInterpreter class.
*/
public class FormatInterpreterTest extends TestCase {
- private static final AddressData US_CA_ADDRESS;
- private static final AddressData TW_ADDRESS;
-
- private FormatInterpreter formatInterpreter;
-
- static {
- US_CA_ADDRESS = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mt View")
- .setAddressLine1("1098 Alta Ave")
- .setPostalCode("94043")
- .build();
-
- TW_ADDRESS = new AddressData.Builder().setCountry("TW")
- .setAdminArea("\u53F0\u5317\u5E02") // Taipei city
- .setLocality("\u5927\u5B89\u5340") // Da-an district
- .setAddressLine1("Sec. 3 Hsin-yi Rd.")
- .setPostalCode("106")
- .setOrganization("Giant Bike Store")
- .setRecipient("Mr. Liu")
- .build();
- }
+ private static final AddressData US_CA_ADDRESS;
+ private static final AddressData TW_ADDRESS;
+
+ private FormatInterpreter formatInterpreter;
+
+ static {
+ US_CA_ADDRESS = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mt View")
+ .setAddressLine1("1098 Alta Ave")
+ .setPostalCode("94043")
+ .build();
+
+ TW_ADDRESS = new AddressData.Builder().setCountry("TW")
+ .setAdminArea("\u53F0\u5317\u5E02") // Taipei city
+ .setLocality("\u5927\u5B89\u5340") // Da-an district
+ .setAddressLine1("Sec. 3 Hsin-yi Rd.")
+ .setPostalCode("106")
+ .setOrganization("Giant Bike Store")
+ .setRecipient("Mr. Liu")
+ .build();
+ }
- @Override
- public void setUp() {
- formatInterpreter = new FormatInterpreter(new FormOptions.Builder().build());
- }
+ @Override
+ public void setUp() {
+ formatInterpreter = new FormatInterpreter(new FormOptions.Builder().build());
+ }
- public void testIterateUsAddressFields() {
- AddressField[] format = {
- AddressField.RECIPIENT,
- AddressField.ORGANIZATION,
- AddressField.ADDRESS_LINE_1,
- AddressField.ADDRESS_LINE_2,
- AddressField.LOCALITY,
- AddressField.ADMIN_AREA,
- AddressField.POSTAL_CODE
- };
-
- int currIndex = 0;
- for (AddressField field : formatInterpreter.getAddressFieldOrder(ScriptType.LOCAL, "US")) {
- assertEquals("index " + currIndex + " should have matched",
- format[currIndex].getChar(), field.getChar());
- currIndex++;
- }
+ public void testIterateUsAddressFields() {
+ AddressField[] format = {
+ AddressField.RECIPIENT,
+ AddressField.ORGANIZATION,
+ AddressField.ADDRESS_LINE_1,
+ AddressField.ADDRESS_LINE_2,
+ AddressField.LOCALITY,
+ AddressField.ADMIN_AREA,
+ AddressField.POSTAL_CODE
+ };
+
+ int currIndex = 0;
+ for (AddressField field : formatInterpreter.getAddressFieldOrder(ScriptType.LOCAL, "US")) {
+ assertEquals("index " + currIndex + " should have matched",
+ format[currIndex].getChar(), field.getChar());
+ currIndex++;
}
+ }
- /**
- * Tests that this works for the case of Vanuatu, since we have no country-specific formatting
- * data for that country. Should fall back to the default region.
- */
- public void testIterateVuAddressFields() {
- AddressField[] format = {
- AddressField.RECIPIENT,
- AddressField.ORGANIZATION,
- AddressField.ADDRESS_LINE_1,
- AddressField.ADDRESS_LINE_2,
- AddressField.LOCALITY,
- };
-
- int currIndex = 0;
- for (AddressField field : formatInterpreter.getAddressFieldOrder(ScriptType.LOCAL, "VU")) {
- assertEquals("index " + currIndex + " should have matched",
- format[currIndex].getChar(), field.getChar());
- currIndex++;
- }
+ /**
+ * Tests that this works for the case of Vanuatu, since we have no country-specific formatting
+ * data for that country. Should fall back to the default region.
+ */
+ public void testIterateVuAddressFields() {
+ AddressField[] format = {
+ AddressField.RECIPIENT,
+ AddressField.ORGANIZATION,
+ AddressField.ADDRESS_LINE_1,
+ AddressField.ADDRESS_LINE_2,
+ AddressField.LOCALITY,
+ };
+
+ int currIndex = 0;
+ for (AddressField field : formatInterpreter.getAddressFieldOrder(ScriptType.LOCAL, "VU")) {
+ assertEquals("index " + currIndex + " should have matched",
+ format[currIndex].getChar(), field.getChar());
+ currIndex++;
}
+ }
- public void testOverrideFieldOrder() {
- AddressField[] expectedOrder = {
- AddressField.ADMIN_AREA,
- AddressField.ORGANIZATION,
- AddressField.ADDRESS_LINE_1,
- AddressField.ADDRESS_LINE_2,
- AddressField.LOCALITY,
- AddressField.RECIPIENT,
- AddressField.POSTAL_CODE
- };
-
- FormatInterpreter myInterpreter = new FormatInterpreter(
- new FormOptions.Builder().customizeFieldOrder("US",
- AddressField.ADMIN_AREA,
- AddressField.RECIPIENT,
- AddressField.SORTING_CODE,
- AddressField.POSTAL_CODE).build());
-
- int currIndex = 0;
- for (AddressField field : myInterpreter.getAddressFieldOrder(ScriptType.LOCAL, "US")) {
- assertEquals("Wrong field order for US on index " + currIndex + " of address fields.",
- expectedOrder[currIndex], field);
-
- // Sorting code (CEDEX) is not in US address format and should be
- // neglected even if it is specified in customizeFieldOrder().
- assertNotSame(AddressField.SORTING_CODE, field);
- currIndex++;
- }
+ public void testOverrideFieldOrder() {
+ AddressField[] expectedOrder = {
+ AddressField.ADMIN_AREA,
+ AddressField.ORGANIZATION,
+ AddressField.ADDRESS_LINE_1,
+ AddressField.ADDRESS_LINE_2,
+ AddressField.LOCALITY,
+ AddressField.RECIPIENT,
+ AddressField.POSTAL_CODE
+ };
+
+ FormatInterpreter myInterpreter = new FormatInterpreter(
+ new FormOptions.Builder().customizeFieldOrder("US",
+ AddressField.ADMIN_AREA,
+ AddressField.RECIPIENT,
+ AddressField.SORTING_CODE,
+ AddressField.POSTAL_CODE).build());
+
+ int currIndex = 0;
+ for (AddressField field : myInterpreter.getAddressFieldOrder(ScriptType.LOCAL, "US")) {
+ assertEquals("Wrong field order for US on index " + currIndex + " of address fields.",
+ expectedOrder[currIndex], field);
+
+ // Sorting code (CEDEX) is not in US address format and should be
+ // neglected even if it is specified in customizeFieldOrder().
+ assertNotSame(AddressField.SORTING_CODE, field);
+ currIndex++;
}
+ }
- public void testIterateTwLatinAddressFields() {
- AddressField[] format = {
- AddressField.RECIPIENT,
- AddressField.ORGANIZATION,
- AddressField.ADDRESS_LINE_1,
- AddressField.ADDRESS_LINE_2,
- AddressField.LOCALITY,
- AddressField.ADMIN_AREA,
- AddressField.POSTAL_CODE
- };
-
- int currIndex = 0;
- for (AddressField field : formatInterpreter.getAddressFieldOrder(ScriptType.LATIN, "TW")) {
- assertEquals("Unexpected field order -- mismatched on index " + currIndex,
- format[currIndex].getChar(), field.getChar());
- currIndex++;
- }
+ public void testIterateTwLatinAddressFields() {
+ AddressField[] format = {
+ AddressField.RECIPIENT,
+ AddressField.ORGANIZATION,
+ AddressField.ADDRESS_LINE_1,
+ AddressField.ADDRESS_LINE_2,
+ AddressField.LOCALITY,
+ AddressField.ADMIN_AREA,
+ AddressField.POSTAL_CODE
+ };
+
+ int currIndex = 0;
+ for (AddressField field : formatInterpreter.getAddressFieldOrder(ScriptType.LATIN, "TW")) {
+ assertEquals("Unexpected field order -- mismatched on index " + currIndex,
+ format[currIndex].getChar(), field.getChar());
+ currIndex++;
}
+ }
- public void testUsEnvelopeAddress() {
- List<String> expected = new ArrayList<String>();
- expected.add("1098 Alta Ave");
- expected.add("Mt View, CA 94043");
+ public void testUsEnvelopeAddress() {
+ List<String> expected = new ArrayList<String>();
+ expected.add("1098 Alta Ave");
+ expected.add("Mt View, CA 94043");
- List<String> real = formatInterpreter.getEnvelopeAddress(US_CA_ADDRESS);
+ List<String> real = formatInterpreter.getEnvelopeAddress(US_CA_ADDRESS);
- assertEquals(expected, real);
- }
+ assertEquals(expected, real);
+ }
- public void testTwEnvelopeAddress() {
- // To be in this order, the whole address should really be in Traditional Chinese - for
- // readability, only the neighbourhood and city are.
- List<String> expected = new ArrayList<String>();
- expected.add("106");
- expected.add("\u53F0\u5317\u5E02\u5927\u5B89\u5340"); // Taipei city, Da-an district
- expected.add("Sec. 3 Hsin-yi Rd.");
- expected.add("Giant Bike Store");
- expected.add("Mr. Liu");
+ public void testTwEnvelopeAddress() {
+ // To be in this order, the whole address should really be in Traditional Chinese - for
+ // readability, only the neighbourhood and city are.
+ List<String> expected = new ArrayList<String>();
+ expected.add("106");
+ expected.add("\u53F0\u5317\u5E02\u5927\u5B89\u5340"); // Taipei city, Da-an district
+ expected.add("Sec. 3 Hsin-yi Rd.");
+ expected.add("Giant Bike Store");
+ expected.add("Mr. Liu");
- List<String> real = formatInterpreter.getEnvelopeAddress(TW_ADDRESS);
+ List<String> real = formatInterpreter.getEnvelopeAddress(TW_ADDRESS);
- assertEquals(expected, real);
- }
+ assertEquals(expected, real);
+ }
- public void testEnvelopeAddressIncompleteAddress() {
- List<String> expected = new ArrayList<String>();
- expected.add("1098 Alta Ave");
- expected.add("CA 94043");
+ public void testEnvelopeAddressIncompleteAddress() {
+ List<String> expected = new ArrayList<String>();
+ expected.add("1098 Alta Ave");
+ expected.add("CA 94043");
- AddressData address = new AddressData.Builder().set(US_CA_ADDRESS)
- .set(AddressField.LOCALITY, null).build();
+ AddressData address = new AddressData.Builder().set(US_CA_ADDRESS)
+ .set(AddressField.LOCALITY, null).build();
- List<String> real = formatInterpreter.getEnvelopeAddress(address);
+ List<String> real = formatInterpreter.getEnvelopeAddress(address);
- assertEquals(expected, real);
- }
+ assertEquals(expected, real);
+ }
- public void testEnvelopeAddressEmptyAddress() {
- List<String> expected = new ArrayList<String>();
- AddressData address = new AddressData.Builder().setCountry("US").build();
+ public void testEnvelopeAddressEmptyAddress() {
+ List<String> expected = new ArrayList<String>();
+ AddressData address = new AddressData.Builder().setCountry("US").build();
- List<String> real = formatInterpreter.getEnvelopeAddress(address);
- assertEquals(expected, real);
- }
+ List<String> real = formatInterpreter.getEnvelopeAddress(address);
+ assertEquals(expected, real);
+ }
public void testEnvelopeAddressLeadingPostPrefix() {
- List<String> expected = new ArrayList<String>();
- expected.add("CH-8047 Herrliberg");
- AddressData address = new AddressData.Builder().setCountry("CH")
- .setPostalCode("8047")
- .setLocality("Herrliberg")
- .build();
-
- List<String> real = formatInterpreter.getEnvelopeAddress(address);
- assertEquals(expected, real);
+ List<String> expected = new ArrayList<String>();
+ expected.add("CH-8047 Herrliberg");
+ AddressData address = new AddressData.Builder().setCountry("CH")
+ .setPostalCode("8047")
+ .setLocality("Herrliberg")
+ .build();
+
+ List<String> real = formatInterpreter.getEnvelopeAddress(address);
+ assertEquals(expected, real);
}
public void testSvAddress() {
- final AddressData svAddress = new AddressData.Builder().setCountry("SV")
- .setAdminArea("Ahuachapán")
- .setLocality("Ahuachapán")
- .setAddressLine1("Some Street 12")
- .build();
-
- List<String> expected = new ArrayList<String>();
- expected.add("Some Street 12");
- expected.add("Ahuachapán");
- expected.add("Ahuachapán");
-
- List<String> real = formatInterpreter.getEnvelopeAddress(svAddress);
- assertEquals(expected, real);
-
- final AddressData svAddressWithPostCode = new AddressData.Builder(svAddress)
- .setPostalCode("CP 2101")
- .build();
-
- expected = new ArrayList<String>();
- expected.add("Some Street 12");
- expected.add("CP 2101-Ahuachapán");
- expected.add("Ahuachapán");
-
- real = formatInterpreter.getEnvelopeAddress(svAddressWithPostCode);
- assertEquals(expected, real);
+ final AddressData svAddress = new AddressData.Builder().setCountry("SV")
+ .setAdminArea("Ahuachapán")
+ .setLocality("Ahuachapán")
+ .setAddressLine1("Some Street 12")
+ .build();
+
+ List<String> expected = new ArrayList<String>();
+ expected.add("Some Street 12");
+ expected.add("Ahuachapán");
+ expected.add("Ahuachapán");
+
+ List<String> real = formatInterpreter.getEnvelopeAddress(svAddress);
+ assertEquals(expected, real);
+
+ final AddressData svAddressWithPostCode = new AddressData.Builder(svAddress)
+ .setPostalCode("CP 2101")
+ .build();
+
+ expected = new ArrayList<String>();
+ expected.add("Some Street 12");
+ expected.add("CP 2101-Ahuachapán");
+ expected.add("Ahuachapán");
+
+ real = formatInterpreter.getEnvelopeAddress(svAddressWithPostCode);
+ assertEquals(expected, real);
}
}
diff --git a/java/test/com/android/i18n/addressinput/JsoMapTest.java b/java/test/com/android/i18n/addressinput/JsoMapTest.java
index 76bcbed..56e4d1e 100644
--- a/java/test/com/android/i18n/addressinput/JsoMapTest.java
+++ b/java/test/com/android/i18n/addressinput/JsoMapTest.java
@@ -30,218 +30,218 @@ import java.util.Set;
*/
public class JsoMapTest extends TestCase {
- private static final String VALID_JSON = "{\"a\":\"b\",\"c\":1,\"d\":{\"e\":\"f\"}}";
- private static final String INVALID_JSON = "!";
-
- public void testBuildJsoMap() throws Exception {
- assertNotNull(JsoMap.buildJsoMap(VALID_JSON));
-
- try {
- JsoMap.buildJsoMap(INVALID_JSON);
- fail("Expected JSONException.");
- } catch (JSONException e) {
- // Expected.
- }
- }
-
- public void testCreateEmptyJsoMap() throws Exception {
- assertNotNull(JsoMap.createEmptyJsoMap());
- }
+ private static final String VALID_JSON = "{\"a\":\"b\",\"c\":1,\"d\":{\"e\":\"f\"}}";
+ private static final String INVALID_JSON = "!";
- public void testDelKey() throws Exception {
- JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
+ public void testBuildJsoMap() throws Exception {
+ assertNotNull(JsoMap.buildJsoMap(VALID_JSON));
- assertEquals("b", map.get("a"));
- map.delKey("a");
- assertNull(map.get("a"));
-
- map.delKey("b");
- map.delKey("c");
- map.delKey("d");
+ try {
+ JsoMap.buildJsoMap(INVALID_JSON);
+ fail("Expected JSONException.");
+ } catch (JSONException e) {
+ // Expected.
}
-
- public void testGet() throws Exception {
- JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
- assertEquals("b", map.get("a"));
- assertNull(map.get("b"));
-
- try {
- map.get("c");
- fail("Expected IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- try {
- map.get("d");
- fail("Expected ClassCastException.");
- } catch (ClassCastException e) {
- // Expected.
- }
+ }
+
+ public void testCreateEmptyJsoMap() throws Exception {
+ assertNotNull(JsoMap.createEmptyJsoMap());
+ }
+
+ public void testDelKey() throws Exception {
+ JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
+
+ assertEquals("b", map.get("a"));
+ map.delKey("a");
+ assertNull(map.get("a"));
+
+ map.delKey("b");
+ map.delKey("c");
+ map.delKey("d");
+ }
+
+ public void testGet() throws Exception {
+ JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
+ assertEquals("b", map.get("a"));
+ assertNull(map.get("b"));
+
+ try {
+ map.get("c");
+ fail("Expected IllegalArgumentException.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
}
- public void testGetInt() throws Exception {
- JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
-
- try {
- map.getInt("a");
- fail("Expected RuntimeException.");
- } catch (RuntimeException e) {
- // Expected.
- }
-
- assertEquals(-1, map.getInt("b"));
- assertEquals(1, map.getInt("c"));
-
- try {
- map.getInt("d");
- fail("Expected RuntimeException.");
- } catch (RuntimeException e) {
- // Expected.
- }
+ try {
+ map.get("d");
+ fail("Expected ClassCastException.");
+ } catch (ClassCastException e) {
+ // Expected.
}
+ }
- public void testGetKeys() throws Exception {
- JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
- JSONArray keys = map.getKeys();
- assertNotNull(keys);
- assertEquals(3, keys.length());
- Set<String> keySet = new HashSet<String>(keys.length());
- for (int i = 0; i < keys.length(); i++) {
- keySet.add(keys.getString(i));
- }
- assertEquals(new HashSet<String>(Arrays.asList("a", "c", "d")), keySet);
- }
-
- public void testGetObj() throws Exception {
- JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
+ public void testGetInt() throws Exception {
+ JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
- try {
- map.getObj("a");
- fail("Expected ClassCastException.");
- } catch (ClassCastException e) {
- // Expected.
- }
-
- assertNull(map.getObj("b"));
+ try {
+ map.getInt("a");
+ fail("Expected RuntimeException.");
+ } catch (RuntimeException e) {
+ // Expected.
+ }
- try {
- map.getObj("c");
- fail("Expected IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
+ assertEquals(-1, map.getInt("b"));
+ assertEquals(1, map.getInt("c"));
- JsoMap obj = map.getObj("d");
- assertNotNull(obj);
- assertEquals("f", obj.get("e"));
+ try {
+ map.getInt("d");
+ fail("Expected RuntimeException.");
+ } catch (RuntimeException e) {
+ // Expected.
}
-
- public void testContainsKey() throws Exception {
- JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
- assertTrue(map.containsKey("a"));
- assertFalse(map.containsKey("b"));
- assertTrue(map.containsKey("c"));
- assertTrue(map.containsKey("d"));
+ }
+
+ public void testGetKeys() throws Exception {
+ JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
+ JSONArray keys = map.getKeys();
+ assertNotNull(keys);
+ assertEquals(3, keys.length());
+ Set<String> keySet = new HashSet<String>(keys.length());
+ for (int i = 0; i < keys.length(); i++) {
+ keySet.add(keys.getString(i));
}
+ assertEquals(new HashSet<String>(Arrays.asList("a", "c", "d")), keySet);
+ }
- public void testMergeData() throws Exception {
- JsoMap mapA = JsoMap.createEmptyJsoMap();
- JsoMap mapB = JsoMap.createEmptyJsoMap();
-
- mapA.putInt("a", 1);
- mapA.putInt("b", 2);
-
- mapB.putInt("b", 3);
- mapB.putInt("c", 4);
+ public void testGetObj() throws Exception {
+ JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
- mapA.mergeData(mapB);
- assertEquals(1, mapA.getInt("a"));
- assertEquals(2, mapA.getInt("b"));
- assertEquals(4, mapA.getInt("c"));
+ try {
+ map.getObj("a");
+ fail("Expected ClassCastException.");
+ } catch (ClassCastException e) {
+ // Expected.
}
- public void testPut() throws Exception {
- JsoMap map = JsoMap.createEmptyJsoMap();
+ assertNull(map.getObj("b"));
- map.put("a", "b");
- assertEquals("b", map.get("a"));
-
- map.put("a", "c");
- assertEquals("c", map.get("a"));
+ try {
+ map.getObj("c");
+ fail("Expected IllegalArgumentException.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
}
- public void testPutInt() throws Exception {
- JsoMap map = JsoMap.createEmptyJsoMap();
-
- map.putInt("a", 1);
- assertEquals(1, map.getInt("a"));
-
- map.putInt("a", 2);
- assertEquals(2, map.getInt("a"));
+ JsoMap obj = map.getObj("d");
+ assertNotNull(obj);
+ assertEquals("f", obj.get("e"));
+ }
+
+ public void testContainsKey() throws Exception {
+ JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
+ assertTrue(map.containsKey("a"));
+ assertFalse(map.containsKey("b"));
+ assertTrue(map.containsKey("c"));
+ assertTrue(map.containsKey("d"));
+ }
+
+ public void testMergeData() throws Exception {
+ JsoMap mapA = JsoMap.createEmptyJsoMap();
+ JsoMap mapB = JsoMap.createEmptyJsoMap();
+
+ mapA.putInt("a", 1);
+ mapA.putInt("b", 2);
+
+ mapB.putInt("b", 3);
+ mapB.putInt("c", 4);
+
+ mapA.mergeData(mapB);
+ assertEquals(1, mapA.getInt("a"));
+ assertEquals(2, mapA.getInt("b"));
+ assertEquals(4, mapA.getInt("c"));
+ }
+
+ public void testPut() throws Exception {
+ JsoMap map = JsoMap.createEmptyJsoMap();
+
+ map.put("a", "b");
+ assertEquals("b", map.get("a"));
+
+ map.put("a", "c");
+ assertEquals("c", map.get("a"));
+ }
+
+ public void testPutInt() throws Exception {
+ JsoMap map = JsoMap.createEmptyJsoMap();
+
+ map.putInt("a", 1);
+ assertEquals(1, map.getInt("a"));
+
+ map.putInt("a", 2);
+ assertEquals(2, map.getInt("a"));
+ }
+
+ public void testPutObj() throws Exception {
+ JsoMap map = JsoMap.createEmptyJsoMap();
+ JsoMap obj = JsoMap.createEmptyJsoMap();
+
+ obj.putInt("a", 1);
+ map.putObj("b", obj);
+ assertEquals(obj.toString(), map.getObj("b").toString());
+
+ obj.putInt("a", 2);
+ map.putObj("b", obj);
+ assertEquals(obj.toString(), map.getObj("b").toString());
+ }
+
+ public void testString() throws Exception {
+ JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
+
+ try {
+ // This should fail on the integer "c" or the map "d".
+ map.string();
+ fail("Expected IllegalArgumentException.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ } catch (ClassCastException e) {
+ // Expected.
}
- public void testPutObj() throws Exception {
- JsoMap map = JsoMap.createEmptyJsoMap();
- JsoMap obj = JsoMap.createEmptyJsoMap();
-
- obj.putInt("a", 1);
- map.putObj("b", obj);
- assertEquals(obj.toString(), map.getObj("b").toString());
-
- obj.putInt("a", 2);
- map.putObj("b", obj);
- assertEquals(obj.toString(), map.getObj("b").toString());
+ map.delKey("c");
+ try {
+ // This should fail on the object "d".
+ map.string();
+ fail("Expected ClassCastException.");
+ } catch (ClassCastException e) {
+ // Expected.
}
- public void testString() throws Exception {
- JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
-
- try {
- // This should fail on the integer "c" or the map "d".
- map.string();
- fail("Expected IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // Expected.
- } catch (ClassCastException e) {
- // Expected.
- }
-
- map.delKey("c");
- try {
- // This should fail on the object "d".
- map.string();
- fail("Expected ClassCastException.");
- } catch (ClassCastException e) {
- // Expected.
- }
-
- map.delKey("d");
- assertEquals("JsoMap[\n(a:b)\n]", map.string());
+ map.delKey("d");
+ assertEquals("JsoMap[\n(a:b)\n]", map.string());
+ }
+
+ public void testMap() throws Exception {
+ JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
+ try {
+ // This should fail on the string "a" or the integer "c".
+ map.map();
+ fail("Expected ClassCastException.");
+ } catch (ClassCastException e) {
+ // Expected.
+ } catch (IllegalArgumentException e) {
+ // Expected.
}
- public void testMap() throws Exception {
- JsoMap map = JsoMap.buildJsoMap(VALID_JSON);
- try {
- // This should fail on the string "a" or the integer "c".
- map.map();
- fail("Expected ClassCastException.");
- } catch (ClassCastException e) {
- // Expected.
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- map.delKey("a");
- try {
- // This should fail on the integer "c".
- map.map();
- fail("Expected IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- map.delKey("c");
- assertEquals("JsoMap[\n(d:JsoMap[\n(e:f)\n])\n]", map.map());
+ map.delKey("a");
+ try {
+ // This should fail on the integer "c".
+ map.map();
+ fail("Expected IllegalArgumentException.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
}
+
+ map.delKey("c");
+ assertEquals("JsoMap[\n(d:JsoMap[\n(e:f)\n])\n]", map.map());
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java b/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java
index 392a68e..9a40d1a 100644
--- a/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java
+++ b/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java
@@ -27,131 +27,131 @@ import java.net.Socket;
import java.net.SocketTimeoutException;
public class JsonpRequestBuilderTest extends AsyncTestCase {
- private JsonpRequestBuilder builder;
-
- @Override
- public void setUp() {
- builder = new JsonpRequestBuilder();
- }
-
- public void testRequestObject() throws Exception {
- delayTestFinish(4000);
- builder.setTimeout(2000);
-
- String url = HttpServer.execute(1000, "{\"id\": \"data\"}");
-
- builder.requestObject(url, new AsyncCallback<JsoMap>() {
- @Override
- public void onFailure(Throwable caught) {
- fail(caught.toString());
- }
-
- @Override
- public void onSuccess(JsoMap result) {
- assertNotNull(result);
- assertEquals("data", result.get("id"));
- finishTest();
- }
- });
- }
-
- public void testSetTimeout() throws Exception {
- delayTestFinish(4000);
- builder.setTimeout(1000);
-
- String url = HttpServer.execute(2000, "Fubar");
-
- builder.requestObject(url, new AsyncCallback<JsoMap>() {
- @Override
- public void onFailure(Throwable caught) {
- assertNotNull(caught);
- assertTrue(caught instanceof SocketTimeoutException);
- finishTest();
- }
-
- @Override
- public void onSuccess(JsoMap result) {
- fail("The request should have timed out.");
- }
- });
- }
-
- public void testUrlEncoding() throws Exception {
- delayTestFinish(4000);
- builder.setTimeout(2000);
-
- String urlBase = HttpServer.execute(1000, "{\"id\": \"data\"}");
- String url = urlBase + "address/data/VN/B\u1EAFc K\u1EA1n";
-
- builder.requestObject(url, new AsyncCallback<JsoMap>() {
- @Override
- public void onFailure(Throwable caught) {
- fail(caught.toString());
- }
-
- @Override
- public void onSuccess(JsoMap result) {
- assertNotNull(result);
- assertEquals("data", result.get("id"));
- finishTest();
- }
- });
- }
-
+ private JsonpRequestBuilder builder;
+
+ @Override
+ public void setUp() {
+ builder = new JsonpRequestBuilder();
+ }
+
+ public void testRequestObject() throws Exception {
+ delayTestFinish(4000);
+ builder.setTimeout(2000);
+
+ String url = HttpServer.execute(1000, "{\"id\": \"data\"}");
+
+ builder.requestObject(url, new AsyncCallback<JsoMap>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ fail(caught.toString());
+ }
+
+ @Override
+ public void onSuccess(JsoMap result) {
+ assertNotNull(result);
+ assertEquals("data", result.get("id"));
+ finishTest();
+ }
+ });
+ }
+
+ public void testSetTimeout() throws Exception {
+ delayTestFinish(4000);
+ builder.setTimeout(1000);
+
+ String url = HttpServer.execute(2000, "Fubar");
+
+ builder.requestObject(url, new AsyncCallback<JsoMap>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ assertNotNull(caught);
+ assertTrue(caught instanceof SocketTimeoutException);
+ finishTest();
+ }
+
+ @Override
+ public void onSuccess(JsoMap result) {
+ fail("The request should have timed out.");
+ }
+ });
+ }
+
+ public void testUrlEncoding() throws Exception {
+ delayTestFinish(4000);
+ builder.setTimeout(2000);
+
+ String urlBase = HttpServer.execute(1000, "{\"id\": \"data\"}");
+ String url = urlBase + "address/data/VN/B\u1EAFc K\u1EA1n";
+
+ builder.requestObject(url, new AsyncCallback<JsoMap>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ fail(caught.toString());
+ }
+
+ @Override
+ public void onSuccess(JsoMap result) {
+ assertNotNull(result);
+ assertEquals("data", result.get("id"));
+ finishTest();
+ }
+ });
+ }
+
+ /**
+ * Simple implementation of an HTTP server.
+ */
+ private static class HttpServer extends Thread {
/**
- * Simple implementation of an HTTP server.
+ * Start an HTTP server that will serve one request and then terminate.
+ *
+ * @param timeoutMillis
+ * Wait this long before answering a request.
+ * @param response
+ * Reply to any request with this response.
+ * @return The URL to the server.
+ * @throws IOException
*/
- private static class HttpServer extends Thread {
- /**
- * Start an HTTP server that will serve one request and then terminate.
- *
- * @param timeoutMillis
- * Wait this long before answering a request.
- * @param response
- * Reply to any request with this response.
- * @return The URL to the server.
- * @throws IOException
- */
- public static String execute(long timeoutMillis, String response) throws IOException {
- HttpServer server = new HttpServer(timeoutMillis, response);
- server.start();
- return "http://localhost:" + server.serverSocket.getLocalPort() + "/";
- }
+ public static String execute(long timeoutMillis, String response) throws IOException {
+ HttpServer server = new HttpServer(timeoutMillis, response);
+ server.start();
+ return "http://localhost:" + server.serverSocket.getLocalPort() + "/";
+ }
- @Override
- public void run() {
- try {
- Socket clientSocket = serverSocket.accept();
- try {
- synchronized (this) {
- wait(waitMillis);
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- InputStream inputStream = clientSocket.getInputStream();
- inputStream.read(new byte[1024]); // Discard input.
- OutputStream outputStream = clientSocket.getOutputStream();
- outputStream.write(response);
- outputStream.close();
- inputStream.close();
- clientSocket.close();
- serverSocket.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ @Override
+ public void run() {
+ try {
+ Socket clientSocket = serverSocket.accept();
+ try {
+ synchronized (this) {
+ wait(waitMillis);
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
}
+ InputStream inputStream = clientSocket.getInputStream();
+ inputStream.read(new byte[1024]); // Discard input.
+ OutputStream outputStream = clientSocket.getOutputStream();
+ outputStream.write(response);
+ outputStream.close();
+ inputStream.close();
+ clientSocket.close();
+ serverSocket.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
- private HttpServer(long waitMillis, String response) throws IOException {
- this.waitMillis = waitMillis;
- this.response = (header + response).getBytes();
- serverSocket = new ServerSocket(0);
- }
+ private HttpServer(long waitMillis, String response) throws IOException {
+ this.waitMillis = waitMillis;
+ this.response = (header + response).getBytes();
+ serverSocket = new ServerSocket(0);
+ }
- private long waitMillis;
- private byte[] response;
- private ServerSocket serverSocket;
+ private long waitMillis;
+ private byte[] response;
+ private ServerSocket serverSocket;
- private static final String header = "HTTP/1.0 200 OK\nContent-Type: text/plain\n\n";
- }
+ private static final String header = "HTTP/1.0 200 OK\nContent-Type: text/plain\n\n";
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/LookupKeyTest.java b/java/test/com/android/i18n/addressinput/LookupKeyTest.java
index 608e076..fa07618 100644
--- a/java/test/com/android/i18n/addressinput/LookupKeyTest.java
+++ b/java/test/com/android/i18n/addressinput/LookupKeyTest.java
@@ -27,211 +27,211 @@ import junit.framework.TestCase;
* Unit tests for the LookupKey class.
*/
public class LookupKeyTest extends TestCase {
- private static final String ROOT_KEY = "data";
- private static final String ROOT_EXAMPLE_KEY = "examples";
- private static final String US_KEY = "data/US";
- private static final String CALIFORNIA_KEY = "data/US/CA";
- private static final String EXAMPLE_LOCAL_US_KEY = "examples/US/local/_default";
-
- // Data key for Da-an District, Taipei Taiwan
- private static final String TW_KEY = "data/TW/\u53F0\u5317\u5E02/\u5927\u5B89\u5340";
-
- // Example key for TW's address (local script)
- private static final String TW_EXAMPLE_LOCAL_KEY = "examples/TW/local/_default";
-
- // Example key for TW's address (latin script)
- private static final String TW_EXAMPLE_LATIN_KEY = "examples/TW/latin/_default";
-
- private static final String RANDOM_KEY = "sdfIisooIFOOBAR";
- private static final String RANDOM_COUNTRY_KEY = "data/asIOSDxcowW";
-
- public void testRootKey() {
- LookupKey key = new LookupKey.Builder(KeyType.DATA).build();
- assertEquals(ROOT_KEY, key.toString());
-
- LookupKey key2 = new LookupKey.Builder(key.toString()).build();
- assertEquals(ROOT_KEY, key2.toString());
+ private static final String ROOT_KEY = "data";
+ private static final String ROOT_EXAMPLE_KEY = "examples";
+ private static final String US_KEY = "data/US";
+ private static final String CALIFORNIA_KEY = "data/US/CA";
+ private static final String EXAMPLE_LOCAL_US_KEY = "examples/US/local/_default";
+
+ // Data key for Da-an District, Taipei Taiwan
+ private static final String TW_KEY = "data/TW/\u53F0\u5317\u5E02/\u5927\u5B89\u5340";
+
+ // Example key for TW's address (local script)
+ private static final String TW_EXAMPLE_LOCAL_KEY = "examples/TW/local/_default";
+
+ // Example key for TW's address (latin script)
+ private static final String TW_EXAMPLE_LATIN_KEY = "examples/TW/latin/_default";
+
+ private static final String RANDOM_KEY = "sdfIisooIFOOBAR";
+ private static final String RANDOM_COUNTRY_KEY = "data/asIOSDxcowW";
+
+ public void testRootKey() {
+ LookupKey key = new LookupKey.Builder(KeyType.DATA).build();
+ assertEquals(ROOT_KEY, key.toString());
+
+ LookupKey key2 = new LookupKey.Builder(key.toString()).build();
+ assertEquals(ROOT_KEY, key2.toString());
+ }
+
+ public void testDataKeys() {
+ LookupKey key = new LookupKey.Builder(US_KEY).build();
+ assertEquals(US_KEY, key.toString());
+
+ LookupKey key2 = new LookupKey.Builder(CALIFORNIA_KEY).build();
+ assertEquals(CALIFORNIA_KEY, key2.toString());
+ }
+
+ public void testExampleRootKeys() {
+ LookupKey key = new LookupKey.Builder(KeyType.EXAMPLES).build();
+ assertEquals(ROOT_EXAMPLE_KEY, key.toString());
+ }
+
+ public void testExampleKeys() {
+ AddressData address = new AddressData.Builder().setCountry("US")
+ .setLanguageCode("en")
+ .build();
+
+ LookupKey key = new LookupKey.Builder(KeyType.EXAMPLES).setAddressData(address).build();
+ assertEquals(EXAMPLE_LOCAL_US_KEY, key.toString());
+
+ key = new LookupKey.Builder(EXAMPLE_LOCAL_US_KEY).build();
+ assertEquals(EXAMPLE_LOCAL_US_KEY, key.toString());
+ }
+
+ public void testKeyWithWrongScriptType() {
+ String wrongScript = "examples/US/asdfasdfasdf/_default";
+ try {
+ new LookupKey.Builder(wrongScript).build();
+ fail("should fail since the script type is wrong");
+ } catch (RuntimeException e) {
+ // Expected.
}
-
- public void testDataKeys() {
- LookupKey key = new LookupKey.Builder(US_KEY).build();
- assertEquals(US_KEY, key.toString());
-
- LookupKey key2 = new LookupKey.Builder(CALIFORNIA_KEY).build();
- assertEquals(CALIFORNIA_KEY, key2.toString());
- }
-
- public void testExampleRootKeys() {
- LookupKey key = new LookupKey.Builder(KeyType.EXAMPLES).build();
- assertEquals(ROOT_EXAMPLE_KEY, key.toString());
+ }
+
+ public void testFallbackToCountry() {
+ // Admin Area is missing.
+ AddressData address = new AddressData.Builder().setCountry("US")
+ .setLocality("Mt View")
+ .build();
+
+ LookupKey key = new LookupKey.Builder(KeyType.DATA).setAddressData(address).build();
+
+ assertEquals("locality should be omitted since admin area is not specified", US_KEY,
+ key.toString());
+
+ // Tries key string with the same problem (missing Admin Area).
+ key = new LookupKey.Builder("data/US//Mt View").build();
+
+ assertEquals("locality should be omitted since admin area is not specified", US_KEY,
+ key.toString());
+ }
+
+ public void testNonUsAddress() {
+ AddressData address = new AddressData.Builder().setCountry("TW")
+ // Taipei City
+ .setAdminArea("\u53F0\u5317\u5E02")
+ // Da-an District
+ .setLocality("\u5927\u5B89\u5340")
+ .build();
+
+ LookupKey key = new LookupKey.Builder(KeyType.DATA).setAddressData(address).build();
+ assertEquals(TW_KEY, key.toString());
+
+ key = new LookupKey.Builder(KeyType.EXAMPLES).setAddressData(address).build();
+ assertEquals(TW_EXAMPLE_LOCAL_KEY, key.toString());
+
+ address = new AddressData.Builder(address).setLanguageCode("zh-latn").build();
+ key = new LookupKey.Builder(KeyType.EXAMPLES).setAddressData(address).build();
+ assertEquals(TW_EXAMPLE_LATIN_KEY, key.toString());
+ }
+
+ public void testGetKeyForUpperLevelFieldWithDataKey() {
+ AddressData address = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mt View")
+ .build();
+
+ LookupKey key = new LookupKey.Builder(KeyType.DATA).setAddressData(address).build();
+ LookupKey newKey = key.getKeyForUpperLevelField(AddressField.COUNTRY);
+ assertNotNull("failed to get key for " + AddressField.COUNTRY, newKey);
+ assertEquals("data/US", newKey.toString());
+
+ newKey = key.getKeyForUpperLevelField(AddressField.ADMIN_AREA);
+ assertNotNull("failed to get key for " + AddressField.ADMIN_AREA, newKey);
+ assertEquals("data/US/CA", newKey.toString());
+ assertEquals("original key should not be changed", "data/US/CA/Mt View", key.toString());
+
+ newKey = key.getKeyForUpperLevelField(AddressField.LOCALITY);
+ assertNotNull("failed to get key for " + AddressField.LOCALITY, newKey);
+ assertEquals("data/US/CA/Mt View", newKey.toString());
+
+ newKey = key.getKeyForUpperLevelField(AddressField.DEPENDENT_LOCALITY);
+ assertNull("should return null for field not contained in current key", newKey);
+
+ newKey = key.getKeyForUpperLevelField(AddressField.RECIPIENT);
+ assertNull("should return null since field '" + AddressField.RECIPIENT +
+ "' is not in address hierarchy", newKey);
+ }
+
+ public void testGetKeyForUpperLevelFieldWithExampleKey() {
+ LookupKey key = new LookupKey.Builder("examples/US/latin/_default").build();
+
+ try {
+ key.getKeyForUpperLevelField(AddressField.COUNTRY);
+ fail("should fail if you try to get parent key for an example key.");
+ } catch (RuntimeException e) {
+ // Expected.
}
+ }
- public void testExampleKeys() {
- AddressData address = new AddressData.Builder().setCountry("US")
- .setLanguageCode("en")
- .build();
+ public void testGetParentKey() {
+ AddressData address = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mt View")
+ .setDependentLocality("El Camino")
+ .build();
- LookupKey key = new LookupKey.Builder(KeyType.EXAMPLES).setAddressData(address).build();
- assertEquals(EXAMPLE_LOCAL_US_KEY, key.toString());
+ LookupKey key = new LookupKey.Builder(KeyType.DATA).setAddressData(address).build();
+ assertEquals("data/US/CA/Mt View/El Camino", key.toString());
- key = new LookupKey.Builder(EXAMPLE_LOCAL_US_KEY).build();
- assertEquals(EXAMPLE_LOCAL_US_KEY, key.toString());
- }
+ key = key.getParentKey();
+ assertEquals("data/US/CA/Mt View", key.toString());
- public void testKeyWithWrongScriptType() {
- String wrongScript = "examples/US/asdfasdfasdf/_default";
- try {
- new LookupKey.Builder(wrongScript).build();
- fail("should fail since the script type is wrong");
- } catch (RuntimeException e) {
- // Expected.
- }
- }
+ key = key.getParentKey();
+ assertEquals("data/US/CA", key.toString());
- public void testFallbackToCountry() {
- // Admin Area is missing.
- AddressData address = new AddressData.Builder().setCountry("US")
- .setLocality("Mt View")
- .build();
+ key = key.getParentKey();
+ assertEquals("data/US", key.toString());
- LookupKey key = new LookupKey.Builder(KeyType.DATA).setAddressData(address).build();
+ key = key.getParentKey();
+ assertEquals("data", key.toString());
- assertEquals("locality should be omitted since admin area is not specified", US_KEY,
- key.toString());
+ key = key.getParentKey();
+ assertNull("root key's parent should be null", key);
+ }
- // Tries key string with the same problem (missing Admin Area).
- key = new LookupKey.Builder("data/US//Mt View").build();
-
- assertEquals("locality should be omitted since admin area is not specified", US_KEY,
- key.toString());
- }
-
- public void testNonUsAddress() {
- AddressData address = new AddressData.Builder().setCountry("TW")
- // Taipei City
- .setAdminArea("\u53F0\u5317\u5E02")
- // Da-an District
- .setLocality("\u5927\u5B89\u5340")
- .build();
-
- LookupKey key = new LookupKey.Builder(KeyType.DATA).setAddressData(address).build();
- assertEquals(TW_KEY, key.toString());
-
- key = new LookupKey.Builder(KeyType.EXAMPLES).setAddressData(address).build();
- assertEquals(TW_EXAMPLE_LOCAL_KEY, key.toString());
-
- address = new AddressData.Builder(address).setLanguageCode("zh-latn").build();
- key = new LookupKey.Builder(KeyType.EXAMPLES).setAddressData(address).build();
- assertEquals(TW_EXAMPLE_LATIN_KEY, key.toString());
+ public void testInvalidKeyTypeWillFail() {
+ try {
+ new LookupKey.Builder(RANDOM_KEY).build();
+ fail("Should fail if key string does not start with a valid key type");
+ } catch (RuntimeException e) {
+ // Expected.
}
-
- public void testGetKeyForUpperLevelFieldWithDataKey() {
- AddressData address = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mt View")
- .build();
-
- LookupKey key = new LookupKey.Builder(KeyType.DATA).setAddressData(address).build();
- LookupKey newKey = key.getKeyForUpperLevelField(AddressField.COUNTRY);
- assertNotNull("failed to get key for " + AddressField.COUNTRY, newKey);
- assertEquals("data/US", newKey.toString());
-
- newKey = key.getKeyForUpperLevelField(AddressField.ADMIN_AREA);
- assertNotNull("failed to get key for " + AddressField.ADMIN_AREA, newKey);
- assertEquals("data/US/CA", newKey.toString());
- assertEquals("original key should not be changed", "data/US/CA/Mt View", key.toString());
-
- newKey = key.getKeyForUpperLevelField(AddressField.LOCALITY);
- assertNotNull("failed to get key for " + AddressField.LOCALITY, newKey);
- assertEquals("data/US/CA/Mt View", newKey.toString());
-
- newKey = key.getKeyForUpperLevelField(AddressField.DEPENDENT_LOCALITY);
- assertNull("should return null for field not contained in current key", newKey);
-
- newKey = key.getKeyForUpperLevelField(AddressField.RECIPIENT);
- assertNull("should return null since field '" + AddressField.RECIPIENT +
- "' is not in address hierarchy", newKey);
- }
-
- public void testGetKeyForUpperLevelFieldWithExampleKey() {
- LookupKey key = new LookupKey.Builder("examples/US/latin/_default").build();
-
- try {
- key.getKeyForUpperLevelField(AddressField.COUNTRY);
- fail("should fail if you try to get parent key for an example key.");
- } catch (RuntimeException e) {
- // Expected.
- }
- }
-
- public void testGetParentKey() {
- AddressData address = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mt View")
- .setDependentLocality("El Camino")
- .build();
-
- LookupKey key = new LookupKey.Builder(KeyType.DATA).setAddressData(address).build();
- assertEquals("data/US/CA/Mt View/El Camino", key.toString());
-
- key = key.getParentKey();
- assertEquals("data/US/CA/Mt View", key.toString());
-
- key = key.getParentKey();
- assertEquals("data/US/CA", key.toString());
-
- key = key.getParentKey();
- assertEquals("data/US", key.toString());
-
- key = key.getParentKey();
- assertEquals("data", key.toString());
-
- key = key.getParentKey();
- assertNull("root key's parent should be null", key);
- }
-
- public void testInvalidKeyTypeWillFail() {
- try {
- new LookupKey.Builder(RANDOM_KEY).build();
- fail("Should fail if key string does not start with a valid key type");
- } catch (RuntimeException e) {
- // Expected.
- }
- }
-
- /**
- * Ensures that even when the input key string is random, we still create a key. (We do not
- * verify if the key maps to an real world entity like a city or country).
- */
- public void testWeDontVerifyKeyName() {
- LookupKey key = new LookupKey.Builder(RANDOM_COUNTRY_KEY).build();
- assertEquals(RANDOM_COUNTRY_KEY, key.toString());
- }
-
- public void testHash() {
- String keys[] = { ROOT_KEY, ROOT_EXAMPLE_KEY, US_KEY, CALIFORNIA_KEY };
- Map<LookupKey, String> map = new HashMap<LookupKey, String>();
-
- for (String key : keys) {
- map.put(new LookupKey.Builder(key).build(), key);
- }
-
- for (String key : keys) {
- assertTrue(map.containsKey(new LookupKey.Builder(key).build()));
- assertEquals(key, map.get(new LookupKey.Builder(key).build()));
- }
- assertFalse(map.containsKey(new LookupKey.Builder(RANDOM_COUNTRY_KEY).build()));
- }
-
- public void testGetValueForUpperLevelField() {
- LookupKey key = new LookupKey.Builder("data/US/CA").build();
- assertEquals("US", key.getValueForUpperLevelField(AddressField.COUNTRY));
+ }
+
+ /**
+ * Ensures that even when the input key string is random, we still create a key. (We do not
+ * verify if the key maps to an real world entity like a city or country).
+ */
+ public void testWeDontVerifyKeyName() {
+ LookupKey key = new LookupKey.Builder(RANDOM_COUNTRY_KEY).build();
+ assertEquals(RANDOM_COUNTRY_KEY, key.toString());
+ }
+
+ public void testHash() {
+ String keys[] = { ROOT_KEY, ROOT_EXAMPLE_KEY, US_KEY, CALIFORNIA_KEY };
+ Map<LookupKey, String> map = new HashMap<LookupKey, String>();
+
+ for (String key : keys) {
+ map.put(new LookupKey.Builder(key).build(), key);
}
- public void testGetValueForUpperLevelFieldInvalid() {
- LookupKey key = new LookupKey.Builder("data").build();
- assertEquals("", key.getValueForUpperLevelField(AddressField.COUNTRY));
- LookupKey key2 = new LookupKey.Builder("data/").build();
- assertEquals("", key2.getValueForUpperLevelField(AddressField.COUNTRY));
+ for (String key : keys) {
+ assertTrue(map.containsKey(new LookupKey.Builder(key).build()));
+ assertEquals(key, map.get(new LookupKey.Builder(key).build()));
}
+ assertFalse(map.containsKey(new LookupKey.Builder(RANDOM_COUNTRY_KEY).build()));
+ }
+
+ public void testGetValueForUpperLevelField() {
+ LookupKey key = new LookupKey.Builder("data/US/CA").build();
+ assertEquals("US", key.getValueForUpperLevelField(AddressField.COUNTRY));
+ }
+
+ public void testGetValueForUpperLevelFieldInvalid() {
+ LookupKey key = new LookupKey.Builder("data").build();
+ assertEquals("", key.getValueForUpperLevelField(AddressField.COUNTRY));
+ LookupKey key2 = new LookupKey.Builder("data/").build();
+ assertEquals("", key2.getValueForUpperLevelField(AddressField.COUNTRY));
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/RegionDataConstantsTest.java b/java/test/com/android/i18n/addressinput/RegionDataConstantsTest.java
index f623146..d268c5f 100644
--- a/java/test/com/android/i18n/addressinput/RegionDataConstantsTest.java
+++ b/java/test/com/android/i18n/addressinput/RegionDataConstantsTest.java
@@ -23,22 +23,22 @@ import junit.framework.TestCase;
* and converted into the appropriate format.
*/
public class RegionDataConstantsTest extends TestCase {
- public void testDataLoad() throws Exception {
- assertFalse("The list of countries should not be empty",
- RegionDataConstants.getCountryFormatMap().isEmpty());
- }
+ public void testDataLoad() throws Exception {
+ assertFalse("The list of countries should not be empty",
+ RegionDataConstants.getCountryFormatMap().isEmpty());
+ }
- public void testZZRegion() throws Exception {
- assertNotNull("Data for 'ZZ' is missing (needed for default region info.)",
- RegionDataConstants.getCountryFormatMap().get("ZZ"));
- }
+ public void testZZRegion() throws Exception {
+ assertNotNull("Data for 'ZZ' is missing (needed for default region info.)",
+ RegionDataConstants.getCountryFormatMap().get("ZZ"));
+ }
- public void testStringsAreConvertedIntoJson() throws Exception {
- String[] input = { "key", "value", "key2", "value2" };
- // Input order is not maintained, since we build this using JSON objects. This is
- // unimportant, so long as the key-value mappings are maintained.
- String expectedOutput = "{\"key2\":\"value2\",\"key\":\"value\"}";
- String actualOutput = RegionDataConstants.convertArrayToJsonString(input);
- assertEquals(expectedOutput, actualOutput);
- }
+ public void testStringsAreConvertedIntoJson() throws Exception {
+ String[] input = { "key", "value", "key2", "value2" };
+ // Input order is not maintained, since we build this using JSON objects. This is
+ // unimportant, so long as the key-value mappings are maintained.
+ String expectedOutput = "{\"key2\":\"value2\",\"key\":\"value\"}";
+ String actualOutput = RegionDataConstants.convertArrayToJsonString(input);
+ assertEquals(expectedOutput, actualOutput);
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/RegionDataTest.java b/java/test/com/android/i18n/addressinput/RegionDataTest.java
index 547f934..4731e4d 100644
--- a/java/test/com/android/i18n/addressinput/RegionDataTest.java
+++ b/java/test/com/android/i18n/addressinput/RegionDataTest.java
@@ -22,28 +22,28 @@ import junit.framework.TestCase;
* Small unit tests for the RegionData class.
*/
public class RegionDataTest extends TestCase {
- public void testBuilder() throws Exception {
- RegionData data = new RegionData.Builder().setKey("CA").setName("California").build();
- assertEquals("CA", data.getKey());
- assertEquals("California", data.getName());
- assertTrue(data.isValidName("CA"));
- // Should match either the key or the name.
- assertTrue(data.isValidName("California"));
- // Matching should be case-insensitive.
- assertTrue(data.isValidName("ca"));
- assertFalse(data.isValidName("Cat"));
- }
+ public void testBuilder() throws Exception {
+ RegionData data = new RegionData.Builder().setKey("CA").setName("California").build();
+ assertEquals("CA", data.getKey());
+ assertEquals("California", data.getName());
+ assertTrue(data.isValidName("CA"));
+ // Should match either the key or the name.
+ assertTrue(data.isValidName("California"));
+ // Matching should be case-insensitive.
+ assertTrue(data.isValidName("ca"));
+ assertFalse(data.isValidName("Cat"));
+ }
- public void testBuilderNoName() throws Exception {
- RegionData data = new RegionData.Builder().setKey("CA").build();
- assertEquals("CA", data.getKey());
- assertEquals(null, data.getName());
- }
+ public void testBuilderNoName() throws Exception {
+ RegionData data = new RegionData.Builder().setKey("CA").build();
+ assertEquals("CA", data.getKey());
+ assertEquals(null, data.getName());
+ }
- public void testBuilderWhitespaceName() throws Exception {
- RegionData data = new RegionData.Builder().setKey("CA").setName(" ").build();
- assertEquals("CA", data.getKey());
- assertEquals(null, data.getName());
- assertEquals("CA", data.getDisplayName());
- }
+ public void testBuilderWhitespaceName() throws Exception {
+ RegionData data = new RegionData.Builder().setKey("CA").setName(" ").build();
+ assertEquals("CA", data.getKey());
+ assertEquals(null, data.getName());
+ assertEquals("CA", data.getDisplayName());
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/StandardAddressVerifierTest.java b/java/test/com/android/i18n/addressinput/StandardAddressVerifierTest.java
index f2c86f6..f47e64f 100644
--- a/java/test/com/android/i18n/addressinput/StandardAddressVerifierTest.java
+++ b/java/test/com/android/i18n/addressinput/StandardAddressVerifierTest.java
@@ -23,235 +23,235 @@ import junit.framework.TestCase;
*/
public class StandardAddressVerifierTest extends TestCase {
- private AddressProblems problems = new AddressProblems();
- private StandardAddressVerifier verifier;
-
- @Override
- protected void setUp() {
- problems.clear();
- verifier = new StandardAddressVerifier(new FieldVerifier(new ClientData(new CacheData())),
- StandardChecks.PROBLEM_MAP);
- }
-
- public void testUnitedStatesOk() {
- AddressData addr = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mountain View")
- .setAddress("1234 Somewhere")
- .setPostalCode("94025")
- .build();
- verifier.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty()); // no mismatch
- }
-
- public void testUnitedStatesZipMismatch() {
- AddressData addr = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mountain View")
- .setPostalCode("12345")
- .build();
- verifier.verify(addr, problems);
-
- assertEquals(AddressProblemType.MISMATCHING_VALUE,
- problems.getProblem(AddressField.POSTAL_CODE));
- }
-
- public void testUnitedStatesNotOk() {
- AddressData addr = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality(null)
- .setDependentLocality("Foo Bar")
- .setPostalCode("12345")
- .build();
- verifier.verify(addr, problems);
-
- assertEquals(AddressProblemType.MISMATCHING_VALUE,
- problems.getProblem(AddressField.POSTAL_CODE));
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- problems.getProblem(AddressField.LOCALITY));
- }
-
- public void testChinaOk() {
- AddressData addr = new AddressData.Builder().setCountry("CN")
- .setAdminArea("Beijing Shi")
- .setLocality("Xicheng Qu")
- .setAddress("Yitiao Lu")
- .setPostalCode("123456")
- .build();
- verifier.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
- }
-
- public void testGermanAddress() {
- AddressData addr = new AddressData.Builder().setCountry("DE")
- .setLocality("Berlin")
- .setAddress("Huttenstr. 50")
- .setPostalCode("10553")
- .setOrganization("BMW AG Niederkassung Berlin")
- .setRecipient("Herr Diefendorf")
- .build();
-
- verifier.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
-
- // Clones address but leave city empty.
- addr = new AddressData.Builder().set(addr).setLocality(null).build();
-
- verifier.verify(addr, problems);
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- problems.getProblem(AddressField.LOCALITY));
- }
-
- public void testIrishAddress() {
- AddressData addr = new AddressData.Builder().setCountry("IE")
- .setLocality("Dublin")
- .setAdminArea("Co. Dublin")
- .setAddress("7424 118 Avenue NW")
- .setRecipient("Conan O'Brien")
- .build();
-
- verifier.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
-
- // Clones address but leave county empty. This address should be valid
- // since county is not required.
- addr = new AddressData.Builder().set(addr).setAdminArea(null).build();
-
- verifier.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
- }
-
- public void testChinaPostalCodeBadFormat() {
- AddressData addr = new AddressData.Builder().setCountry("CN")
- .setAdminArea("Beijing Shi")
- .setLocality("Xicheng Qu")
- .setPostalCode("12345")
- .build();
- verifier.verify(addr, problems);
-
- // ensure problem is unrecognized format and problem is in POSTAL_CODE
- assertEquals(AddressProblemType.UNRECOGNIZED_FORMAT,
- problems.getProblem(AddressField.POSTAL_CODE));
- }
-
- /**
- * If there is a postal code pattern for a certain country, and the input postal code is empty,
- * it should not be reported as bad postal code format. Whether empty postal code is ok should
- * be determined by checks for required fields.
- */
- public void testEmptyPostalCodeReportedAsGoodFormat() {
- // Chilean address has a postal code format pattern, but does not require
- // postal code. The following address is valid.
- AddressData addr = new AddressData.Builder().setCountry("CL")
- .setAddressLine1("GUSTAVO LE PAIGE ST #159")
- .setAdminArea("Atacama")
- .setLocality("San Pedro")
- .setPostalCode("")
- .build();
- verifier.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
-
- problems.clear();
-
- // Now checks for US addresses, which requires postal code. The following
- // address's postal code is wrong because it misses required field, not
- // because it mismatches expected postal code pattern.
- addr = new AddressData.Builder().setCountry("US").setPostalCode("").build();
- problems.clear();
- verifier.verify(addr, problems);
-
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- problems.getProblem(AddressField.POSTAL_CODE));
- }
-
- public void testChinaTaiwanOk() {
- AddressData addr = new AddressData.Builder().setCountry("CN")
- .setAdminArea("Taiwan")
- .setLocality("Taichung City")
- .setDependentLocality("Situn District")
- .setAddress("12345 Yitiao Lu")
- .setPostalCode("407")
- .build();
- verifier.verify(addr, problems);
- assertTrue(problems.toString(), problems.isEmpty());
- }
-
- public void testChinaTaiwanUnknownDistrict() {
- AddressData addr = new AddressData.Builder().setCountry("CN")
- .setAdminArea("Taiwan")
- .setLocality("Taichung City")
- .setDependentLocality("Foo Bar")
- .setPostalCode("400")
- .build();
- verifier.verify(addr, problems);
-
- assertEquals(AddressProblemType.UNKNOWN_VALUE,
- problems.getProblem(AddressField.DEPENDENT_LOCALITY));
- }
-
- public void testStreetVerification() {
- // missing street address
- AddressData addr = new AddressData.Builder().setCountry("US")
- .setAdminArea("CA")
- .setLocality("Mountain View")
- .setPostalCode("94025")
- .build();
-
- assertNull(addr.getAddressLine1());
- assertNull(addr.getAddressLine2());
-
- verifier.verify(addr, problems);
-
- assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
- problems.getProblem(AddressField.STREET_ADDRESS));
- }
-
- // Tests The Bahamas' address
- public void failingtestBahamas() {
- final AddressData address =
- new AddressData.Builder().setAddress("Abaco Beach Resort & Boat Habour")
- .setLocality("Treasure Cay")
- .setAdminArea("Abaco")
- .setCountry("BS")
- .build();
- verifier.verify(address, problems);
- assertTrue(problems.toString(), problems.isEmpty());
- }
-
- public void testJapan() {
- // added AdminArea since address verification can't infer it from Kyoto City
- // commented out dependent locality since address verification doesn't use it
- // TODO: support inference of higher levels from lower ones
- // TODO: add dependent locality support for japan addresses
- final AddressData address =
- new AddressData.Builder()
- .setRecipient("\u5BAE\u672C \u8302") // SHIGERU_MIYAMOTO
- .setAddress("\u4E0A\u9CE5\u7FBD\u927E\u7ACB\u753A11\u756A\u5730")
- .setAdminArea("\u4eac\u90fd\u5e9c") // Kyoto prefecture, added
- .setLocality("\u4EAC\u90FD\u5E02") // Kyoto city
- // .setDependentLocality("\u5357\u533A")
- .setCountry("JP")
- .setPostalCode("601-8501")
- .build();
- verifier.verify(address, problems);
- assertTrue(problems.toString(), problems.isEmpty());
- }
-
- public void testJapanLatin() {
- // added AdminArea since address verification can't infer it from Kyoto City
- // commented out dependent locality since address verification doesn't use it
- final AddressData address =
- new AddressData.Builder()
- .setRecipient("Shigeru Miyamoto") // SHIGERU_MIYAMOTO_ENGLISH
- .setAddress("11-1 Kamitoba-hokotate-cho")
- .setAdminArea("KYOTO") // Kyoto prefecture, added
- .setLocality("Kyoto") // Kyoto city
- // .setDependentLocality("Minami-ku")
- .setLanguageCode("ja_Latn")
- .setCountry("JP")
- .setPostalCode("601-8501")
- .build();
- verifier.verify(address, problems);
- assertTrue(problems.toString(), problems.isEmpty());
- }
+ private AddressProblems problems = new AddressProblems();
+ private StandardAddressVerifier verifier;
+
+ @Override
+ protected void setUp() {
+ problems.clear();
+ verifier = new StandardAddressVerifier(new FieldVerifier(new ClientData(new CacheData())),
+ StandardChecks.PROBLEM_MAP);
+ }
+
+ public void testUnitedStatesOk() {
+ AddressData addr = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mountain View")
+ .setAddress("1234 Somewhere")
+ .setPostalCode("94025")
+ .build();
+ verifier.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty()); // no mismatch
+ }
+
+ public void testUnitedStatesZipMismatch() {
+ AddressData addr = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mountain View")
+ .setPostalCode("12345")
+ .build();
+ verifier.verify(addr, problems);
+
+ assertEquals(AddressProblemType.MISMATCHING_VALUE,
+ problems.getProblem(AddressField.POSTAL_CODE));
+ }
+
+ public void testUnitedStatesNotOk() {
+ AddressData addr = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality(null)
+ .setDependentLocality("Foo Bar")
+ .setPostalCode("12345")
+ .build();
+ verifier.verify(addr, problems);
+
+ assertEquals(AddressProblemType.MISMATCHING_VALUE,
+ problems.getProblem(AddressField.POSTAL_CODE));
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ problems.getProblem(AddressField.LOCALITY));
+ }
+
+ public void testChinaOk() {
+ AddressData addr = new AddressData.Builder().setCountry("CN")
+ .setAdminArea("Beijing Shi")
+ .setLocality("Xicheng Qu")
+ .setAddress("Yitiao Lu")
+ .setPostalCode("123456")
+ .build();
+ verifier.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+ }
+
+ public void testGermanAddress() {
+ AddressData addr = new AddressData.Builder().setCountry("DE")
+ .setLocality("Berlin")
+ .setAddress("Huttenstr. 50")
+ .setPostalCode("10553")
+ .setOrganization("BMW AG Niederkassung Berlin")
+ .setRecipient("Herr Diefendorf")
+ .build();
+
+ verifier.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+
+ // Clones address but leave city empty.
+ addr = new AddressData.Builder().set(addr).setLocality(null).build();
+
+ verifier.verify(addr, problems);
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ problems.getProblem(AddressField.LOCALITY));
+ }
+
+ public void testIrishAddress() {
+ AddressData addr = new AddressData.Builder().setCountry("IE")
+ .setLocality("Dublin")
+ .setAdminArea("Co. Dublin")
+ .setAddress("7424 118 Avenue NW")
+ .setRecipient("Conan O'Brien")
+ .build();
+
+ verifier.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+
+ // Clones address but leave county empty. This address should be valid
+ // since county is not required.
+ addr = new AddressData.Builder().set(addr).setAdminArea(null).build();
+
+ verifier.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+ }
+
+ public void testChinaPostalCodeBadFormat() {
+ AddressData addr = new AddressData.Builder().setCountry("CN")
+ .setAdminArea("Beijing Shi")
+ .setLocality("Xicheng Qu")
+ .setPostalCode("12345")
+ .build();
+ verifier.verify(addr, problems);
+
+ // ensure problem is unrecognized format and problem is in POSTAL_CODE
+ assertEquals(AddressProblemType.UNRECOGNIZED_FORMAT,
+ problems.getProblem(AddressField.POSTAL_CODE));
+ }
+
+ /**
+ * If there is a postal code pattern for a certain country, and the input postal code is empty,
+ * it should not be reported as bad postal code format. Whether an empty postal code is ok
+ * should be determined by checks for required fields.
+ */
+ public void testEmptyPostalCodeReportedAsGoodFormat() {
+ // Chilean address has a postal code format pattern, but does not require
+ // postal code. The following address is valid.
+ AddressData addr = new AddressData.Builder().setCountry("CL")
+ .setAddressLine1("GUSTAVO LE PAIGE ST #159")
+ .setAdminArea("Atacama")
+ .setLocality("Alto del Carmen")
+ .setPostalCode("")
+ .build();
+ verifier.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+
+ problems.clear();
+
+ // Now checks for US addresses, which requires postal code. The following
+ // address's postal code is wrong because it misses required field, not
+ // because it mismatches expected postal code pattern.
+ addr = new AddressData.Builder().setCountry("US").setPostalCode("").build();
+ problems.clear();
+ verifier.verify(addr, problems);
+
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ problems.getProblem(AddressField.POSTAL_CODE));
+ }
+
+ public void testChinaTaiwanOk() {
+ AddressData addr = new AddressData.Builder().setCountry("CN")
+ .setAdminArea("Taiwan")
+ .setLocality("Taichung City")
+ .setDependentLocality("Situn District")
+ .setAddress("12345 Yitiao Lu")
+ .setPostalCode("407")
+ .build();
+ verifier.verify(addr, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+ }
+
+ public void testChinaTaiwanUnknownDistrict() {
+ AddressData addr = new AddressData.Builder().setCountry("CN")
+ .setAdminArea("Taiwan")
+ .setLocality("Taichung City")
+ .setDependentLocality("Foo Bar")
+ .setPostalCode("400")
+ .build();
+ verifier.verify(addr, problems);
+
+ assertEquals(AddressProblemType.UNKNOWN_VALUE,
+ problems.getProblem(AddressField.DEPENDENT_LOCALITY));
+ }
+
+ public void testStreetVerification() {
+ // missing street address
+ AddressData addr = new AddressData.Builder().setCountry("US")
+ .setAdminArea("CA")
+ .setLocality("Mountain View")
+ .setPostalCode("94025")
+ .build();
+
+ assertNull(addr.getAddressLine1());
+ assertNull(addr.getAddressLine2());
+
+ verifier.verify(addr, problems);
+
+ assertEquals(AddressProblemType.MISSING_REQUIRED_FIELD,
+ problems.getProblem(AddressField.STREET_ADDRESS));
+ }
+
+ // Tests The Bahamas' address
+ public void failingtestBahamas() {
+ final AddressData address =
+ new AddressData.Builder().setAddress("Abaco Beach Resort & Boat Habour")
+ .setLocality("Treasure Cay")
+ .setAdminArea("Abaco")
+ .setCountry("BS")
+ .build();
+ verifier.verify(address, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+ }
+
+ public void testJapan() {
+ // added AdminArea since address verification can't infer it from Kyoto City
+ // commented out dependent locality since address verification doesn't use it
+ // TODO: support inference of higher levels from lower ones
+ // TODO: add dependent locality support for japan addresses
+ final AddressData address =
+ new AddressData.Builder()
+ .setRecipient("\u5BAE\u672C \u8302") // SHIGERU_MIYAMOTO
+ .setAddress("\u4E0A\u9CE5\u7FBD\u927E\u7ACB\u753A11\u756A\u5730")
+ .setAdminArea("\u4eac\u90fd\u5e9c") // Kyoto prefecture, added
+ .setLocality("\u4EAC\u90FD\u5E02") // Kyoto city
+ // .setDependentLocality("\u5357\u533A")
+ .setCountry("JP")
+ .setPostalCode("601-8501")
+ .build();
+ verifier.verify(address, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+ }
+
+ public void testJapanLatin() {
+ // added AdminArea since address verification can't infer it from Kyoto City
+ // commented out dependent locality since address verification doesn't use it
+ final AddressData address =
+ new AddressData.Builder()
+ .setRecipient("Shigeru Miyamoto") // SHIGERU_MIYAMOTO_ENGLISH
+ .setAddress("11-1 Kamitoba-hokotate-cho")
+ .setAdminArea("KYOTO") // Kyoto prefecture, added
+ .setLocality("Kyoto") // Kyoto city
+ // .setDependentLocality("Minami-ku")
+ .setLanguageCode("ja_Latn")
+ .setCountry("JP")
+ .setPostalCode("601-8501")
+ .build();
+ verifier.verify(address, problems);
+ assertTrue(problems.toString(), problems.isEmpty());
+ }
}
diff --git a/java/test/com/android/i18n/addressinput/UtilTest.java b/java/test/com/android/i18n/addressinput/UtilTest.java
index d552062..73a7956 100644
--- a/java/test/com/android/i18n/addressinput/UtilTest.java
+++ b/java/test/com/android/i18n/addressinput/UtilTest.java
@@ -26,129 +26,129 @@ import java.util.Map;
*/
public class UtilTest extends TestCase {
- public void testIsExplicitLatinScript() throws Exception {
- // Should recognise Latin script in a variety of forms.
- assertTrue(Util.isExplicitLatinScript("zh-Latn"));
- assertTrue(Util.isExplicitLatinScript("ja_LATN"));
- assertTrue(Util.isExplicitLatinScript("und_LATN"));
- assertTrue(Util.isExplicitLatinScript("ja_LATN-JP"));
- assertTrue(Util.isExplicitLatinScript("ko-latn_JP"));
- }
+ public void testIsExplicitLatinScript() throws Exception {
+ // Should recognise Latin script in a variety of forms.
+ assertTrue(Util.isExplicitLatinScript("zh-Latn"));
+ assertTrue(Util.isExplicitLatinScript("ja_LATN"));
+ assertTrue(Util.isExplicitLatinScript("und_LATN"));
+ assertTrue(Util.isExplicitLatinScript("ja_LATN-JP"));
+ assertTrue(Util.isExplicitLatinScript("ko-latn_JP"));
+ }
- public void testIsExplicitLatinScriptNonLatin() throws Exception {
- assertFalse(Util.isExplicitLatinScript("ko"));
- assertFalse(Util.isExplicitLatinScript("KO"));
- assertFalse(Util.isExplicitLatinScript("ja"));
- assertFalse(Util.isExplicitLatinScript("ja-JP"));
- assertFalse(Util.isExplicitLatinScript("zh-Hans"));
- assertFalse(Util.isExplicitLatinScript("zh-Hans-CN"));
- assertFalse(Util.isExplicitLatinScript("zh-Hant"));
- assertFalse(Util.isExplicitLatinScript("zh-TW"));
- assertFalse(Util.isExplicitLatinScript("zh_TW"));
- assertFalse(Util.isExplicitLatinScript("ko"));
- assertFalse(Util.isExplicitLatinScript("ko_KR"));
- assertFalse(Util.isExplicitLatinScript("en"));
- assertFalse(Util.isExplicitLatinScript("EN"));
- assertFalse(Util.isExplicitLatinScript("ru"));
- }
+ public void testIsExplicitLatinScriptNonLatin() throws Exception {
+ assertFalse(Util.isExplicitLatinScript("ko"));
+ assertFalse(Util.isExplicitLatinScript("KO"));
+ assertFalse(Util.isExplicitLatinScript("ja"));
+ assertFalse(Util.isExplicitLatinScript("ja-JP"));
+ assertFalse(Util.isExplicitLatinScript("zh-Hans"));
+ assertFalse(Util.isExplicitLatinScript("zh-Hans-CN"));
+ assertFalse(Util.isExplicitLatinScript("zh-Hant"));
+ assertFalse(Util.isExplicitLatinScript("zh-TW"));
+ assertFalse(Util.isExplicitLatinScript("zh_TW"));
+ assertFalse(Util.isExplicitLatinScript("ko"));
+ assertFalse(Util.isExplicitLatinScript("ko_KR"));
+ assertFalse(Util.isExplicitLatinScript("en"));
+ assertFalse(Util.isExplicitLatinScript("EN"));
+ assertFalse(Util.isExplicitLatinScript("ru"));
+ }
- public void testGetLanguageSubtag() throws Exception {
- assertEquals("zh", Util.getLanguageSubtag("zh-Latn"));
- assertEquals("ja", Util.getLanguageSubtag("ja_LATN"));
- assertEquals("und", Util.getLanguageSubtag("und_LATN"));
- assertEquals("ja", Util.getLanguageSubtag("ja_LATN-JP"));
- assertEquals("ko", Util.getLanguageSubtag("ko"));
- assertEquals("ko", Util.getLanguageSubtag("KO"));
- assertEquals("ko", Util.getLanguageSubtag("ko-KR"));
- assertEquals("ko", Util.getLanguageSubtag("ko_kr"));
- assertEquals("und", Util.getLanguageSubtag("Not a language"));
- }
+ public void testGetLanguageSubtag() throws Exception {
+ assertEquals("zh", Util.getLanguageSubtag("zh-Latn"));
+ assertEquals("ja", Util.getLanguageSubtag("ja_LATN"));
+ assertEquals("und", Util.getLanguageSubtag("und_LATN"));
+ assertEquals("ja", Util.getLanguageSubtag("ja_LATN-JP"));
+ assertEquals("ko", Util.getLanguageSubtag("ko"));
+ assertEquals("ko", Util.getLanguageSubtag("KO"));
+ assertEquals("ko", Util.getLanguageSubtag("ko-KR"));
+ assertEquals("ko", Util.getLanguageSubtag("ko_kr"));
+ assertEquals("und", Util.getLanguageSubtag("Not a language"));
+ }
- public void testTrimToNull() throws Exception {
- assertEquals("Trimmed String", Util.trimToNull(" Trimmed String "));
- assertEquals("Trimmed String", Util.trimToNull(" Trimmed String"));
- assertEquals("Trimmed String", Util.trimToNull("Trimmed String"));
- assertEquals(null, Util.trimToNull(" "));
- assertEquals(null, Util.trimToNull(null));
- }
+ public void testTrimToNull() throws Exception {
+ assertEquals("Trimmed String", Util.trimToNull(" Trimmed String "));
+ assertEquals("Trimmed String", Util.trimToNull(" Trimmed String"));
+ assertEquals("Trimmed String", Util.trimToNull("Trimmed String"));
+ assertEquals(null, Util.trimToNull(" "));
+ assertEquals(null, Util.trimToNull(null));
+ }
- public void testJoinAndSkipNulls() throws Exception {
- String first = "String 1";
- String second = "String 2";
- String expectedString = "String 1-String 2";
- String nullString = null;
- assertEquals(expectedString, Util.joinAndSkipNulls("-", first, second));
- assertEquals(expectedString, Util.joinAndSkipNulls("-", first, second, nullString));
- assertEquals(expectedString, Util.joinAndSkipNulls("-", first, nullString, second));
- assertEquals(expectedString, Util.joinAndSkipNulls("-", first, nullString, " ", second));
- assertEquals(first, Util.joinAndSkipNulls("-", first, nullString));
- assertEquals(first, Util.joinAndSkipNulls("-", nullString, first));
+ public void testJoinAndSkipNulls() throws Exception {
+ String first = "String 1";
+ String second = "String 2";
+ String expectedString = "String 1-String 2";
+ String nullString = null;
+ assertEquals(expectedString, Util.joinAndSkipNulls("-", first, second));
+ assertEquals(expectedString, Util.joinAndSkipNulls("-", first, second, nullString));
+ assertEquals(expectedString, Util.joinAndSkipNulls("-", first, nullString, second));
+ assertEquals(expectedString, Util.joinAndSkipNulls("-", first, nullString, " ", second));
+ assertEquals(first, Util.joinAndSkipNulls("-", first, nullString));
+ assertEquals(first, Util.joinAndSkipNulls("-", nullString, first));
- assertEquals(null, Util.joinAndSkipNulls("-", nullString));
- assertEquals(null, Util.joinAndSkipNulls("-", nullString, nullString));
- assertEquals(null, Util.joinAndSkipNulls("-", nullString, "", nullString));
- }
+ assertEquals(null, Util.joinAndSkipNulls("-", nullString));
+ assertEquals(null, Util.joinAndSkipNulls("-", nullString, nullString));
+ assertEquals(null, Util.joinAndSkipNulls("-", nullString, "", nullString));
+ }
- public void testGetWidgetCompatibleLanguageCodeCjkCountry() throws Exception {
- Locale canadianFrench = new Locale("fr", "CA");
- // Latin language, CJK country. Need explicit Latin tag, and country should be retained.
- assertEquals("fr_latn_CA", Util.getWidgetCompatibleLanguageCode(canadianFrench, "CN"));
- Locale canadianFrenchUpper = new Locale("FR", "CA");
- // Test that the locale returns the same language code, regardless of the case of the
- // initial input.
- assertEquals("fr_latn_CA", Util.getWidgetCompatibleLanguageCode(canadianFrenchUpper, "CN"));
- // No country in the Locale language.
- assertEquals("fr_latn", Util.getWidgetCompatibleLanguageCode(Locale.FRENCH, "CN"));
- // CJK language - but wrong country.
- assertEquals("ko_latn",
- Util.getWidgetCompatibleLanguageCode(Locale.KOREAN, "CN"));
- Locale chineseChina = new Locale("zh", "CN");
- assertEquals("zh_CN", Util.getWidgetCompatibleLanguageCode(chineseChina, "CN"));
- }
+ public void testGetWidgetCompatibleLanguageCodeCjkCountry() throws Exception {
+ Locale canadianFrench = new Locale("fr", "CA");
+ // Latin language, CJK country. Need explicit Latin tag, and country should be retained.
+ assertEquals("fr_latn_CA", Util.getWidgetCompatibleLanguageCode(canadianFrench, "CN"));
+ Locale canadianFrenchUpper = new Locale("FR", "CA");
+ // Test that the locale returns the same language code, regardless of the case of the
+ // initial input.
+ assertEquals("fr_latn_CA", Util.getWidgetCompatibleLanguageCode(canadianFrenchUpper, "CN"));
+ // No country in the Locale language.
+ assertEquals("fr_latn", Util.getWidgetCompatibleLanguageCode(Locale.FRENCH, "CN"));
+ // CJK language - but wrong country.
+ assertEquals("ko_latn",
+ Util.getWidgetCompatibleLanguageCode(Locale.KOREAN, "CN"));
+ Locale chineseChina = new Locale("zh", "CN");
+ assertEquals("zh_CN", Util.getWidgetCompatibleLanguageCode(chineseChina, "CN"));
+ }
- public void testGetWidgetCompatibleLanguageCodeThailand() throws Exception {
- Locale thai = new Locale("th", "TH");
- assertEquals("th_TH", Util.getWidgetCompatibleLanguageCode(thai, "TH"));
- // However, we assume Thai users prefer Latin names for China.
- assertEquals("th_latn_TH", Util.getWidgetCompatibleLanguageCode(thai, "CN"));
- }
+ public void testGetWidgetCompatibleLanguageCodeThailand() throws Exception {
+ Locale thai = new Locale("th", "TH");
+ assertEquals("th_TH", Util.getWidgetCompatibleLanguageCode(thai, "TH"));
+ // However, we assume Thai users prefer Latin names for China.
+ assertEquals("th_latn_TH", Util.getWidgetCompatibleLanguageCode(thai, "CN"));
+ }
- public void testGetWidgetCompatibleLanguageCodeNonCjkCountry() throws Exception {
- // Nothing should be changed for non-CJK countries, since their form layout is the same
- // regardless of language.
- Locale canadianFrench = new Locale("fr", "CA");
- assertEquals("fr_CA", Util.getWidgetCompatibleLanguageCode(canadianFrench, "US"));
- // No country in the Locale language.
- assertEquals(Locale.FRENCH.toString(),
- Util.getWidgetCompatibleLanguageCode(Locale.FRENCH, "US"));
- // CJK language - should be unaltered too.
- assertEquals(Locale.KOREAN.toString(),
- Util.getWidgetCompatibleLanguageCode(Locale.KOREAN, "US"));
- }
+ public void testGetWidgetCompatibleLanguageCodeNonCjkCountry() throws Exception {
+ // Nothing should be changed for non-CJK countries, since their form layout is the same
+ // regardless of language.
+ Locale canadianFrench = new Locale("fr", "CA");
+ assertEquals("fr_CA", Util.getWidgetCompatibleLanguageCode(canadianFrench, "US"));
+ // No country in the Locale language.
+ assertEquals(Locale.FRENCH.toString(),
+ Util.getWidgetCompatibleLanguageCode(Locale.FRENCH, "US"));
+ // CJK language - should be unaltered too.
+ assertEquals(Locale.KOREAN.toString(),
+ Util.getWidgetCompatibleLanguageCode(Locale.KOREAN, "US"));
+ }
- public void testBuildNameToKeyMap() throws Exception {
- String names[] = {"", "", "", "", "NEW PROVIDENCE" };
- // We have one more key than name here.
- String keys[] = {"AB", "AC", "AD", "AE", "NP", "XX"};
- Map<String, String> result = Util.buildNameToKeyMap(keys, names, null);
- // We should have the six keys, and the one name, in the end result. No empty-string names
- // should be present.
- assertEquals(keys.length + 1, result.size());
- // The empty string should not be present.
- assertFalse(result.containsKey(""));
+ public void testBuildNameToKeyMap() throws Exception {
+ String names[] = {"", "", "", "", "NEW PROVIDENCE" };
+ // We have one more key than name here.
+ String keys[] = {"AB", "AC", "AD", "AE", "NP", "XX"};
+ Map<String, String> result = Util.buildNameToKeyMap(keys, names, null);
+ // We should have the six keys, and the one name, in the end result. No empty-string names
+ // should be present.
+ assertEquals(keys.length + 1, result.size());
+ // The empty string should not be present.
+ assertFalse(result.containsKey(""));
- // Try with Latin names instead.
- Map<String, String> resultWithLatin = Util.buildNameToKeyMap(keys, null, names);
- // We should have the six keys and the one Latin-script name in the end result.
- assertEquals(keys.length + 1, resultWithLatin.size());
- String lnames[] = { "Other name" };
- resultWithLatin = Util.buildNameToKeyMap(keys, names, lnames);
- // We should have the keys, plus the names in lnames and names.
- assertEquals(keys.length + 2, resultWithLatin.size());
- assertTrue(resultWithLatin.containsKey("other name"));
- assertTrue(resultWithLatin.containsKey("new providence"));
- assertTrue(resultWithLatin.containsKey("xx"));
- // The empty string should not be present.
- assertFalse(resultWithLatin.containsKey(""));
- }
+ // Try with Latin names instead.
+ Map<String, String> resultWithLatin = Util.buildNameToKeyMap(keys, null, names);
+ // We should have the six keys and the one Latin-script name in the end result.
+ assertEquals(keys.length + 1, resultWithLatin.size());
+ String lnames[] = { "Other name" };
+ resultWithLatin = Util.buildNameToKeyMap(keys, names, lnames);
+ // We should have the keys, plus the names in lnames and names.
+ assertEquals(keys.length + 2, resultWithLatin.size());
+ assertTrue(resultWithLatin.containsKey("other name"));
+ assertTrue(resultWithLatin.containsKey("new providence"));
+ assertTrue(resultWithLatin.containsKey("xx"));
+ // The empty string should not be present.
+ assertFalse(resultWithLatin.containsKey(""));
+ }
}