mirror of https://github.com/iSoron/uhabits.git
parent
eb8d39fbe3
commit
0f828cbd3a
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.models.memory.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.test.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
import org.mockito.junit.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BaseAndroidJVMTest
|
||||
{
|
||||
protected HabitList habitList;
|
||||
protected HabitFixtures fixtures;
|
||||
protected MemoryModelFactory modelFactory;
|
||||
protected SingleThreadTaskRunner taskRunner;
|
||||
protected CommandRunner commandRunner;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
long fixed_local_time = 1422172800000L;
|
||||
DateUtils.setFixedLocalTime(fixed_local_time);
|
||||
DateUtils.setStartDayOffset(0, 0);
|
||||
modelFactory = new MemoryModelFactory();
|
||||
habitList = spy(modelFactory.buildHabitList());
|
||||
fixtures = new HabitFixtures(modelFactory, habitList);
|
||||
taskRunner = new SingleThreadTaskRunner();
|
||||
commandRunner = new CommandRunner(taskRunner);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
DateUtils.setFixedLocalTime(null);
|
||||
DateUtils.setStartDayOffset(0, 0);
|
||||
}
|
||||
|
||||
public long timestamp(int year, int month, int day)
|
||||
{
|
||||
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
||||
cal.set(year, month, day);
|
||||
return cal.getTimeInMillis();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothing()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.isoron.uhabits
|
||||
|
||||
import org.isoron.uhabits.core.commands.CommandRunner
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
import org.isoron.uhabits.core.models.memory.MemoryModelFactory
|
||||
import org.isoron.uhabits.core.tasks.SingleThreadTaskRunner
|
||||
import org.isoron.uhabits.core.test.HabitFixtures
|
||||
import org.isoron.uhabits.core.utils.DateUtils.Companion.setFixedLocalTime
|
||||
import org.isoron.uhabits.core.utils.DateUtils.Companion.setStartDayOffset
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
open class BaseAndroidJVMTest {
|
||||
private lateinit var habitList: HabitList
|
||||
protected lateinit var fixtures: HabitFixtures
|
||||
private lateinit var modelFactory: MemoryModelFactory
|
||||
private lateinit var taskRunner: SingleThreadTaskRunner
|
||||
private lateinit var commandRunner: CommandRunner
|
||||
|
||||
@Before
|
||||
open fun setUp() {
|
||||
val fixedLocalTime = 1422172800000L
|
||||
setFixedLocalTime(fixedLocalTime)
|
||||
setStartDayOffset(0, 0)
|
||||
modelFactory = MemoryModelFactory()
|
||||
habitList = Mockito.spy(modelFactory.buildHabitList())
|
||||
fixtures = HabitFixtures(modelFactory, habitList)
|
||||
taskRunner = SingleThreadTaskRunner()
|
||||
commandRunner = CommandRunner(taskRunner)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
setFixedLocalTime(null)
|
||||
setStartDayOffset(0, 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nothing() {
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.receivers;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.reminders.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class ReminderControllerTest extends BaseAndroidJVMTest
|
||||
{
|
||||
|
||||
private ReminderController controller;
|
||||
|
||||
private ReminderScheduler reminderScheduler;
|
||||
|
||||
private NotificationTray notificationTray;
|
||||
|
||||
private Preferences preferences;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
reminderScheduler = mock(ReminderScheduler.class);
|
||||
notificationTray = mock(NotificationTray.class);
|
||||
preferences = mock(Preferences.class);
|
||||
|
||||
controller = new ReminderController(reminderScheduler,
|
||||
notificationTray, preferences);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDismiss() throws Exception
|
||||
{
|
||||
verifyNoMoreInteractions(reminderScheduler);
|
||||
verifyNoMoreInteractions(notificationTray);
|
||||
verifyNoMoreInteractions(preferences);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnShowReminder() throws Exception
|
||||
{
|
||||
Habit habit = mock(Habit.class);
|
||||
controller.onShowReminder(habit, Timestamp.ZERO.plus(100), 456);
|
||||
verify(notificationTray).show(habit, Timestamp.ZERO.plus(100), 456);
|
||||
verify(reminderScheduler).scheduleAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnBootCompleted() throws Exception
|
||||
{
|
||||
controller.onBootCompleted();
|
||||
verify(reminderScheduler).scheduleAll();
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.isoron.uhabits.receivers
|
||||
|
||||
import org.isoron.uhabits.BaseAndroidJVMTest
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.Timestamp
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.reminders.ReminderScheduler
|
||||
import org.isoron.uhabits.core.ui.NotificationTray
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito
|
||||
|
||||
class ReminderControllerTest : BaseAndroidJVMTest() {
|
||||
private lateinit var controller: ReminderController
|
||||
private lateinit var reminderScheduler: ReminderScheduler
|
||||
private lateinit var notificationTray: NotificationTray
|
||||
private lateinit var preferences: Preferences
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
reminderScheduler = Mockito.mock(ReminderScheduler::class.java)
|
||||
notificationTray = Mockito.mock(NotificationTray::class.java)
|
||||
preferences = Mockito.mock(Preferences::class.java)
|
||||
controller = ReminderController(
|
||||
reminderScheduler,
|
||||
notificationTray,
|
||||
preferences
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnDismiss() {
|
||||
Mockito.verifyNoMoreInteractions(reminderScheduler)
|
||||
Mockito.verifyNoMoreInteractions(notificationTray)
|
||||
Mockito.verifyNoMoreInteractions(preferences)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnShowReminder() {
|
||||
val habit = Mockito.mock(Habit::class.java)
|
||||
controller.onShowReminder(habit, Timestamp.ZERO.plus(100), 456)
|
||||
Mockito.verify(notificationTray).show(habit, Timestamp.ZERO.plus(100), 456)
|
||||
Mockito.verify(reminderScheduler).scheduleAll()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnBootCompleted() {
|
||||
controller.onBootCompleted()
|
||||
Mockito.verify(reminderScheduler).scheduleAll()
|
||||
}
|
||||
}
|
Loading…
Reference in new issue