diff --git a/uhabits-android/build.gradle b/uhabits-android/build.gradle index e6d6a25a1..0a8170e61 100644 --- a/uhabits-android/build.gradle +++ b/uhabits-android/build.gradle @@ -62,25 +62,12 @@ dependencies { implementation 'org.jetbrains:annotations-java5:15.0' implementation 'com.google.code.gson:gson:2.7' implementation 'com.google.code.findbugs:jsr305:3.0.2' - implementation 'com.google.guava:guava:20.0' compileOnly 'javax.annotation:jsr250-api:1.0' compileOnly 'com.google.auto.factory:auto-factory:1.0-beta3' annotationProcessor 'com.google.dagger:dagger-compiler:2.11-rc2' annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT' annotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3' - testImplementation project(":uhabits-core") - testImplementation 'junit:junit:5.0-SNAPSHOT' - testImplementation 'org.hamcrest:hamcrest-library:1.4-atlassian-1' - testImplementation 'org.mockito:mockito-core:2.8.9' - testImplementation 'org.json:json:20160810' - testImplementation 'org.robolectric:robolectric:3.4-rc2' - testCompileOnly 'javax.annotation:jsr250-api:1.0' - testCompileOnly 'com.google.auto.factory:auto-factory:1.0-beta3' - testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.11-rc2' - testAnnotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3' - testAnnotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT' - androidTestImplementation project(":uhabits-core") androidTestImplementation 'com.android.support:support-annotations:25.3.1' androidTestImplementation 'com.android.support.test:rules:0.5' @@ -101,3 +88,6 @@ dependencies { exclude group: 'org.json', module: 'json' } } +repositories { + mavenCentral() +} diff --git a/uhabits-android/src/test/java/org/isoron/androidbase/activities/BaseActivityTest.java b/uhabits-android/src/test/java/org/isoron/androidbase/activities/BaseActivityTest.java deleted file mode 100644 index 17374c582..000000000 --- a/uhabits-android/src/test/java/org/isoron/androidbase/activities/BaseActivityTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2017 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.androidbase.activities; - -import android.content.*; -import android.os.*; -import android.support.v4.app.*; -import android.support.v7.app.*; -import android.support.v7.widget.Toolbar; -import android.view.*; -import android.widget.*; - -import org.isoron.uhabits.*; -import org.isoron.uhabits.activities.common.dialogs.*; -import org.junit.*; -import org.junit.runner.*; -import org.robolectric.*; -import org.robolectric.annotation.*; -import org.robolectric.shadows.*; - -import static org.hamcrest.core.IsEqual.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import static org.robolectric.Robolectric.*; -import static org.robolectric.Shadows.*; - -@RunWith(RobolectricTestRunner.class) -@Config(sdk = BuildConfig.roboSdk, constants = BuildConfig.class) -public class BaseActivityTest -{ - private static boolean hasCrashed = false; - - @Test - public void activityResultTest() - { - ScreenActivity activity = spy(setupActivity(ScreenActivity.class)); - activity.onActivityResult(0, 0, null); - verify(activity.screen).onResult(0, 0, null); - } - - @Test - public void componentTest() - { - EmptyActivity activity = setupActivity(EmptyActivity.class); - ActivityComponent component = activity.getComponent(); - assertThat(component.getActivity(), equalTo(activity)); - } - - @Test - public void dialogFragmentTest() - { - EmptyActivity activity = setupActivity(EmptyActivity.class); - FragmentManager manager = activity.getSupportFragmentManager(); - ColorPickerDialog d = new ColorPickerDialogFactory(activity).create(0); - - activity.showDialog(d, "picker"); - assertTrue(d.getDialog().isShowing()); - assertThat(d, equalTo(manager.findFragmentByTag("picker"))); - } - - @Test - public void dialogTest() - { - EmptyActivity activity = setupActivity(EmptyActivity.class); - AlertDialog dialog = - new AlertDialog.Builder(activity).setTitle("Hello world").create(); - - activity.showDialog(dialog); - assertTrue(dialog.isShowing()); - } - - @Test - public void restartTest() throws Exception - { - EmptyActivity activity = setupActivity(EmptyActivity.class); - - activity.restartWithFade(EmptyActivity.class); - ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); - - Intent nextStartedActivity = shadowOf(activity).getNextStartedActivity(); - assertNotNull(nextStartedActivity); - - assertTrue(activity.isFinishing()); - assertThat(shadowOf(nextStartedActivity).getIntentClass(), - equalTo(EmptyActivity.class)); - } - - @Test - public void exceptionHandlerTest() throws InterruptedException - { - assertFalse(hasCrashed); - - Thread crashThread = new Thread() - { - @Override - public void run() - { - Looper.prepare(); - CrashActivity activity = setupActivity(CrashActivity.class); - activity.crash(); - } - }; - - crashThread.start(); - crashThread.join(); - assertTrue(hasCrashed); - } - - @Test - public void menuTest() - { - MenuActivity activity = setupActivity(MenuActivity.class); - verify(activity.baseMenu).onCreate(eq(activity.getMenuInflater()), - any()); - - Menu menu = activity.toolbar.getMenu(); - MenuItem item = menu.getItem(0); - activity.onMenuItemSelected(0, item); - verify(activity.baseMenu).onItemSelected(item); - } - - static class CrashActivity extends BaseActivity - { - public void crash() - { - throw new RuntimeException("crash!"); - } - - @Override - protected Thread.UncaughtExceptionHandler getExceptionHandler() - { - return (t, e) -> hasCrashed = true; - } - } - - static class EmptyActivity extends BaseActivity - { - - } - - static class MenuActivity extends BaseActivity - { - public BaseMenu baseMenu; - - public Toolbar toolbar; - - @Override - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - toolbar = new Toolbar(this); - LinearLayout layout = new LinearLayout(this); - layout.addView(toolbar); - setContentView(layout); - setSupportActionBar(toolbar); - - baseMenu = spy(new BaseMenu(this) - { - @Override - protected int getMenuResourceId() - { - return R.menu.list_habits; - } - }); - - setBaseMenu(baseMenu); - } - } - - static class ScreenActivity extends BaseActivity - { - private BaseScreen screen; - - @Override - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - screen = spy(new BaseScreen(this)); - setScreen(screen); - } - } -} diff --git a/uhabits-android/src/test/java/org/isoron/androidbase/activities/BaseScreenTest.java b/uhabits-android/src/test/java/org/isoron/androidbase/activities/BaseScreenTest.java deleted file mode 100644 index 1b984d853..000000000 --- a/uhabits-android/src/test/java/org/isoron/androidbase/activities/BaseScreenTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2017 Álinson Santos Xavier - * - * 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 . - */ - -package org.isoron.androidbase.activities; - -import android.content.*; -import android.support.annotation.*; -import android.support.v7.view.ActionMode; -import android.support.v7.widget.*; -import android.view.*; - -import org.isoron.uhabits.*; -import org.junit.*; -import org.junit.runner.*; -import org.robolectric.*; -import org.robolectric.annotation.*; - -import java.util.*; - -import static android.view.View.*; -import static junit.framework.Assert.assertNotNull; -import static org.hamcrest.core.IsEqual.*; -import static org.junit.Assert.*; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; -import static org.robolectric.Robolectric.*; - -@RunWith(RobolectricTestRunner.class) -@Config(sdk = BuildConfig.roboSdk, constants = BuildConfig.class) -public class BaseScreenTest -{ - @Test - public void selectionMenuTest() - { - BaseSelectionMenu selectionMenu = spy(new BaseSelectionMenu() - { - @Override - protected int getResourceId() - { - return R.menu.list_habits_selection; - } - }); - - ActionModeActivity activity = setupActivity(ActionModeActivity.class); - BaseScreen screen = new BaseScreen(activity); - screen.setSelectionMenu(selectionMenu); - activity.setScreen(screen); - - screen.startSelection(); - assertNotNull(activity.callback); - verify(selectionMenu).onCreate(any(), any(), any()); - verify(selectionMenu).onPrepare(any()); - - ActionMode mode = mock(ActionMode.class); - MenuItem item = mock(MenuItem.class); - - activity.callback.onActionItemClicked(mode, item); - verify(selectionMenu).onItemClicked(item); - - activity.callback.onDestroyActionMode(mode); - verify(selectionMenu).onFinish(); - } - - @Test - public void showMessageTest() - { - EmptyActivity activity = setupActivity(EmptyActivity.class); - ConcreteRootView rootView = new ConcreteRootView(activity); - View decor = activity.getWindow().getDecorView(); - BaseScreen screen = new BaseScreen(activity); - screen.setRootView(rootView); - activity.setScreen(screen); - - ArrayList matches = new ArrayList<>(); - - screen.showMessage(R.string.checkmark); - decor.findViewsWithText(matches, "Checkmark", FIND_VIEWS_WITH_TEXT); - assertThat(matches.size(), equalTo(1)); - assertTrue(matches.get(0).isShown()); - - screen.showMessage(R.string.frequency); - decor.findViewsWithText(matches, "Frequency", FIND_VIEWS_WITH_TEXT); - assertThat(matches.size(), equalTo(1)); - assertTrue(matches.get(0).isShown()); - } - - static class ActionModeActivity extends BaseActivity - { - private ActionMode.Callback callback; - - @Nullable - @Override - public ActionMode startSupportActionMode( - @NonNull ActionMode.Callback callback) - { - this.callback = callback; - return super.startSupportActionMode(this.callback); - } - } - - static class ConcreteRootView extends BaseRootView - { - private final Toolbar toolbar; - - public ConcreteRootView(@NonNull Context context) - { - super(context); - toolbar = new Toolbar(context); - addView(toolbar); - } - - @NonNull - @Override - public Toolbar getToolbar() - { - return toolbar; - } - } - - static class EmptyActivity extends BaseActivity - { - - } -}