1 /* 2 * Copyright (C) 2022 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.metadata.source; 18 19 import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata; 20 import junit.framework.TestCase; 21 22 public class MapBackedMetadataContainerTest extends TestCase { 23 24 private static final String REGION_CODE = "US"; 25 private static final Integer COUNTRY_CODE = 41; 26 private static final PhoneMetadata PHONE_METADATA = 27 PhoneMetadata.newBuilder().setId(REGION_CODE).setCountryCode(COUNTRY_CODE); 28 test_getMetadataBy_shouldReturnNullForNullRegionCode()29 public void test_getMetadataBy_shouldReturnNullForNullRegionCode() { 30 assertNull(MapBackedMetadataContainer.byRegionCode().getMetadataBy(null)); 31 } 32 test_getMetadataBy_shouldReturnNullForNonExistingRegionCode()33 public void test_getMetadataBy_shouldReturnNullForNonExistingRegionCode() { 34 assertNull(MapBackedMetadataContainer.byRegionCode().getMetadataBy(REGION_CODE)); 35 } 36 test_getMetadataBy_shouldReturnMetadataForExistingRegionCode()37 public void test_getMetadataBy_shouldReturnMetadataForExistingRegionCode() { 38 MapBackedMetadataContainer<String> metadataContainer = 39 MapBackedMetadataContainer.byRegionCode(); 40 41 metadataContainer.accept(PHONE_METADATA); 42 43 assertSame(PHONE_METADATA, metadataContainer.getMetadataBy(REGION_CODE)); 44 } 45 test_getMetadataBy_shouldReturnNullForNullCountryCode()46 public void test_getMetadataBy_shouldReturnNullForNullCountryCode() { 47 assertNull(MapBackedMetadataContainer.byCountryCallingCode().getMetadataBy(null)); 48 } 49 test_getMetadataBy_shouldReturnNullForNonExistingCountryCode()50 public void test_getMetadataBy_shouldReturnNullForNonExistingCountryCode() { 51 assertNull(MapBackedMetadataContainer.byCountryCallingCode().getMetadataBy(COUNTRY_CODE)); 52 } 53 test_getMetadataBy_shouldReturnMetadataForExistingCountryCode()54 public void test_getMetadataBy_shouldReturnMetadataForExistingCountryCode() { 55 MapBackedMetadataContainer<Integer> metadataContainer = 56 MapBackedMetadataContainer.byCountryCallingCode(); 57 58 metadataContainer.accept(PHONE_METADATA); 59 60 assertSame(PHONE_METADATA, metadataContainer.getMetadataBy(COUNTRY_CODE)); 61 } 62 } 63