Android Open Source - sleep-timer Pause Music Receiver Test






From Project

Back to project page sleep-timer.

License

The source code is released under:

MIT License

If you think the Android project sleep-timer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
Copyright (c) 2013 Joel Andrews/*from  w ww. j a v  a 2s .  co  m*/
Distributed under the MIT License: http://opensource.org/licenses/MIT
 */

package com.oldsneerjaw.sleeptimer;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.oldsneerjaw.sleeptimer.test.AndroidMockingTestCase;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.mockito.Mockito;

/**
 * Test cases for {@link PauseMusicReceiver}.
 *
 * @author Joel Andrews
 */
public class PauseMusicReceiverTest extends AndroidMockingTestCase {

    public void testPauseMusic() {
        Context mockContext = Mockito.mock(Context.class);
        TimerManager mockTimerManager = Mockito.mock(TimerManager.class);
        CountdownNotifier mockNotifier = Mockito.mock(CountdownNotifier.class);

        new PauseMusicReceiver().pauseMusic(mockContext, mockTimerManager, mockNotifier);

        Mockito.verify(mockTimerManager).cancelTimer();
        Mockito.verify(mockNotifier).cancelNotification();
        Mockito.verify(mockContext).startService(Mockito.argThat(new BaseMatcher<Intent>() {
            @Override
            public boolean matches(Object o) {
                Intent candidate = (Intent) o;

                ComponentName component = candidate.getComponent();
                return TextUtils.equals(PauseMusicService.class.getName(), component.getClassName());
            }

            @Override
            public void describeTo(Description description) {
                // In the event of a test failure, this describes what was expected
                description.appendText("explicit intent to launch " + PauseMusicService.class.getName());
            }
        }));
    }
}




Java Source Code List

com.oldsneerjaw.sleeptimer.CountdownActivity.java
com.oldsneerjaw.sleeptimer.CountdownNotifierTest.java
com.oldsneerjaw.sleeptimer.CountdownNotifier.java
com.oldsneerjaw.sleeptimer.MainActivityTest.java
com.oldsneerjaw.sleeptimer.MainActivity.java
com.oldsneerjaw.sleeptimer.PauseMusicNotifierTest.java
com.oldsneerjaw.sleeptimer.PauseMusicNotifier.java
com.oldsneerjaw.sleeptimer.PauseMusicReceiverTest.java
com.oldsneerjaw.sleeptimer.PauseMusicReceiver.java
com.oldsneerjaw.sleeptimer.PauseMusicServiceTest.java
com.oldsneerjaw.sleeptimer.PauseMusicService.java
com.oldsneerjaw.sleeptimer.SetTimerActivity.java
com.oldsneerjaw.sleeptimer.TimerManagerTest.java
com.oldsneerjaw.sleeptimer.TimerManager.java