1f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia/* 2f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * Copyright (C) 2013 The Libphonenumber Authors 3f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * 4f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * Licensed under the Apache License, Version 2.0 (the "License"); 5f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * you may not use this file except in compliance with the License. 6f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * You may obtain a copy of the License at 7f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * 8f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * http://www.apache.org/licenses/LICENSE-2.0 9f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * 10f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * Unless required by applicable law or agreed to in writing, software 11f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * distributed under the License is distributed on an "AS IS" BASIS, 12f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * See the License for the specific language governing permissions and 14f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * limitations under the License. 15f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia */ 16f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 17f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jiapackage com.android.i18n.phonenumbers.prefixmapper; 18f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 19f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jiaimport com.android.i18n.phonenumbers.Phonenumber.PhoneNumber; 20f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jiaimport junit.framework.TestCase; 21f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 22f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia/** 23f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * Unit tests for PrefixFileReader.java 24f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * 25f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia * @author Cecilia Roes 26f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia */ 27f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jiapublic class PrefixFileReaderTest extends TestCase { 28f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia private final PrefixFileReader reader = new PrefixFileReader(TEST_MAPPING_DATA_DIRECTORY); 29f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia private static final String TEST_MAPPING_DATA_DIRECTORY = 30f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia "/com/android/i18n/phonenumbers/geocoding/testing_data/"; 31f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 32f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia private static final PhoneNumber KO_NUMBER = 33f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia new PhoneNumber().setCountryCode(82).setNationalNumber(22123456L); 34f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia private static final PhoneNumber US_NUMBER1 = 35f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia new PhoneNumber().setCountryCode(1).setNationalNumber(6502530000L); 36f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia private static final PhoneNumber US_NUMBER2 = 37f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia new PhoneNumber().setCountryCode(1).setNationalNumber(2128120000L); 38f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia private static final PhoneNumber US_NUMBER3 = 39f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia new PhoneNumber().setCountryCode(1).setNationalNumber(6174240000L); 40f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia private static final PhoneNumber SE_NUMBER = 41f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia new PhoneNumber().setCountryCode(46).setNationalNumber(81234567L); 42f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 43f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia public void testGetDescriptionForNumberWithMapping() { 44f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("Kalifornien", 45f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia reader.getDescriptionForNumber(US_NUMBER1, "de", "", "CH")); 46f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("CA", 47f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia reader.getDescriptionForNumber(US_NUMBER1, "en", "", "AU")); 48f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("\uC11C\uC6B8", 49f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia reader.getDescriptionForNumber(KO_NUMBER, "ko", "", "")); 50f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("Seoul", 51f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia reader.getDescriptionForNumber(KO_NUMBER, "en", "", "")); 52f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia } 53f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 54f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia public void testGetDescriptionForNumberWithMissingMapping() { 55f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("", reader.getDescriptionForNumber(US_NUMBER3, "en", "", "")); 56f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia } 57f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 58f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia public void testGetDescriptionUsingFallbackLanguage() { 59f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia // Mapping file exists but the number isn't present, causing it to fallback. 60f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("New York, NY", 61f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia reader.getDescriptionForNumber(US_NUMBER2, "de", "", "CH")); 62f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia // No mapping file exists, causing it to fallback. 63f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("New York, NY", 64f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia reader.getDescriptionForNumber(US_NUMBER2, "sv", "", "")); 65f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia } 66f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 67f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia public void testGetDescriptionForNonFallbackLanguage() { 68f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("", reader.getDescriptionForNumber(US_NUMBER2, "ko", "", "")); 69f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia } 70f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia 71f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia public void testGetDescriptionForNumberWithoutMappingFile() { 72f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("", reader.getDescriptionForNumber(SE_NUMBER, "sv", "", "")); 73f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia assertEquals("", reader.getDescriptionForNumber(SE_NUMBER, "en", "", "")); 74f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia } 75f9768eb3c8f303725fb4f899598481cbc4fb76a3Shaopeng Jia} 76