mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-17 11:19:01 +00:00
Added fixes for task alarm manager tests
This commit is contained in:
parent
0f70acc650
commit
729034ee24
5 changed files with 187 additions and 22 deletions
140
Habitica/AndroidManifestTesting.xml
Normal file
140
Habitica/AndroidManifestTesting.xml
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.habitrpg.android.habitica"
|
||||
android:versionCode="104"
|
||||
android:versionName="0.0.32"
|
||||
android:screenOrientation="portrait"
|
||||
android:installLocation="auto" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="15"
|
||||
android:targetSdkVersion="24" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
||||
<application
|
||||
android:name=".HabiticaApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".ui.activities.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="stateHidden|adjustPan"
|
||||
android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.PrefsActivity"
|
||||
android:parentActivityName=".ui.activities.MainActivity"
|
||||
android:label="@string/PS_settings_title"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="UnusedAttribute">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.LoginActivity"
|
||||
android:label="@string/LoginActivityName"
|
||||
android:theme="@style/AppThemeWithActionBarBlackText"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:screenOrientation="portrait">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.IntroActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:screenOrientation="portrait">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.SetupActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:screenOrientation="portrait">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.SkillTasksActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.activities.AboutActivity"
|
||||
android:theme="@style/AppThemeWithActionBarBlackText"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name=".ui.activities.TaskFormActivity"
|
||||
android:theme="@style/AppThemeWithActionBarBlackText"
|
||||
android:parentActivityName=".ui.activities.MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ui.activities.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.GroupFormActivity"
|
||||
android:theme="@style/AppThemeWithActionBarBlackText"
|
||||
android:parentActivityName=".ui.activities.MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ui.activities.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.ClassSelectionActivity"
|
||||
android:theme="@style/AppThemeWithActionBarBlackText"
|
||||
android:parentActivityName=".ui.activities.MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="UnusedAttribute"
|
||||
android:label="@string/select_class">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ui.activities.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.PartyInviteActivity"
|
||||
android:theme="@style/AppThemeWithActionBarBlackText"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="UnusedAttribute"
|
||||
android:label="@string/invite_users">
|
||||
</activity>
|
||||
<activity android:name="com.facebook.FacebookActivity"
|
||||
android:configChanges=
|
||||
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:label="@string/app_name" />
|
||||
<activity android:name=".ui.activities.MaintenanceActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
|
||||
<receiver android:process=":remote" android:name=".NotificationPublisher" />
|
||||
|
||||
<receiver android:process=":remote" android:name=".receivers.TaskReceiver"></receiver>
|
||||
<receiver android:name=".receivers.TaskAlarmBootReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action._BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="com.habitrpg.android.habitica.fileprovider"
|
||||
android:grantUriPermissions="true"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/filepaths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -183,7 +183,7 @@ android {
|
|||
assets.srcDirs = ['assets']
|
||||
}
|
||||
robolectric {
|
||||
manifest.srcFile 'AndroidManifest.xml'
|
||||
manifest.srcFile 'AndroidManifestTesting.xml'
|
||||
java.srcDir file('src/test/java/')
|
||||
res.srcDirs = ['res']
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,7 +130,11 @@ public class HabiticaApplication extends MultiDexApplication {
|
|||
setupCrashlytics();
|
||||
createBillingAndCheckout();
|
||||
registerActivityLifecycleCallbacks();
|
||||
Amplitude.getInstance().initialize(this, getString(R.string.amplitude_app_id)).enableForegroundTracking(this);
|
||||
|
||||
if (!BuildConfig.DEBUG) {
|
||||
Amplitude.getInstance().initialize(this, getString(R.string.amplitude_app_id)).enableForegroundTracking(this);
|
||||
}
|
||||
|
||||
Fresco.initialize(this);
|
||||
checkIfNewVersion();
|
||||
}
|
||||
|
|
@ -178,7 +182,9 @@ public class HabiticaApplication extends MultiDexApplication {
|
|||
}
|
||||
|
||||
private void setupFacebookSdk() {
|
||||
FacebookSdk.sdkInitialize(getApplicationContext());
|
||||
if (!BuildConfig.DEBUG) {
|
||||
FacebookSdk.sdkInitialize(getApplicationContext());
|
||||
}
|
||||
}
|
||||
|
||||
private void setupCrashlytics() {
|
||||
|
|
|
|||
|
|
@ -603,7 +603,7 @@ public class Task extends BaseModel {
|
|||
Calendar newTime = new GregorianCalendar();
|
||||
newTime.setTime(oldTime);
|
||||
|
||||
if (this.getFrequency().equals(FREQUENCY_DAILY) && (newTime.before(today) || newTime.equals(today))) {
|
||||
if (this.getFrequency().equals(FREQUENCY_DAILY) ) {
|
||||
Calendar startDate = new GregorianCalendar();
|
||||
startDate.setTime(this.getStartDate());
|
||||
|
||||
|
|
@ -611,7 +611,9 @@ public class Task extends BaseModel {
|
|||
long diffInMillies = today.getTimeInMillis() - startDate.getTimeInMillis();
|
||||
long daySinceStart = timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
long daysUntilNextReminder = this.getEveryX() - (daySinceStart % this.getEveryX());
|
||||
newTime.add(Calendar.DATE, (int) daysUntilNextReminder);
|
||||
|
||||
today.add(Calendar.DATE, (int) daysUntilNextReminder);
|
||||
newTime.setTime(today.getTime());
|
||||
} else {
|
||||
int nextActiveDayOfTheWeek = newTime.get(Calendar.DAY_OF_WEEK);
|
||||
while (!this.getRepeat().getForDay(nextActiveDayOfTheWeek) || newTime.before(today) || newTime.equals(today)) {
|
||||
|
|
|
|||
|
|
@ -21,12 +21,14 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
|
@ -35,6 +37,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
* Created by keithholliday on 7/16/16.
|
||||
*/
|
||||
|
||||
@Config(manifest = "AndroidManifestTesting.xml")
|
||||
@RunWith(value = RobolectricTestRunner.class)
|
||||
public class TaskAlarmManagerTest {
|
||||
private TaskAlarmManager taskAlarmManager;
|
||||
|
|
@ -59,6 +62,8 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
List<RemindersItem> reminders = new ArrayList<RemindersItem>();
|
||||
RemindersItem remindersItem1 = new RemindersItem();
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
remindersItem1.setId(randomUUID.toString());
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1);
|
||||
|
|
@ -71,14 +76,13 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
taskAlarmManager.setAlarmsForTask(task);
|
||||
|
||||
Integer alarmId = reminders.get(0).getAlarmId();
|
||||
|
||||
int intentId = remindersItem1.getId().hashCode() & 0xfffffff;
|
||||
Intent intent = new Intent(context, TaskReceiver.class);
|
||||
intent.setAction(remindersItem1.getAlarmId().toString());
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
intent.setAction(remindersItem1.getId());
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, intentId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
boolean alarmUp = sender != null;
|
||||
|
||||
Assert.assertNotNull(alarmId);
|
||||
Assert.assertNotNull(intentId);
|
||||
Assert.assertEquals(true, alarmUp);
|
||||
}
|
||||
|
||||
|
|
@ -89,6 +93,8 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
List<RemindersItem> reminders = new ArrayList<RemindersItem>();
|
||||
RemindersItem remindersItem1 = new RemindersItem();
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
remindersItem1.setId(randomUUID.toString());
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1);
|
||||
|
|
@ -101,9 +107,9 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
taskAlarmManager.setAlarmsForTask(task);
|
||||
|
||||
Integer alarmId = reminders.get(0).getAlarmId();
|
||||
int alarmId = remindersItem1.getId().hashCode() & 0xfffffff;
|
||||
Intent intent = new Intent(context, TaskReceiver.class);
|
||||
intent.setAction(remindersItem1.getAlarmId().toString());
|
||||
intent.setAction(remindersItem1.getId());
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
boolean alarmUp = sender != null;
|
||||
|
||||
|
|
@ -127,7 +133,7 @@ public class TaskAlarmManagerTest {
|
|||
}
|
||||
|
||||
taskAlarmManager.setAlarmsForTask(task);
|
||||
Integer newAlarmId = reminders.get(0).getAlarmId();
|
||||
int newAlarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
PendingIntent senderNew = PendingIntent.getBroadcast(context, newAlarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
boolean alarmUpNew = senderNew != null;
|
||||
|
||||
|
|
@ -192,6 +198,8 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
List<RemindersItem> reminders = new ArrayList<RemindersItem>();
|
||||
RemindersItem remindersItem1 = new RemindersItem();
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
remindersItem1.setId(randomUUID.toString());
|
||||
|
||||
//We try to set a reminder on Tuesday, but the manager will correct this to Monday
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
|
@ -206,13 +214,13 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
taskAlarmManager.setAlarmsForTask(task);
|
||||
|
||||
Integer alarmId = reminders.get(0).getAlarmId();
|
||||
int alarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
|
||||
Calendar newReminderTime = Calendar.getInstance();
|
||||
newReminderTime.setTime(reminders.get(0).getTime());
|
||||
|
||||
Intent intent = new Intent(context, TaskReceiver.class);
|
||||
intent.setAction(remindersItem1.getAlarmId().toString());
|
||||
intent.setAction(remindersItem1.getId());
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
boolean alarmUp = sender != null;
|
||||
|
||||
|
|
@ -240,6 +248,8 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
List<RemindersItem> reminders = new ArrayList<RemindersItem>();
|
||||
RemindersItem remindersItem1 = new RemindersItem();
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
remindersItem1.setId(randomUUID.toString());
|
||||
|
||||
//We try to set a reminder for now, but by the manager will correct (because the seconds will be different)
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
|
@ -252,13 +262,13 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
taskAlarmManager.setAlarmsForTask(task);
|
||||
|
||||
Integer alarmId = reminders.get(0).getAlarmId();
|
||||
int alarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
|
||||
Calendar newReminderTime = Calendar.getInstance();
|
||||
newReminderTime.setTime(reminders.get(0).getTime());
|
||||
|
||||
Intent intent = new Intent(context, TaskReceiver.class);
|
||||
intent.setAction(remindersItem1.getAlarmId().toString());
|
||||
intent.setAction(remindersItem1.getId());
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
boolean alarmUp = sender != null;
|
||||
|
||||
|
|
@ -278,13 +288,18 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
List<RemindersItem> reminders = new ArrayList<RemindersItem>();
|
||||
RemindersItem remindersItem1 = new RemindersItem();
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
remindersItem1.setId(randomUUID.toString());
|
||||
|
||||
//We try to set a reminder one day after the start date, but the manager will correct since the
|
||||
// daily is every 2 days from above
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int currentDayOfTheWeek = cal.get(Calendar.DAY_OF_WEEK);
|
||||
|
||||
task.setStartDate(cal.getTime());
|
||||
|
||||
cal.set(Calendar.DAY_OF_WEEK, currentDayOfTheWeek + 1);
|
||||
cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1);
|
||||
cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE));
|
||||
|
||||
remindersItem1.setTime(cal.getTime());
|
||||
reminders.add(remindersItem1);
|
||||
|
|
@ -294,13 +309,13 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
taskAlarmManager.setAlarmsForTask(task);
|
||||
|
||||
Integer alarmId = reminders.get(0).getAlarmId();
|
||||
int alarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
|
||||
Calendar newReminderTime = Calendar.getInstance();
|
||||
newReminderTime.setTime(reminders.get(0).getTime());
|
||||
|
||||
Intent intent = new Intent(context, TaskReceiver.class);
|
||||
intent.setAction(remindersItem1.getAlarmId().toString());
|
||||
intent.setAction(remindersItem1.getId());
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
boolean alarmUp = sender != null;
|
||||
|
||||
|
|
@ -321,6 +336,8 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
List<RemindersItem> reminders = new ArrayList<RemindersItem>();
|
||||
RemindersItem remindersItem1 = new RemindersItem();
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
remindersItem1.setId(randomUUID.toString());
|
||||
|
||||
//We try to set a reminder for now, but the manager will correct since the seconds will be off
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
|
@ -334,13 +351,13 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
taskAlarmManager.setAlarmsForTask(task);
|
||||
|
||||
Integer alarmId = reminders.get(0).getAlarmId();
|
||||
int alarmId = reminders.get(0).getId().hashCode() & 0xfffffff;
|
||||
|
||||
Calendar newReminderTime = Calendar.getInstance();
|
||||
newReminderTime.setTime(reminders.get(0).getTime());
|
||||
|
||||
Intent intent = new Intent(context, TaskReceiver.class);
|
||||
intent.setAction(remindersItem1.getAlarmId().toString());
|
||||
intent.setAction(remindersItem1.getId());
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_NO_CREATE);
|
||||
boolean alarmUp = sender != null;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue