1 /*
2  * Copyright (C) 2015 The Libphonenumber Authors
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.google.i18n.phonenumbers;
18 
19 import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata;
20 import junit.framework.TestCase;
21 
22 /**
23  * Unit tests for MultiFileMetadataSourceImpl.java.
24  */
25 public class MultiFileMetadataSourceImplTest extends TestCase {
26   private static final MultiFileMetadataSourceImpl SOURCE =
27       new MultiFileMetadataSourceImpl(MetadataManager.DEFAULT_METADATA_LOADER);
28   private static final MultiFileMetadataSourceImpl MISSING_FILE_SOURCE =
29       new MultiFileMetadataSourceImpl("no/such/file", MetadataManager.DEFAULT_METADATA_LOADER);
30 
testGeoPhoneNumberMetadataLoadCorrectly()31   public void testGeoPhoneNumberMetadataLoadCorrectly() {
32     // We should have some data for the UAE.
33     PhoneMetadata uaeMetadata = SOURCE.getMetadataForRegion("AE");
34     assertEquals(uaeMetadata.getCountryCode(), 971);
35     assertTrue(uaeMetadata.hasGeneralDesc());
36   }
37 
testGeoPhoneNumberMetadataLoadFromMissingFileThrowsException()38   public void testGeoPhoneNumberMetadataLoadFromMissingFileThrowsException() throws Exception {
39     try {
40       MISSING_FILE_SOURCE.getMetadataForRegion("AE");
41       fail("expected exception");
42     } catch (RuntimeException e) {
43       assertTrue("Unexpected error: " + e, e.getMessage().contains("no/such/file"));
44     }
45   }
46 
testNonGeoPhoneNumberMetadataLoadCorrectly()47   public void testNonGeoPhoneNumberMetadataLoadCorrectly() {
48     // We should have some data for international toll-free numbers.
49     PhoneMetadata intlMetadata = SOURCE.getMetadataForNonGeographicalRegion(800);
50     assertEquals(intlMetadata.getId(), "001");
51     assertTrue(intlMetadata.hasGeneralDesc());
52   }
53 
testNonGeoPhoneNumberMetadataLoadFromMissingFileThrowsException()54   public void testNonGeoPhoneNumberMetadataLoadFromMissingFileThrowsException() throws Exception {
55     try {
56       MISSING_FILE_SOURCE.getMetadataForNonGeographicalRegion(800);
57       fail("expected exception");
58     } catch (RuntimeException e) {
59       assertTrue("Unexpected error: " + e, e.getMessage().contains("no/such/file"));
60     }
61   }
62 }
63