Skip to content

Commit

Permalink
Merge pull request #5 from physphil/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
physphil authored Jun 17, 2018
2 parents 1434bf2 + 441e7d7 commit 0a43b48
Show file tree
Hide file tree
Showing 34 changed files with 806 additions and 364 deletions.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions .idea/compiler.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/encodings.xml

This file was deleted.

59 changes: 4 additions & 55 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ dependencies {
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'android.arch.lifecycle:extensions:1.0.0'
kapt 'android.arch.lifecycle:compiler:1.0.0'
implementation 'android.arch.lifecycle:extensions:1.1.0'
kapt 'android.arch.lifecycle:compiler:1.1.0'
implementation 'android.arch.persistence.room:runtime:1.0.0'
kapt 'android.arch.persistence.room:compiler:1.0.0'
implementation 'android.arch.persistence.room:rxjava2:1.0.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'

implementation 'com.evernote:android-job:1.2.1'
implementation 'com.jakewharton:butterknife:8.8.1'
Expand All @@ -50,10 +52,13 @@ dependencies {
debugImplementation 'com.facebook.stetho:stetho:1.5.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.13.0'
testImplementation 'android.arch.core:core-testing:1.0.0'
testImplementation 'org.mockito:mockito-core:2.15.0'
testImplementation 'android.arch.core:core-testing:1.1.0'
testImplementation 'android.arch.persistence.room:testing:1.0.0'

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'android.arch.core:core-testing:1.1.0'
}

apply plugin: 'kotlin-android-extensions'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package com.physphil.android.remindme

import android.arch.core.executor.testing.InstantTaskExecutorRule
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.physphil.android.remindme.room.AppDatabase
import com.physphil.android.remindme.room.ReminderDao
import com.physphil.android.remindme.room.entities.Reminder
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.Calendar

private const val TITLE = "Watch The Wire"
private const val NEW_TITLE = "Watch Seinfeld"
private const val EXTERNAL_ID = 3
private const val NEW_EXTERNAL_ID = 4
private const val TIME = 5000L
private const val NEW_TIME = 10000L
private const val NOTIFICATION_ID = 9
private const val NEW_NOTIFICATION_ID = 10

/**
* Copyright (c) 2018 Phil Shadlyn
*/
@RunWith(AndroidJUnit4::class)
class ReminderDaoTest {

private lateinit var dao: ReminderDao
private lateinit var db: AppDatabase

@get: Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()

@Before
fun createDb() {
db = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getTargetContext(), AppDatabase::class.java)
.allowMainThreadQueries()
.build()
dao = db.reminderDao()
}

@After
fun closeDb() {
db.close()
}

@Test
fun testGetEmptyReminderList() {
dao.getAllReminders()
.test()
.assertValue({ it.isEmpty() })
}

@Test
fun testGetReminderList() {
val time = Calendar.getInstance()
time.timeInMillis = System.currentTimeMillis() + 60000 * 5 // set each reminder 5 minutes in future
dao.insertReminder(Reminder(time = time))
dao.insertReminder(Reminder(time = time))
dao.getAllReminders()
.test()
.assertValue({ it.size == 2 })
}

@Test
fun testGetReminderById() {
val reminder = Reminder(title = TITLE)
val id = reminder.id
dao.insertReminder(reminder)
dao.insertReminder(Reminder())
dao.insertReminder(Reminder())

dao.getReminderById(id)
.test()
.assertValue({ it.id == id })
.assertValue({ it.title == TITLE })
}

@Test
fun testGetReminderByInvalidId() {
dao.insertReminder(Reminder())
dao.insertReminder(Reminder())
dao.insertReminder(Reminder())

dao.getReminderById("123")
.test()
.assertNoValues()
}

@Test
fun testDeleteAllReminders() {
val time = Calendar.getInstance()
time.timeInMillis = System.currentTimeMillis() + 60000 * 5 // set each reminder 5 minutes in future
dao.insertReminder(Reminder(time = time))
dao.insertReminder(Reminder(time = time))
dao.insertReminder(Reminder(time = time))

dao.getAllReminders()
.test()
.assertValue({ it.size == 3 })

dao.deleteAllReminders()
dao.getAllReminders()
.test()
.assertValue( { it.isEmpty() })
}

@Test
fun testDeleteReminder() {
val reminder = Reminder()
dao.insertReminder(reminder)

dao.getReminderById(reminder.id)
.test()
.assertValueCount(1)

dao.deleteReminder(reminder)
dao.getReminderById(reminder.id)
.test()
.assertNoValues()
}

@Test
fun testUpdateReminder() {
val reminder = Reminder(title = TITLE)
val id = reminder.id
dao.insertReminder(reminder)

dao.getReminderById(id)
.test()
.assertValue({ it.title == TITLE })

reminder.title = NEW_TITLE
dao.updateReminder(reminder)

dao.getReminderById(id)
.test()
.assertValue({ it.title == NEW_TITLE })
}

@Test
fun testUpdateRecurringReminder() {
val time = Calendar.getInstance()
time.timeInMillis = TIME
val reminder = Reminder(time = time, externalId = EXTERNAL_ID)
dao.insertReminder(reminder)

dao.updateRecurringReminder(reminder.id, NEW_EXTERNAL_ID, NEW_TIME)
dao.getReminderById(reminder.id)
.test()
.assertValueCount(1)
.assertValue({ it.externalId == NEW_EXTERNAL_ID })
.assertValue({ it.time.timeInMillis == NEW_TIME })
}

@Test
fun testUpdateNotificationId() {
val reminder = Reminder(notificationId = NOTIFICATION_ID)
dao.insertReminder(reminder)

dao.updateNotificationId(reminder.id, NEW_NOTIFICATION_ID)
dao.getReminderById(reminder.id)
.test()
.assertValueCount(1)
.assertValue({ it.notificationId == NEW_NOTIFICATION_ID })
}
}
10 changes: 8 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
</activity>

<activity
android:name=".reminders.ReminderActivity"
android:parentActivityName=".MainActivity"/>

<receiver
android:name=".job.SnoozeBroadcastReceiver"
android:enabled="true"
android:exported="false">
</receiver>

</application>

</manifest>
Loading

0 comments on commit 0a43b48

Please sign in to comment.