InCallWakeLockControllerTest.java revision aa383cca668afd8578a6e007c3ea360768dc52f6
1/*
2 * Copyright (C) 2014 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
17package com.android.server.telecom.tests;
18
19import static org.mockito.Mockito.verify;
20import static org.mockito.Mockito.when;
21import static org.mockito.Mockito.never;
22
23import android.content.Context;
24import android.os.PowerManager;
25import android.telecom.CallState;
26
27import com.android.server.telecom.Call;
28import com.android.server.telecom.CallsManager;
29import com.android.server.telecom.InCallWakeLockController;
30
31import org.mockito.Mock;
32
33/**
34 * TODO: The tests here are disabled because they depend on classes {@code PowerManager} and
35 * {@code PowerManager.WakeLock}, which are both {@code final} and therefore cannot easily be
36 * mocked.
37 *
38 * At the moment, we are using an {@link com.android.server.telecom.InCallWakeLockControllerFactory}
39 * in the system under test to abstract out this class, and are assuming it's simple enough that it
40 * is not the highest priority to test.
41 */
42public class InCallWakeLockControllerTest extends TelecomTestCase {
43
44    @Mock Context mContext;
45    @Mock PowerManager mPowerManager;
46    @Mock PowerManager.WakeLock mWakeLock;
47    @Mock CallsManager mCallsManager;
48    @Mock Call mCall;
49
50    private InCallWakeLockController mInCallWakeLockController;
51
52    @Override
53    public void setUp() throws Exception {
54        /*
55        super.setUp();
56
57        when(mContext.getSystemService(Context.POWER_SERVICE)).thenReturn(mPowerManager);
58        when(mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "InCallWakeLockController"))
59                .thenReturn(mWakeLock);
60        mInCallWakeLockController = new InCallWakeLockController(mContext, mCallsManager);
61        */
62    }
63
64    @Override
65    public void tearDown() throws Exception {
66        /*
67        super.tearDown();
68        */
69    }
70
71    public void DONT_test_RingingCallAdded() throws Exception {
72        when(mCallsManager.getRingingCall()).thenReturn(mCall);
73        mInCallWakeLockController.onCallAdded(mCall);
74        verify(mWakeLock).acquire();
75    }
76
77    public void DONT_test_NonRingingCallAdded() throws Exception {
78        when(mCallsManager.getRingingCall()).thenReturn(null);
79        when(mWakeLock.isHeld()).thenReturn(false);
80
81        mInCallWakeLockController.onCallAdded(mCall);
82        verify(mWakeLock, never()).acquire();
83    }
84
85    public void DONT_test_RingingCallTransition() throws Exception {
86        when(mCallsManager.getRingingCall()).thenReturn(mCall);
87        mInCallWakeLockController.onCallStateChanged(mCall, CallState.NEW, CallState.RINGING);
88        verify(mWakeLock).acquire();
89    }
90
91    public void DONT_test_RingingCallRemoved() throws Exception {
92        when(mCallsManager.getRingingCall()).thenReturn(null);
93        when(mWakeLock.isHeld()).thenReturn(false);
94
95        mInCallWakeLockController.onCallRemoved(mCall);
96        verify(mWakeLock, never()).acquire();
97    }
98
99    public void DONT_test_WakeLockReleased() throws Exception {
100        when(mCallsManager.getRingingCall()).thenReturn(null);
101        when(mWakeLock.isHeld()).thenReturn(true);
102
103        mInCallWakeLockController.onCallRemoved(mCall);
104        verify(mWakeLock).release();
105    }
106}
107