Android Open Source - sleep-timer Main Activity 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 www .  j  a  v a2  s.  c o m
Distributed under the MIT License: http://opensource.org/licenses/MIT
 */

package com.oldsneerjaw.sleeptimer;

import android.content.Intent;
import android.test.ActivityUnitTestCase;

import java.util.Calendar;
import java.util.Date;

/**
 * Test cases for {@link MainActivity}.
 *
 * @author Joel Andrews
 */
public class MainActivityTest extends ActivityUnitTestCase<MainActivity> {

    private MainActivity activity;

    public MainActivityTest() {
        super(MainActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        Intent intent = new Intent(getInstrumentation().getTargetContext(), MainActivity.class);
        activity = startActivity(intent, null, null);
    }

    public void testGetActivityIntent_NoScheduledTime() {
        Date now = new Date(0);
        Intent result = activity.getActivityIntent(now, null);

        assertEquals(activity.getPackageName(), result.getComponent().getPackageName());
        assertEquals(SetTimerActivity.class.getName(), result.getComponent().getClassName());
    }

    public void testGetActivityIntent_FutureScheduledTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);

        calendar.set(2013, Calendar.AUGUST, 5, 15, 53, 48);
        Date now = calendar.getTime();

        calendar.set(2014, Calendar.SEPTEMBER, 6, 16, 54, 49);
        Date scheduledTime = calendar.getTime();

        Intent result = activity.getActivityIntent(now, scheduledTime);

        assertEquals(activity.getPackageName(), result.getComponent().getPackageName());
        assertEquals(CountdownActivity.class.getName(), result.getComponent().getClassName());
    }

    public void testGetActivityIntent_PastScheduledTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);

        calendar.set(2013, Calendar.AUGUST, 5, 15, 53, 48);
        Date now = calendar.getTime();

        calendar.set(2012, Calendar.JULY, 4, 14, 52, 47);
        Date scheduledTime = calendar.getTime();

        Intent result = activity.getActivityIntent(now, scheduledTime);

        assertEquals(activity.getPackageName(), result.getComponent().getPackageName());
        assertEquals(SetTimerActivity.class.getName(), result.getComponent().getClassName());
    }

    public void testGetActivityIntent_PresentScheduledTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(2013, Calendar.AUGUST, 5, 15, 53, 48);

        Date now = calendar.getTime();
        Date scheduledTime = calendar.getTime();

        Intent result = activity.getActivityIntent(now, scheduledTime);

        // Since "now" and the scheduled time are the same, we should be taken to schedule a new timer
        assertEquals(activity.getPackageName(), result.getComponent().getPackageName());
        assertEquals(SetTimerActivity.class.getName(), result.getComponent().getClassName());
    }
}




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