Back to project page sleep-timer.
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.
/* 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()); } }