Upstream version 8.36.169.0
[platform/framework/web/crosswalk.git] / src / third_party / libaddressinput / src / java / test / com / android / i18n / addressinput / AddressDataTest.java
1 /*
2  * Copyright (C) 2010 Google Inc.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.android.i18n.addressinput;
18
19 import junit.framework.TestCase;
20
21 /**
22  * Tests for the AddressData class.
23  */
24 public class AddressDataTest extends TestCase {
25     private static final String ADDRESS_LINE = "First address line";
26
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());
33     }
34
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());
41     }
42
43     public void testAddressLineNormalisationWithNewLineCharacters() {
44         AddressData address =
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());
49     }
50
51     public void testNoAdminArea() {
52         AddressData address = new AddressData.Builder().build();
53         assertEquals(null, address.getAdministrativeArea());
54     }
55
56     public void testSetLanguageCode() throws Exception {
57         AddressData address = new AddressData.Builder().setCountry("TW")
58                                                        // Taipei City
59                                                        .setAdminArea("\u53F0\u5317\u5E02")
60                                                        // Da-an District
61                                                        .setLocality("\u5927\u5B89\u5340")
62                                                        .build();
63         address = new AddressData.Builder(address).setLanguageCode("zh-latn").build();
64         assertEquals("zh-latn", address.getLanguageCode());
65     }
66 }