diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.kt similarity index 56% rename from uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.java rename to uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.kt index d681ba0e0..f6996903f 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.kt @@ -16,32 +16,25 @@ * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ +package org.isoron.uhabits -package org.isoron.uhabits; +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import org.hamcrest.CoreMatchers +import org.hamcrest.MatcherAssert +import org.junit.Test +import org.junit.runner.RunWith +import java.io.IOException -import androidx.test.filters.*; - -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.*; -import org.junit.runner.*; - -import java.io.*; - -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.*; - -@RunWith(AndroidJUnit4.class) +@RunWith(AndroidJUnit4::class) @MediumTest -public class HabitsApplicationTest extends BaseAndroidTest -{ +class HabitsApplicationTest : BaseAndroidTest() { @Test - public void test_getLogcat() throws IOException - { - String msg = "LOGCAT TEST"; - new RuntimeException(msg).printStackTrace(); - - String log = new AndroidBugReporter(targetContext).getLogcat(); - assertThat(log, containsString(msg)); + @Throws(IOException::class) + fun test_getLogcat() { + val msg = "LOGCAT TEST" + RuntimeException(msg).printStackTrace() + val log = AndroidBugReporter(targetContext).getLogcat() + MatcherAssert.assertThat(log, CoreMatchers.containsString(msg)) } } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTestComponent.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTestComponent.kt similarity index 56% rename from uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTestComponent.java rename to uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTestComponent.kt index 8693399c7..751baaae8 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTestComponent.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTestComponent.kt @@ -16,35 +16,17 @@ * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ +package org.isoron.uhabits -package org.isoron.uhabits; - -import org.isoron.uhabits.core.*; -import org.isoron.uhabits.core.tasks.*; -import org.isoron.uhabits.inject.*; -import org.isoron.uhabits.intents.*; - -import dagger.*; +import dagger.Component +import org.isoron.uhabits.core.AppScope +import org.isoron.uhabits.inject.AppContextModule +import org.isoron.uhabits.inject.HabitsApplicationComponent +import org.isoron.uhabits.inject.HabitsModule +import org.isoron.uhabits.intents.IntentScheduler @AppScope -@Component(modules = { - AppContextModule.class, - HabitsModule.class, - SingleThreadModule.class, -}) -public interface HabitsApplicationTestComponent - extends HabitsApplicationComponent -{ - IntentScheduler getIntentScheduler(); -} - -@dagger.Module -class SingleThreadModule -{ - @Provides - @AppScope - static TaskRunner provideTaskRunner() - { - return new SingleThreadTaskRunner(); - } +@Component(modules = [AppContextModule::class, HabitsModule::class, SingleThreadModule::class]) +interface HabitsApplicationTestComponent : HabitsApplicationComponent { + val intentScheduler: IntentScheduler? } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/SingleThreadModule.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/SingleThreadModule.kt new file mode 100644 index 000000000..b07aaee63 --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/SingleThreadModule.kt @@ -0,0 +1,17 @@ +package org.isoron.uhabits + +import dagger.Module +import dagger.Provides +import org.isoron.uhabits.core.AppScope +import org.isoron.uhabits.core.tasks.SingleThreadTaskRunner +import org.isoron.uhabits.core.tasks.TaskRunner + +@Module +internal object SingleThreadModule { + @JvmStatic + @Provides + @AppScope + fun provideTaskRunner(): TaskRunner { + return SingleThreadTaskRunner() + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/intents/IntentSchedulerTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/intents/IntentSchedulerTest.kt index 36a1926bd..eaabde242 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/intents/IntentSchedulerTest.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/intents/IntentSchedulerTest.kt @@ -97,7 +97,7 @@ class IntentSchedulerTest : BaseAndroidTest() { val habit = habitList.getByPosition(0) val scheduler = appComponent.intentScheduler - assertThat(scheduler.scheduleShowReminder(reminderTime, habit, 0), equalTo(OK)) + assertThat(scheduler!!.scheduleShowReminder(reminderTime, habit, 0), equalTo(OK)) setSystemTime("America/Chicago", 2020, JUNE, 2, 22, 44) assertNull(ReminderReceiver.lastReceivedIntent) @@ -116,7 +116,7 @@ class IntentSchedulerTest : BaseAndroidTest() { val updateTime = 1591155900000 // 2020-06-02 22:45:00 (America/Chicago) val scheduler = appComponent.intentScheduler - assertThat(scheduler.scheduleWidgetUpdate(updateTime), equalTo(OK)) + assertThat(scheduler!!.scheduleWidgetUpdate(updateTime), equalTo(OK)) setSystemTime("America/Chicago", 2020, JUNE, 2, 22, 44) assertNull(WidgetReceiver.lastReceivedIntent)