Home | History | Annotate | Download | only in addressinput
      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  * Small unit tests for the RegionData class.
     23  */
     24 public class RegionDataTest extends TestCase {
     25     public void testBuilder() throws Exception {
     26         RegionData data = new RegionData.Builder().setKey("CA").setName("California").build();
     27         assertEquals("CA", data.getKey());
     28         assertEquals("California", data.getName());
     29         assertTrue(data.isValidName("CA"));
     30         // Should match either the key or the name.
     31         assertTrue(data.isValidName("California"));
     32         // Matching should be case-insensitive.
     33         assertTrue(data.isValidName("ca"));
     34         assertFalse(data.isValidName("Cat"));
     35     }
     36 
     37     public void testBuilderNoName() throws Exception {
     38         RegionData data = new RegionData.Builder().setKey("CA").build();
     39         assertEquals("CA", data.getKey());
     40         assertEquals(null, data.getName());
     41     }
     42 
     43     public void testBuilderWhitespaceName() throws Exception {
     44         RegionData data = new RegionData.Builder().setKey("CA").setName("  ").build();
     45         assertEquals("CA", data.getKey());
     46         assertEquals(null, data.getName());
     47         assertEquals("CA", data.getDisplayName());
     48     }
     49 }
     50