diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-02-12 10:37:35 -0800 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2016-02-12 16:25:04 -0800 |
commit | 054559b6c279a0149ac6473d1897f6db817c5a57 (patch) | |
tree | 9e61a9bf511d4fe77355c515514fc564a6c1fe89 /InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java | |
parent | 37274fedfe39d25ac91acb80c41d15aa78adc0f1 (diff) |
Integrating DialerRingtoneManager and InCallTonePlayer
This change makes the Call Waiting tone actually play during the
Call Waiting use case.
+ Plugging InCallTonePlayer into the DialerRingtoneManager in the
StatusBarNotifier
+ Test fixes
+ Added tests for when Dialer ringing is disabled
+ Added tests for DialerRingtoneManager#playCallWaitingTone
- Removed unneeded @NeededForTesting annotations from InCallTonePlayer
since they won't be stipped out by proguard.
Change-Id: I49a83d2a7fe6edf5f9ec88db973a5f37e307f23a
Diffstat (limited to 'InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java')
-rw-r--r-- | InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java | 153 |
1 files changed, 134 insertions, 19 deletions
diff --git a/InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java b/InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java index e116a19fb..01db20272 100644 --- a/InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java +++ b/InCallUI/tests/src/com/android/incallui/ringtone/DialerRingtoneManagerTest.java @@ -13,78 +13,129 @@ * See the License for the specific language governing permissions and * limitations under the License */ + package com.android.incallui.ringtone; import android.media.RingtoneManager; +import android.net.Uri; import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; import com.android.contacts.common.compat.CompatUtils; +import com.android.incallui.Call; import com.android.incallui.Call.State; +import com.android.incallui.CallList; + +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +@SmallTest public class DialerRingtoneManagerTest extends AndroidTestCase { - private DialerRingtoneManager mRingtoneManager; + private static final Uri RINGTONE_URI = RingtoneManager + .getDefaultUri(RingtoneManager.TYPE_RINGTONE); + + @Mock private InCallTonePlayer mInCallTonePlayer; + @Mock private CallList mCallList; + @Mock private Call mCall; + private DialerRingtoneManager mRingtoneManagerEnabled; + private DialerRingtoneManager mRingtoneManagerDisabled; @Override - public void setUp() { - mRingtoneManager = new DialerRingtoneManager(); - mRingtoneManager.forceDialerRingingEnabled(); + public void setUp() throws Exception { + super.setUp(); + MockitoAnnotations.initMocks(this); + mRingtoneManagerEnabled = new DialerRingtoneManager(mInCallTonePlayer, mCallList); + mRingtoneManagerEnabled.setDialerRingingEnabledForTesting(true); + mRingtoneManagerDisabled = new DialerRingtoneManager(mInCallTonePlayer, mCallList); + mRingtoneManagerDisabled.setDialerRingingEnabledForTesting(false); } - @Override - public void tearDown() { - mRingtoneManager = null; + public void testNullInCallTonePlayer() { + try { + new DialerRingtoneManager(null, mCallList); + fail(); + } catch (NullPointerException e) {} + } + + public void testNullCallList() { + try { + new DialerRingtoneManager(mInCallTonePlayer, null); + fail(); + } catch (NullPointerException e) {} } public void testShouldPlayRingtone_M() { if (CompatUtils.isNCompatible()) { return; } - assertFalse(mRingtoneManager.shouldPlayRingtone(0, null)); + assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(0, RINGTONE_URI)); } public void testShouldPlayRingtone_N_NullUri() { if (!CompatUtils.isNCompatible()) { return; } - assertFalse(mRingtoneManager.shouldPlayRingtone(State.INCOMING, null)); + assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(State.INCOMING, null)); + } + + public void testShouldPlayRingtone_N_Disabled() { + if (!CompatUtils.isNCompatible()) { + return; + } + assertFalse(mRingtoneManagerDisabled.shouldPlayRingtone(State.INCOMING, RINGTONE_URI)); } public void testShouldPlayRingtone_N_NotIncoming() { if (!CompatUtils.isNCompatible()) { return; } - assertFalse(mRingtoneManager.shouldPlayRingtone(State.ACTIVE, null)); + assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(State.ACTIVE, RINGTONE_URI)); } // Specific case for call waiting since that needs its own sound - public void testShouldPlayRingtone_N_CallWaiting() { + public void testShouldPlayRingtone_N_CallWaitingByState() { + if (!CompatUtils.isNCompatible()) { + return; + } + assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(State.CALL_WAITING, RINGTONE_URI)); + } + + public void testShouldPlayRingtone_N_CallWaitingByActiveCall() { if (!CompatUtils.isNCompatible()) { return; } - assertFalse(mRingtoneManager.shouldPlayRingtone(State.CALL_WAITING, null)); + Mockito.when(mCallList.getActiveCall()).thenReturn(mCall); + assertFalse(mRingtoneManagerEnabled.shouldPlayRingtone(State.INCOMING, RINGTONE_URI)); } public void testShouldPlayRingtone_N() { if (!CompatUtils.isNCompatible()) { return; } - assertTrue(mRingtoneManager.shouldPlayRingtone(State.INCOMING, - RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE))); + assertTrue(mRingtoneManagerEnabled.shouldPlayRingtone(State.INCOMING, RINGTONE_URI)); } public void testShouldPlayCallWaitingTone_M() { if (CompatUtils.isNCompatible()) { return; } - assertFalse(mRingtoneManager.shouldPlayCallWaitingTone(0)); + assertFalse(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(0)); + } + + public void testShouldPlayCallWaitingTone_N_Disabled() { + if (!CompatUtils.isNCompatible()) { + return; + } + assertFalse(mRingtoneManagerDisabled.shouldPlayCallWaitingTone(State.CALL_WAITING)); } public void testShouldPlayCallWaitingTone_N_NotCallWaiting() { if (!CompatUtils.isNCompatible()) { return; } - assertFalse(mRingtoneManager.shouldPlayCallWaitingTone(State.ACTIVE)); + assertFalse(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.ACTIVE)); } // Specific case for incoming since it plays its own sound @@ -92,13 +143,77 @@ public class DialerRingtoneManagerTest extends AndroidTestCase { if (!CompatUtils.isNCompatible()) { return; } - assertFalse(mRingtoneManager.shouldPlayCallWaitingTone(State.INCOMING)); + assertFalse(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.INCOMING)); + } + + public void testShouldPlayCallWaitingTone_N_AlreadyPlaying() { + if (!CompatUtils.isNCompatible()) { + return; + } + Mockito.when(mInCallTonePlayer.isPlayingTone()).thenReturn(true); + assertFalse(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.CALL_WAITING)); + } + + public void testShouldPlayCallWaitingTone_N_ByState() { + if (!CompatUtils.isNCompatible()) { + return; + } + assertTrue(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.CALL_WAITING)); + } + + public void testShouldPlayCallWaitingTone_N_ByActiveCall() { + if (!CompatUtils.isNCompatible()) { + return; + } + Mockito.when(mCallList.getActiveCall()).thenReturn(mCall); + assertTrue(mRingtoneManagerEnabled.shouldPlayCallWaitingTone(State.INCOMING)); + } + + public void testPlayCallWaitingTone_M() { + if (CompatUtils.isNCompatible()) { + return; + } + mRingtoneManagerEnabled.playCallWaitingTone(); + Mockito.verify(mInCallTonePlayer, Mockito.never()).play(Mockito.anyInt()); + } + + public void testPlayCallWaitingTone_N_NotEnabled() { + if (!CompatUtils.isNCompatible()) { + return; + } + mRingtoneManagerDisabled.playCallWaitingTone(); + Mockito.verify(mInCallTonePlayer, Mockito.never()).play(Mockito.anyInt()); + } + + public void testPlayCallWaitingTone_N() { + if (!CompatUtils.isNCompatible()) { + return; + } + mRingtoneManagerEnabled.playCallWaitingTone(); + Mockito.verify(mInCallTonePlayer).play(Mockito.anyInt()); + } + + public void testStopCallWaitingTone_M() { + if (CompatUtils.isNCompatible()) { + return; + } + mRingtoneManagerEnabled.stopCallWaitingTone(); + Mockito.verify(mInCallTonePlayer, Mockito.never()).stop(); + } + + public void testStopCallWaitingTone_N_NotEnabled() { + if (!CompatUtils.isNCompatible()) { + return; + } + mRingtoneManagerDisabled.stopCallWaitingTone(); + Mockito.verify(mInCallTonePlayer, Mockito.never()).stop(); } - public void testShouldPlayCallWaitingTone_N() { + public void testStopCallWaitingTone_N() { if (!CompatUtils.isNCompatible()) { return; } - assertTrue(mRingtoneManager.shouldPlayCallWaitingTone(State.CALL_WAITING)); + mRingtoneManagerEnabled.stopCallWaitingTone(); + Mockito.verify(mInCallTonePlayer).stop(); } } |