2 * Copyright (C) 2010 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.i18n.addressinput;
19 import junit.framework.TestCase;
22 * Tests for the AddressData class.
24 public class AddressDataTest extends TestCase {
25 private static final String ADDRESS_LINE = "First address line";
27 public void testSetAddressLine() {
28 AddressData.Builder builder = new AddressData.Builder();
29 builder = builder.setAddress("\n " + ADDRESS_LINE);
30 AddressData ad = builder.build();
31 assertEquals(ADDRESS_LINE, ad.getAddressLine1());
32 assertEquals(null, ad.getAddressLine2());
35 public void testAddressLineNormalisation() {
36 AddressData address = new AddressData.Builder().setAddressLine1(null)
37 .setAddressLine2(ADDRESS_LINE).build();
38 AddressData copiedAddress = new AddressData.Builder(address).build();
39 assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine1());
40 assertEquals(null, copiedAddress.getAddressLine2());
43 public void testAddressLineNormalisationWithNewLineCharacters() {
45 new AddressData.Builder().setAddressLine1(ADDRESS_LINE + "\n" + ADDRESS_LINE).build();
46 AddressData copiedAddress = new AddressData.Builder(address).build();
47 assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine1());
48 assertEquals(ADDRESS_LINE, copiedAddress.getAddressLine2());
51 public void testNoAdminArea() {
52 AddressData address = new AddressData.Builder().build();
53 assertEquals(null, address.getAdministrativeArea());
56 public void testSetLanguageCode() throws Exception {
57 AddressData address = new AddressData.Builder().setCountry("TW")
59 .setAdminArea("\u53F0\u5317\u5E02")
61 .setLocality("\u5927\u5B89\u5340")
63 address = new AddressData.Builder(address).setLanguageCode("zh-latn").build();
64 assertEquals("zh-latn", address.getLanguageCode());