Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1f42da8 authored by Geoffrey Boullanger's avatar Geoffrey Boullanger
Browse files

Added test to check that telephonyFinder returns the same countries as MccTable

Flag: EXEMPT adding tests
Test: attest MccTableTest
Bug: 381070025
Change-Id: I0aa4556d8a55c5a663a5817e0f78e26e807aecb4
parent d2be5eb3
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -30,12 +30,14 @@ import android.timezone.TelephonyNetwork;
import android.timezone.TelephonyNetworkFinder;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@@ -53,12 +55,18 @@ public final class MccTable {

    static ArrayList<MccEntry> sTable;

    @VisibleForTesting
    public static List<MccEntry> getAllMccEntries() {
        return new ArrayList<>(sTable);
    }

    /**
     * Container class for mcc and iso. This class implements compareTo so that it can be sorted
     * by mcc.
     */
    public static class MccEntry implements Comparable<MccEntry> {
        final int mMcc;
        @VisibleForTesting
        public final int mMcc;
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q,
                publicAlternatives = "There is no alternative for {@code MccTable.MccEntry.mIso}, "
                        + "but it was included in hidden APIs due to a static analysis false "
+22 −0
Original line number Diff line number Diff line
@@ -19,10 +19,15 @@ package com.android.internal.telephony;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import static org.junit.Assume.assumeTrue;

import android.content.Context;
import android.platform.test.annotations.UsesFlags;
import android.platform.test.flag.junit.FlagsParameterization;
import android.platform.test.flag.junit.SetFlagsRule;
import android.timezone.MobileCountries;
import android.timezone.TelephonyLookup;
import android.timezone.TelephonyNetworkFinder;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -147,6 +152,23 @@ public class MccTableTest {
        assertEquals(2, MccTable.smallestDigitsMccForMnc(2000));
    }

    @Test
    public void telephonyFinder_shouldBeIdenticalToTelephonyMccTable() {
        assumeTrue(Flags.useI18nForMccMapping());
        assumeTrue(com.android.icu.Flags.telephonyLookupMccExtension());

        TelephonyNetworkFinder telephonyNetworkFinder =
                TelephonyLookup.getInstance().getTelephonyNetworkFinder();

        MccTable.getAllMccEntries().forEach(mccEntry -> {
                MobileCountries telephonyCountry =
                        telephonyNetworkFinder.findCountriesByMcc(
                                String.valueOf(mccEntry.mMcc));

                assertEquals(mccEntry.mIso, telephonyCountry.getDefaultCountryIsoCode());
        });
    }

    @SmallTest
    @Test
    public void testNullMcc() throws Exception {