1 /**
2  * Copyright (C) 2022 The Android Open Source Project
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.android.telephony.imsmedia;
18 
19 import static org.junit.Assert.fail;
20 import static org.mockito.Mockito.doReturn;
21 import static org.mockito.Mockito.verify;
22 
23 import android.os.IBinder;
24 import android.telephony.ims.RtpHeaderExtension;
25 import android.telephony.imsmedia.AudioConfig;
26 import android.telephony.imsmedia.IImsAudioSession;
27 import android.telephony.imsmedia.ImsAudioSession;
28 import android.telephony.imsmedia.MediaQualityThreshold;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 
35 import java.util.ArrayList;
36 import java.util.List;
37 
38 public class ImsAudioSessionTest {
39 
40     static final int AUDIO_SESSION_ID = 1;
41 
42     @Mock
43     IImsAudioSession mMockIImsAudioSession;
44 
45     @Mock
46     IBinder mMockIBinder;
47 
48     @Before
setUp()49     public void setUp() throws Exception {
50         MockitoAnnotations.initMocks(this);
51         doReturn(mMockIBinder).when(mMockIImsAudioSession).asBinder();
52     }
53 
54     @Test
testConstructorAndApis()55     public void testConstructorAndApis() {
56         ImsAudioSession imsAudioSession = new ImsAudioSession(mMockIImsAudioSession);
57 
58         imsAudioSession.getBinder();
59         imsAudioSession.getSessionId();
60 
61         AudioConfig audioConfig = new AudioConfig.Builder().build();
62         imsAudioSession.addConfig(audioConfig);
63         imsAudioSession.deleteConfig(audioConfig);
64         imsAudioSession.modifySession(audioConfig);
65         imsAudioSession.confirmConfig(audioConfig);
66 
67         MediaQualityThreshold threshold = new MediaQualityThreshold.Builder().build();
68         imsAudioSession.setMediaQualityThreshold(threshold);
69 
70         imsAudioSession.sendDtmf('1', 10);
71 
72         List<RtpHeaderExtension> extensions = new ArrayList<RtpHeaderExtension>();
73         imsAudioSession.sendHeaderExtension(extensions);
74 
75         try {
76             verify(mMockIImsAudioSession).asBinder();
77             verify(mMockIImsAudioSession).getSessionId();
78             verify(mMockIImsAudioSession).addConfig(audioConfig);
79             verify(mMockIImsAudioSession).deleteConfig(audioConfig);
80             verify(mMockIImsAudioSession).modifySession(audioConfig);
81             verify(mMockIImsAudioSession).confirmConfig(audioConfig);
82             verify(mMockIImsAudioSession).setMediaQualityThreshold(threshold);
83             verify(mMockIImsAudioSession).sendDtmf('1', 10);
84             verify(mMockIImsAudioSession).sendHeaderExtension(extensions);
85         } catch (Exception e) {
86             fail(e.getMessage());
87         }
88     }
89 }
90