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

Commit 1efed246 authored by joonhunshin's avatar joonhunshin Committed by Joonhun Shin
Browse files

Add test function to verify abnormal case.

Add test function to check if the root cause of NPE is correct and to
verify that is has been modified.

Bug: 286447293
Test: atest ImsCallTest
Change-Id: Ie8f6f6a9248bb92e1da784690da0cb84fcccbd82
Merged-In: Ie8f6f6a9248bb92e1da784690da0cb84fcccbd82
parent a15c24b2
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony.imsphone;

import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -237,4 +238,40 @@ public class ImsCallTest extends TelephonyTest {
        assertFalse(mTestImsCall.isWifiCall());
        assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
    }

    @Test
    @SmallTest
    public void testListenerCalledAfterCallClosed() throws Exception {
        ImsCallSession mockSession = mock(ImsCallSession.class);
        ImsCall testImsCall = new ImsCall(mContext, mTestCallProfile);
        ImsCallProfile profile = new ImsCallProfile();
        when(mockSession.getCallProfile()).thenReturn(profile);
        testImsCall.attachSession(mockSession);

        ArgumentCaptor<ImsCallSession.Listener> listenerCaptor =
                ArgumentCaptor.forClass(ImsCallSession.Listener.class);
        verify(mockSession).setListener(listenerCaptor.capture(), any());
        ImsCallSession.Listener listener = listenerCaptor.getValue();
        assertNotNull(listener);

        // Call closed
        testImsCall.close();
        // Set CallProfile value to null because ImsCallSession was closed
        when(mockSession.getCallProfile()).thenReturn(null);

        // Set new profile with direction of none
        ImsStreamMediaProfile newProfile = new ImsStreamMediaProfile(
                ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB,
                ImsStreamMediaProfile.DIRECTION_INACTIVE,
                ImsStreamMediaProfile.VIDEO_QUALITY_NONE,
                ImsStreamMediaProfile.DIRECTION_INACTIVE,
                ImsStreamMediaProfile.RTT_MODE_DISABLED);
        try {
            listener.callSessionProgressing(mockSession, newProfile);
        } catch (Exception e) {
            throw new AssertionError("not expected exception", e);
        }

        assertNull(testImsCall.getCallProfile());
    }
}