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

Commit 54d95c52 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixs test failed due to resource problem" into main

parents 1c083542 a90f6479
Loading
Loading
Loading
Loading
+50 −41
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.settings.network.telephony.satellite.SatelliteSettingF
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
@@ -40,9 +41,9 @@ import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.widget.FooterPreference;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@@ -56,6 +57,8 @@ public class SatelliteSettingFooterControllerTest {

    @Mock
    private TelephonyManager mTelephonyManager;
    @Mock
    FooterPreference mFooterPreference;

    private Context mContext;
    private SatelliteSettingFooterController mController;
@@ -77,58 +80,64 @@ public class SatelliteSettingFooterControllerTest {
    @Test
    public void displayPreferenceScreen_updateContent_hasBasicContent() {
        PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
        FooterPreference preference = new FooterPreference(mContext);
        preference.setKey(KEY_FOOTER_PREFERENCE);
        screen.addPreference(preference);
        when(mFooterPreference.getKey()).thenReturn(KEY_FOOTER_PREFERENCE);
        screen.addPreference(mFooterPreference);
        mController.init(TEST_SUB_ID, mPersistableBundle);

        mController.displayPreference(screen);
        String summary = preference.getSummary().toString();

        assertThat(summary.contains(ResourcesUtils.getResourcesString(mContext,
        ArgumentCaptor<CharSequence> summary = ArgumentCaptor.forClass(CharSequence.class);
        verify(mFooterPreference).setSummary(summary.capture());
        assertThat(
                summary.getValue().toString().contains(ResourcesUtils.getResourcesString(mContext,
                        "satellite_footer_content_section_0"))).isTrue();
        assertThat(summary.contains(ResourcesUtils.getResourcesString(mContext,
        assertThat(
                summary.getValue().toString().contains(ResourcesUtils.getResourcesString(mContext,
                        "satellite_footer_content_section_1"))).isTrue();
        assertThat(summary.contains(ResourcesUtils.getResourcesString(mContext,
        assertThat(
                summary.getValue().toString().contains(ResourcesUtils.getResourcesString(mContext,
                        "satellite_footer_content_section_2"))).isTrue();
        assertThat(summary.contains(ResourcesUtils.getResourcesString(mContext,
        assertThat(
                summary.getValue().toString().contains(ResourcesUtils.getResourcesString(mContext,
                        "satellite_footer_content_section_3"))).isTrue();
        assertThat(summary.contains(ResourcesUtils.getResourcesString(mContext,
        assertThat(
                summary.getValue().toString().contains(ResourcesUtils.getResourcesString(mContext,
                        "satellite_footer_content_section_4"))).isTrue();
        assertThat(summary.contains(ResourcesUtils.getResourcesString(mContext,
        assertThat(
                summary.getValue().toString().contains(ResourcesUtils.getResourcesString(mContext,
                        "satellite_footer_content_section_5"))).isTrue();
    }


    @Test
    public void displayPreferenceScreen_noEmergencyMsgSupport_hasEmergencyContent() {
        mPersistableBundle.putBoolean(KEY_EMERGENCY_MESSAGING_SUPPORTED_BOOL, false);
        PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
        FooterPreference preference = new FooterPreference(mContext);
        preference.setKey(KEY_FOOTER_PREFERENCE);
        screen.addPreference(preference);
        when(mFooterPreference.getKey()).thenReturn(KEY_FOOTER_PREFERENCE);
        screen.addPreference(mFooterPreference);
        mController.init(TEST_SUB_ID, mPersistableBundle);

        mController.displayPreference(screen);
        String summary = preference.getSummary().toString();

        assertThat(summary.contains(ResourcesUtils.getResourcesString(mContext,
        ArgumentCaptor<CharSequence> summary = ArgumentCaptor.forClass(CharSequence.class);
        verify(mFooterPreference).setSummary(summary.capture());
        assertThat(
                summary.getValue().toString().contains(ResourcesUtils.getResourcesString(mContext,
                        "satellite_footer_content_section_6"))).isTrue();
    }

    @Test
    @Ignore("b/405279842")
    public void displayPreferenceScreen_emergencyMsgSupport_noEmergencyContent() {
        mPersistableBundle.putBoolean(KEY_EMERGENCY_MESSAGING_SUPPORTED_BOOL, true);
        PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
        FooterPreference preference = new FooterPreference(mContext);
        preference.setKey(KEY_FOOTER_PREFERENCE);
        screen.addPreference(preference);
        when(mFooterPreference.getKey()).thenReturn(KEY_FOOTER_PREFERENCE);
        screen.addPreference(mFooterPreference);
        mController.init(TEST_SUB_ID, mPersistableBundle);

        mController.displayPreference(screen);
        String summary = preference.getSummary().toString();

        assertThat(summary.contains(ResourcesUtils.getResourcesString(mContext,
        ArgumentCaptor<CharSequence> summary = ArgumentCaptor.forClass(CharSequence.class);
        verify(mFooterPreference).setSummary(summary.capture());
        assertThat(summary.toString().contains(ResourcesUtils.getResourcesString(mContext,
                "satellite_footer_content_section_6"))).isFalse();
    }

@@ -136,29 +145,29 @@ public class SatelliteSettingFooterControllerTest {
    public void displayPreferenceScreen_entitlementSupport_hasEntitlementContent() {
        mPersistableBundle.putBoolean(KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, true);
        PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
        FooterPreference preference = new FooterPreference(mContext);
        preference.setKey(KEY_FOOTER_PREFERENCE);
        screen.addPreference(preference);
        when(mFooterPreference.getKey()).thenReturn(KEY_FOOTER_PREFERENCE);
        screen.addPreference(mFooterPreference);
        mController.init(TEST_SUB_ID, mPersistableBundle);

        mController.displayPreference(screen);
        String summary = preference.getSummary().toString();

        assertThat(summary.contains(TEST_OPERATOR_NAME)).isTrue();
        ArgumentCaptor<CharSequence> summary = ArgumentCaptor.forClass(CharSequence.class);
        verify(mFooterPreference).setSummary(summary.capture());
        assertThat(summary.getValue().toString().contains(TEST_OPERATOR_NAME)).isTrue();
    }

    @Test
    public void displayPreferenceScreen_entitlementNotSupport_noEntitlementContent() {
        mPersistableBundle.putBoolean(KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL, false);
        PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
        FooterPreference preference = new FooterPreference(mContext);
        preference.setKey(KEY_FOOTER_PREFERENCE);
        screen.addPreference(preference);
        when(mFooterPreference.getKey()).thenReturn(KEY_FOOTER_PREFERENCE);
        screen.addPreference(mFooterPreference);
        mController.init(TEST_SUB_ID, mPersistableBundle);

        mController.displayPreference(screen);
        String summary = preference.getSummary().toString();

        assertThat(summary.contains(TEST_OPERATOR_NAME)).isFalse();
        ArgumentCaptor<CharSequence> summary = ArgumentCaptor.forClass(CharSequence.class);
        verify(mFooterPreference).setSummary(summary.capture());
        assertThat(summary.getValue().toString().contains(TEST_OPERATOR_NAME)).isFalse();
    }
}