mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Fix Android tests
This commit is contained in:
14
build.sh
14
build.sh
@@ -19,7 +19,7 @@ ADB="${ANDROID_HOME}/platform-tools/adb"
|
||||
EMULATOR="${ANDROID_HOME}/tools/emulator"
|
||||
GRADLE="./gradlew --stacktrace"
|
||||
PACKAGE_NAME=org.isoron.uhabits
|
||||
OUTPUTS_DIR=app/build/outputs
|
||||
OUTPUTS_DIR=uhabits-android/build/outputs
|
||||
|
||||
KEYFILE="TestKeystore.jks"
|
||||
KEY_ALIAS="default"
|
||||
@@ -128,14 +128,14 @@ install_apk() {
|
||||
log_info "Installing APK"
|
||||
|
||||
if [ ! -z $RELEASE ]; then
|
||||
$ADB install -r ${OUTPUTS_DIR}/apk/release/app-release.apk || fail
|
||||
$ADB install -r ${OUTPUTS_DIR}/apk/release/uhabits-android-release.apk || fail
|
||||
else
|
||||
$ADB install -r ${OUTPUTS_DIR}/apk/debug/app-debug.apk || fail
|
||||
$ADB install -r ${OUTPUTS_DIR}/apk/debug/uhabits-android-debug.apk || fail
|
||||
fi
|
||||
}
|
||||
|
||||
install_test_apk() {
|
||||
$ADB install -r ${OUTPUTS_DIR}/apk/androidTest/debug/app-debug-androidTest.apk || fail
|
||||
$ADB install -r ${OUTPUTS_DIR}/apk/androidTest/debug/uhabits-android-debug-androidTest.apk || fail
|
||||
}
|
||||
|
||||
run_instrumented_tests() {
|
||||
@@ -158,7 +158,7 @@ parse_instrumentation_results() {
|
||||
|
||||
generate_coverage_badge() {
|
||||
log_info "Generating code coverage badge"
|
||||
python tools/coverage-badge/badge.py -i app/build/reports/jacoco/coverageReport/coverageReport.xml -o ${OUTPUTS_DIR}/coverage-badge
|
||||
python tools/coverage-badge/badge.py -i uhabits-android/build/reports/jacoco/coverageReport/coverageReport.xml -o ${OUTPUTS_DIR}/coverage-badge
|
||||
}
|
||||
|
||||
fetch_artifacts() {
|
||||
@@ -199,8 +199,8 @@ run_local_tests() {
|
||||
parse_instrumentation_results
|
||||
fetch_artifacts
|
||||
fetch_logcat
|
||||
run_jvm_tests
|
||||
generate_coverage_badge
|
||||
#run_jvm_tests
|
||||
#generate_coverage_badge
|
||||
uninstall_test_apk
|
||||
}
|
||||
|
||||
|
||||
@@ -73,9 +73,6 @@ dependencies {
|
||||
androidTestImplementation 'com.android.support:support-annotations:25.3.1'
|
||||
androidTestImplementation 'com.android.support.test:rules:0.5'
|
||||
androidTestImplementation 'com.android.support.test:runner:0.5'
|
||||
androidTestImplementation "com.google.dexmaker:dexmaker:1.2"
|
||||
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'
|
||||
androidTestImplementation 'org.mockito:mockito-core:2.8.9'
|
||||
androidTestImplementation 'com.google.guava:guava:20.0'
|
||||
androidTestCompileOnly 'com.google.auto.factory:auto-factory:1.0-beta3'
|
||||
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:2.11-rc2'
|
||||
@@ -86,6 +83,11 @@ dependencies {
|
||||
testAnnotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3'
|
||||
testAnnotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
|
||||
|
||||
testCompile "org.mockito:mockito-core:2.8.9"
|
||||
testCompile "org.mockito:mockito-inline:2.8.9"
|
||||
androidTestCompile "org.mockito:mockito-android:2.8.9"
|
||||
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
|
||||
|
||||
implementation('com.opencsv:opencsv:3.9') {
|
||||
exclude group: 'commons-logging', module: 'commons-logging'
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.io;
|
||||
package org.isoron.uhabits.io;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.test.*;
|
||||
@@ -26,6 +26,7 @@ import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.utils.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.io.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.io;
|
||||
package org.isoron.uhabits.io;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.test.*;
|
||||
@@ -28,7 +28,6 @@ import org.isoron.androidbase.utils.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.io.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.models;
|
||||
package org.isoron.uhabits.models;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.hamcrest.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.models.sqlite;
|
||||
package org.isoron.uhabits.models.sqlite;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.models.sqlite;
|
||||
package org.isoron.uhabits.models.sqlite;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.models.sqlite;
|
||||
package org.isoron.uhabits.models.sqlite;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.models.sqlite;
|
||||
package org.isoron.uhabits.models.sqlite;
|
||||
|
||||
import android.support.annotation.*;
|
||||
import android.support.test.runner.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.models.sqlite;
|
||||
package org.isoron.uhabits.models.sqlite;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
@@ -42,7 +42,6 @@ import static org.hamcrest.core.IsEqual.*;
|
||||
@MediumTest
|
||||
public class PebbleReceiverTest extends BaseAndroidTest
|
||||
{
|
||||
|
||||
private Habit habit1;
|
||||
|
||||
private Habit habit2;
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.tasks;
|
||||
package org.isoron.uhabits.tasks;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.tasks;
|
||||
package org.isoron.uhabits.tasks;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
@@ -17,27 +17,26 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.utils;
|
||||
package org.isoron.uhabits.utils;
|
||||
|
||||
import android.app.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class ReminderSchedulerTest extends BaseAndroidTest
|
||||
{
|
||||
private Habit habit;
|
||||
|
||||
private PendingIntent intent;
|
||||
|
||||
private ReminderScheduler reminderScheduler;
|
||||
|
||||
private HabitLogger logger;
|
||||
@@ -53,11 +52,11 @@ public class ReminderSchedulerTest extends BaseAndroidTest
|
||||
public void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
intent = mock(PendingIntent.class);
|
||||
logger = mock(HabitLogger.class);
|
||||
pendingIntentFactory = mock(PendingIntentFactory.class);
|
||||
intentScheduler = mock(IntentScheduler.class);
|
||||
commandRunner = mock(CommandRunner.class);
|
||||
pendingIntentFactory =
|
||||
new PendingIntentFactory(targetContext, new IntentFactory());
|
||||
|
||||
reminderScheduler =
|
||||
new ReminderScheduler(pendingIntentFactory, intentScheduler, logger,
|
||||
@@ -92,26 +91,23 @@ public class ReminderSchedulerTest extends BaseAndroidTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchedule_list()
|
||||
public void testScheduleAll()
|
||||
{
|
||||
long now = timestamp(2015, 1, 26, 13, 0);
|
||||
DateUtils.setFixedLocalTime(now);
|
||||
|
||||
Habit h1 = fixtures.createEmptyHabit();
|
||||
h1.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
||||
habitList.add(h1);
|
||||
|
||||
Habit h2 = fixtures.createEmptyHabit();
|
||||
h2.setReminder(new Reminder(18, 30, WeekdayList.EVERY_DAY));
|
||||
habitList.add(h2);
|
||||
|
||||
Habit h3 = fixtures.createEmptyHabit();
|
||||
habitList.add(h3);
|
||||
h1.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
||||
h2.setReminder(new Reminder(18, 30, WeekdayList.EVERY_DAY));
|
||||
h3.setReminder(null);
|
||||
habitList.update(asList(h1, h2, h3));
|
||||
|
||||
reminderScheduler.scheduleAll();
|
||||
|
||||
verify(intentScheduler).schedule(timestamp(2015, 1, 27, 12, 30), null);
|
||||
verify(intentScheduler).schedule(timestamp(2015, 1, 26, 22, 30), null);
|
||||
verify(intentScheduler).schedule(eq(timestamp(2015, 1, 27, 12, 30)), any());
|
||||
verify(intentScheduler).schedule(eq(timestamp(2015, 1, 26, 22, 30)), any());
|
||||
verifyNoMoreInteractions(intentScheduler);
|
||||
}
|
||||
|
||||
@@ -146,15 +142,13 @@ public class ReminderSchedulerTest extends BaseAndroidTest
|
||||
long expectedCheckmarkTime,
|
||||
long expectedReminderTime)
|
||||
{
|
||||
when(pendingIntentFactory.showReminder(habit, expectedReminderTime,
|
||||
expectedCheckmarkTime)).thenReturn(intent);
|
||||
PendingIntent intent =
|
||||
pendingIntentFactory.showReminder(habit, expectedReminderTime,
|
||||
expectedCheckmarkTime);
|
||||
|
||||
reminderScheduler.schedule(habit, atTime);
|
||||
|
||||
verify(logger).logReminderScheduled(habit, expectedReminderTime);
|
||||
|
||||
verify(pendingIntentFactory).showReminder(habit, expectedReminderTime,
|
||||
expectedCheckmarkTime);
|
||||
verify(intentScheduler).schedule(expectedReminderTime, intent);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import android.util.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* 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 BaseAndroidUnitTest
|
||||
{
|
||||
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);
|
||||
|
||||
modelFactory = new MemoryModelFactory();
|
||||
habitList = spy(modelFactory.buildHabitList());
|
||||
fixtures = new HabitFixtures(modelFactory);
|
||||
taskRunner = new SingleThreadTaskRunner();
|
||||
commandRunner = new CommandRunner(taskRunner);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
DateUtils.setFixedLocalTime(null);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,56 +23,36 @@ import android.view.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.habits.list.model.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.junit.*;
|
||||
import org.mockito.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class ListHabitsMenuTest extends BaseAndroidTest
|
||||
public class ListHabitsMenuTest extends BaseAndroidUnitTest
|
||||
{
|
||||
private BaseActivity activity;
|
||||
|
||||
private ListHabitsScreen screen;
|
||||
|
||||
private HabitCardListAdapter adapter;
|
||||
|
||||
private AndroidPreferences preferences;
|
||||
|
||||
private ThemeSwitcher themeSwitcher;
|
||||
|
||||
private ListHabitsMenu menu;
|
||||
|
||||
private ArgumentCaptor<HabitMatcher> matcherCaptor;
|
||||
|
||||
private ListHabitsMenuBehavior behavior;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
activity = mock(BaseActivity.class);
|
||||
screen = mock(ListHabitsScreen.class);
|
||||
adapter = mock(HabitCardListAdapter.class);
|
||||
preferences = mock(AndroidPreferences.class);
|
||||
themeSwitcher = mock(ThemeSwitcher.class);
|
||||
behavior = mock(ListHabitsMenuBehavior.class);
|
||||
|
||||
when(preferences.getShowArchived()).thenReturn(false);
|
||||
when(preferences.getShowCompleted()).thenReturn(false);
|
||||
when(themeSwitcher.isNightMode()).thenReturn(false);
|
||||
|
||||
menu = new ListHabitsMenu(activity, preferences,
|
||||
themeSwitcher, behavior);
|
||||
|
||||
matcherCaptor = ArgumentCaptor.forClass(HabitMatcher.class);
|
||||
|
||||
reset(adapter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,84 +69,75 @@ public class ListHabitsMenuTest extends BaseAndroidTest
|
||||
when(androidMenu.findItem(R.id.actionHideCompleted)).thenReturn(
|
||||
hideCompletedItem);
|
||||
|
||||
when(preferences.getShowArchived()).thenReturn(false);
|
||||
when(preferences.getShowCompleted()).thenReturn(false);
|
||||
when(themeSwitcher.isNightMode()).thenReturn(false);
|
||||
|
||||
menu.onCreate(androidMenu);
|
||||
|
||||
verify(nightModeItem).setChecked(false);
|
||||
verify(hideArchivedItem).setChecked(true);
|
||||
verify(hideCompletedItem).setChecked(true);
|
||||
reset(nightModeItem, hideArchivedItem, hideCompletedItem);
|
||||
|
||||
when(preferences.getShowArchived()).thenReturn(true);
|
||||
when(preferences.getShowCompleted()).thenReturn(true);
|
||||
when(themeSwitcher.isNightMode()).thenReturn(true);
|
||||
|
||||
menu.onCreate(androidMenu);
|
||||
|
||||
verify(nightModeItem).setChecked(true);
|
||||
verify(hideArchivedItem).setChecked(false);
|
||||
verify(hideCompletedItem).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSelected_about()
|
||||
{
|
||||
onItemSelected(R.id.actionAbout);
|
||||
verify(screen).showAboutScreen();
|
||||
verify(behavior).onViewAbout();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSelected_add()
|
||||
{
|
||||
onItemSelected(R.id.actionAdd);
|
||||
verify(screen).showCreateHabitScreen();
|
||||
verify(behavior).onCreateHabit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSelected_faq()
|
||||
{
|
||||
onItemSelected(R.id.actionFAQ);
|
||||
verify(screen).showFAQScreen();
|
||||
verify(behavior).onViewFAQ();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSelected_nightMode()
|
||||
{
|
||||
onItemSelected(R.id.actionToggleNightMode);
|
||||
verify(screen).applyTheme();
|
||||
verify(behavior).onToggleNightMode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSelected_settings()
|
||||
{
|
||||
onItemSelected(R.id.actionSettings);
|
||||
verify(screen).showSettingsScreen();
|
||||
verify(behavior).onViewSettings();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSelected_showArchived()
|
||||
{
|
||||
onItemSelected(R.id.actionHideArchived);
|
||||
verify(preferences).setShowArchived(true);
|
||||
verify(adapter).setFilter(matcherCaptor.capture());
|
||||
verify(adapter).refresh();
|
||||
assertTrue(matcherCaptor.getValue().isArchivedAllowed());
|
||||
reset(adapter);
|
||||
|
||||
onItemSelected(R.id.actionHideArchived);
|
||||
verify(preferences).setShowArchived(false);
|
||||
verify(adapter).setFilter(matcherCaptor.capture());
|
||||
verify(adapter).refresh();
|
||||
assertFalse(matcherCaptor.getValue().isArchivedAllowed());
|
||||
verify(behavior).onToggleShowArchived();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSelected_showCompleted()
|
||||
{
|
||||
onItemSelected(R.id.actionHideCompleted);
|
||||
verify(preferences).setShowCompleted(true);
|
||||
verify(adapter).setFilter(matcherCaptor.capture());
|
||||
verify(adapter).refresh();
|
||||
assertTrue(matcherCaptor.getValue().isCompletedAllowed());
|
||||
reset(adapter);
|
||||
|
||||
onItemSelected(R.id.actionHideCompleted);
|
||||
verify(preferences).setShowCompleted(false);
|
||||
verify(adapter).setFilter(matcherCaptor.capture());
|
||||
verify(adapter).refresh();
|
||||
assertFalse(matcherCaptor.getValue().isCompletedAllowed());
|
||||
verify(behavior).onToggleShowCompleted();
|
||||
}
|
||||
|
||||
protected void onItemSelected(int actionId)
|
||||
@@ -26,24 +26,26 @@ import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
import org.junit.runners.*;
|
||||
import org.mockito.junit.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.isoron.uhabits.activities.habits.list.ListHabitsScreen.*;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.eq;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ListHabitsScreenTest extends BaseAndroidTest
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ListHabitsScreenTest
|
||||
{
|
||||
private BaseActivity activity;
|
||||
|
||||
@@ -74,12 +76,9 @@ public class ListHabitsScreenTest extends BaseAndroidTest
|
||||
private CommandParser commandParser;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
activity = mock(BaseActivity.class);
|
||||
activity = mock(ListHabitsActivity.class);
|
||||
commandRunner = mock(CommandRunner.class);
|
||||
rootView = mock(ListHabitsRootView.class);
|
||||
intentFactory = mock(IntentFactory.class);
|
||||
@@ -99,7 +98,7 @@ public class ListHabitsScreenTest extends BaseAndroidTest
|
||||
controller = mock(ListHabitsController.class);
|
||||
screen.setController(controller);
|
||||
|
||||
habit = fixtures.createEmptyHabit();
|
||||
habit = mock(Habit.class);
|
||||
intent = mock(Intent.class);
|
||||
}
|
||||
|
||||
@@ -124,7 +123,7 @@ public class ListHabitsScreenTest extends BaseAndroidTest
|
||||
@Test
|
||||
public void testOnCommand()
|
||||
{
|
||||
Command c = mock(Command.class);
|
||||
Command c = mock(DeleteHabitsCommand.class);
|
||||
screen.onCommandExecuted(c, null);
|
||||
verify(screen).showMessage(R.string.toast_habit_deleted);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import org.junit.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class CheckmarkButtonControllerTest extends BaseAndroidTest
|
||||
public class CheckmarkButtonControllerTest extends BaseAndroidUnitTest
|
||||
{
|
||||
private CheckmarkButtonController controller;
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class HabitCardControllerTest extends BaseAndroidTest
|
||||
public class HabitCardControllerTest extends BaseAndroidUnitTest
|
||||
{
|
||||
|
||||
private Habit habit;
|
||||
@@ -29,7 +29,7 @@ import java.util.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class HabitCardListControllerTest extends BaseAndroidTest
|
||||
public class HabitCardListControllerTest extends BaseAndroidUnitTest
|
||||
{
|
||||
|
||||
private LinkedList<Habit> habits;
|
||||
@@ -66,6 +66,7 @@ public class HabitCardListControllerTest extends BaseAndroidTest
|
||||
|
||||
resetMocks();
|
||||
|
||||
when(adapter.getObservable()).thenReturn(new ModelObservable());
|
||||
this.controller = new HabitCardListController(adapter);
|
||||
controller.setHabitListener(habitListener);
|
||||
controller.setSelectionListener(selectionListener);
|
||||
@@ -29,7 +29,7 @@ import org.junit.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class ReminderControllerTest extends BaseAndroidTest
|
||||
public class ReminderControllerTest extends BaseAndroidUnitTest
|
||||
{
|
||||
|
||||
private ReminderController controller;
|
||||
@@ -32,7 +32,7 @@ import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.isoron.uhabits.core.models.Checkmark.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class WidgetControllerTest extends BaseAndroidTest
|
||||
public class WidgetControllerTest extends BaseAndroidUnitTest
|
||||
{
|
||||
private WidgetBehavior controller;
|
||||
|
||||
@@ -51,7 +51,6 @@ public class WidgetControllerTest extends BaseAndroidTest
|
||||
|
||||
today = DateUtils.getStartOfToday();
|
||||
habit = fixtures.createEmptyHabit();
|
||||
habitList.add(habit);
|
||||
commandRunner = mock(CommandRunner.class);
|
||||
notificationTray = mock(AndroidNotificationTray.class);
|
||||
controller = new WidgetBehavior(commandRunner, notificationTray);
|
||||
@@ -73,7 +72,7 @@ public class WidgetControllerTest extends BaseAndroidTest
|
||||
int todayValue = habit.getCheckmarks().getTodayValue();
|
||||
assertThat(todayValue, equalTo(UNCHECKED));
|
||||
controller.onAddRepetition(habit, today);
|
||||
verify(commandRunner).execute(any(), anyLong());
|
||||
verify(commandRunner).execute(any(), isNull());
|
||||
verify(notificationTray).cancel(habit);
|
||||
}
|
||||
|
||||
@@ -84,7 +83,7 @@ public class WidgetControllerTest extends BaseAndroidTest
|
||||
int todayValue = habit.getCheckmarks().getTodayValue();
|
||||
assertThat(todayValue, equalTo(CHECKED_EXPLICITLY));
|
||||
controller.onRemoveRepetition(habit, today);
|
||||
verify(commandRunner).execute(any(), anyLong());
|
||||
verify(commandRunner).execute(any(), isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,6 +99,6 @@ public class WidgetControllerTest extends BaseAndroidTest
|
||||
public void testOnToggleRepetition() throws Exception
|
||||
{
|
||||
controller.onToggleRepetition(habit, today);
|
||||
verify(commandRunner).execute(any(), anyLong());
|
||||
verify(commandRunner).execute(any(), isNull());
|
||||
}
|
||||
}
|
||||
@@ -49,13 +49,6 @@ public class ArchiveHabitsCommand extends Command
|
||||
habitList.update(selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo()
|
||||
{
|
||||
for (Habit h : selected) h.setArchived(false);
|
||||
habitList.update(selected);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Record toRecord()
|
||||
@@ -63,6 +56,13 @@ public class ArchiveHabitsCommand extends Command
|
||||
return new Record(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo()
|
||||
{
|
||||
for (Habit h : selected) h.setArchived(false);
|
||||
habitList.update(selected);
|
||||
}
|
||||
|
||||
public static class Record
|
||||
{
|
||||
@NonNull
|
||||
|
||||
@@ -17,15 +17,13 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.commands;
|
||||
package org.isoron.uhabits.core.commands;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import com.google.gson.*;
|
||||
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.json.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@@ -44,9 +42,10 @@ public class CommandParser
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Command parse(@NonNull String json) throws JSONException
|
||||
public Command parse(@NonNull String json)
|
||||
{
|
||||
String event = new JSONObject(json).getString("event");
|
||||
JsonObject parsed = new JsonParser().parse(json).getAsJsonObject();
|
||||
String event = parsed.get("event").getAsString();
|
||||
Gson gson = new GsonBuilder().create();
|
||||
|
||||
if (event.equals("Archive")) return gson
|
||||
@@ -17,8 +17,9 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.models;
|
||||
package org.isoron.uhabits.core.test;
|
||||
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
|
||||
public class HabitFixtures
|
||||
@@ -23,6 +23,7 @@ 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.*;
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.support.annotation.*;
|
||||
|
||||
import org.hamcrest.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.json.*;
|
||||
import org.junit.*;
|
||||
@@ -32,7 +31,7 @@ import java.util.*;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
public class CommandParserTest extends BaseAndroidTest
|
||||
public class CommandParserTest extends BaseUnitTest
|
||||
{
|
||||
@NonNull
|
||||
private CommandParser parser;
|
||||
Reference in New Issue
Block a user