mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Convert HabitsApplicationTest
This commit is contained in:
@@ -16,32 +16,25 @@
|
|||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
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.*;
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
|
||||||
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)
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
public class HabitsApplicationTest extends BaseAndroidTest
|
class HabitsApplicationTest : BaseAndroidTest() {
|
||||||
{
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getLogcat() throws IOException
|
@Throws(IOException::class)
|
||||||
{
|
fun test_getLogcat() {
|
||||||
String msg = "LOGCAT TEST";
|
val msg = "LOGCAT TEST"
|
||||||
new RuntimeException(msg).printStackTrace();
|
RuntimeException(msg).printStackTrace()
|
||||||
|
val log = AndroidBugReporter(targetContext).getLogcat()
|
||||||
String log = new AndroidBugReporter(targetContext).getLogcat();
|
MatcherAssert.assertThat(log, CoreMatchers.containsString(msg))
|
||||||
assertThat(log, containsString(msg));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,35 +16,17 @@
|
|||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
package org.isoron.uhabits
|
||||||
|
|
||||||
package org.isoron.uhabits;
|
import dagger.Component
|
||||||
|
import org.isoron.uhabits.core.AppScope
|
||||||
import org.isoron.uhabits.core.*;
|
import org.isoron.uhabits.inject.AppContextModule
|
||||||
import org.isoron.uhabits.core.tasks.*;
|
import org.isoron.uhabits.inject.HabitsApplicationComponent
|
||||||
import org.isoron.uhabits.inject.*;
|
import org.isoron.uhabits.inject.HabitsModule
|
||||||
import org.isoron.uhabits.intents.*;
|
import org.isoron.uhabits.intents.IntentScheduler
|
||||||
|
|
||||||
import dagger.*;
|
|
||||||
|
|
||||||
@AppScope
|
@AppScope
|
||||||
@Component(modules = {
|
@Component(modules = [AppContextModule::class, HabitsModule::class, SingleThreadModule::class])
|
||||||
AppContextModule.class,
|
interface HabitsApplicationTestComponent : HabitsApplicationComponent {
|
||||||
HabitsModule.class,
|
val intentScheduler: IntentScheduler?
|
||||||
SingleThreadModule.class,
|
|
||||||
})
|
|
||||||
public interface HabitsApplicationTestComponent
|
|
||||||
extends HabitsApplicationComponent
|
|
||||||
{
|
|
||||||
IntentScheduler getIntentScheduler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@dagger.Module
|
|
||||||
class SingleThreadModule
|
|
||||||
{
|
|
||||||
@Provides
|
|
||||||
@AppScope
|
|
||||||
static TaskRunner provideTaskRunner()
|
|
||||||
{
|
|
||||||
return new SingleThreadTaskRunner();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -97,7 +97,7 @@ class IntentSchedulerTest : BaseAndroidTest() {
|
|||||||
|
|
||||||
val habit = habitList.getByPosition(0)
|
val habit = habitList.getByPosition(0)
|
||||||
val scheduler = appComponent.intentScheduler
|
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)
|
setSystemTime("America/Chicago", 2020, JUNE, 2, 22, 44)
|
||||||
assertNull(ReminderReceiver.lastReceivedIntent)
|
assertNull(ReminderReceiver.lastReceivedIntent)
|
||||||
@@ -116,7 +116,7 @@ class IntentSchedulerTest : BaseAndroidTest() {
|
|||||||
val updateTime = 1591155900000 // 2020-06-02 22:45:00 (America/Chicago)
|
val updateTime = 1591155900000 // 2020-06-02 22:45:00 (America/Chicago)
|
||||||
|
|
||||||
val scheduler = appComponent.intentScheduler
|
val scheduler = appComponent.intentScheduler
|
||||||
assertThat(scheduler.scheduleWidgetUpdate(updateTime), equalTo(OK))
|
assertThat(scheduler!!.scheduleWidgetUpdate(updateTime), equalTo(OK))
|
||||||
|
|
||||||
setSystemTime("America/Chicago", 2020, JUNE, 2, 22, 44)
|
setSystemTime("America/Chicago", 2020, JUNE, 2, 22, 44)
|
||||||
assertNull(WidgetReceiver.lastReceivedIntent)
|
assertNull(WidgetReceiver.lastReceivedIntent)
|
||||||
|
|||||||
Reference in New Issue
Block a user