From e7b2e584bbc0ed1a5d2c577ca625373109ffab27 Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 6 Jan 2016 12:18:15 +0100 Subject: [PATCH] Unit test fixed --- app/build.gradle | 1 + .../org/solovyev/android/calculator/App.java | 28 +--- .../calculator/plot/PlotterFragment.java | 141 ------------------ .../android/AndroidNumeralBaseTest.java | 13 +- .../AndroidCalculatorEditorViewTest.java | 2 +- .../calculator/CalculatorBroadcasterTest.java | 11 +- .../calculator/CalculatorReceiverTest.java | 3 +- .../calculator/view/AngleUnitsButtonTest.java | 3 +- .../view/NumeralBasesButtonTest.java | 4 + .../wizard/CalculatorWizardActivityTest.java | 18 +-- .../wizard/CalculatorWizardTest.java | 19 +-- .../OnScreenCalculatorWizardStepTest.java | 11 +- 12 files changed, 52 insertions(+), 202 deletions(-) delete mode 100644 app/src/main/java/org/solovyev/android/calculator/plot/PlotterFragment.java diff --git a/app/build.gradle b/app/build.gradle index 9e652ede..0fdd2653 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -87,6 +87,7 @@ dependencies { compile 'com.google.android.gms:play-services-analytics:8.4.0' compile 'com.melnykov:floatingactionbutton:1.1.0' compile(name: 'plotter', ext: 'aar') + testCompile "com.squareup.leakcanary:leakcanary-android-no-op:1.3.1" debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' compile 'org.solovyev:common-text:1.0.7' diff --git a/app/src/main/java/org/solovyev/android/calculator/App.java b/app/src/main/java/org/solovyev/android/calculator/App.java index 214935a3..81075eff 100644 --- a/app/src/main/java/org/solovyev/android/calculator/App.java +++ b/app/src/main/java/org/solovyev/android/calculator/App.java @@ -35,7 +35,6 @@ import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; - import org.solovyev.android.Android; import org.solovyev.android.UiThreadExecutor; import org.solovyev.android.Views; @@ -43,18 +42,8 @@ import org.solovyev.android.calculator.ga.Ga; import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; import org.solovyev.android.calculator.view.ScreenMetrics; -import org.solovyev.android.calculator.widget.BaseCalculatorWidgetProvider; -import org.solovyev.android.calculator.widget.CalculatorWidgetProvider; -import org.solovyev.android.calculator.widget.CalculatorWidgetProvider3x4; -import org.solovyev.android.calculator.widget.CalculatorWidgetProvider4x4; -import org.solovyev.android.calculator.widget.CalculatorWidgetProvider4x5; -import org.solovyev.android.checkout.Billing; -import org.solovyev.android.checkout.Checkout; -import org.solovyev.android.checkout.Inventory; -import org.solovyev.android.checkout.ProductTypes; -import org.solovyev.android.checkout.Products; -import org.solovyev.android.checkout.RobotmediaDatabase; -import org.solovyev.android.checkout.RobotmediaInventory; +import org.solovyev.android.calculator.widget.*; +import org.solovyev.android.checkout.*; import org.solovyev.android.plotter.Plot; import org.solovyev.android.plotter.Plotter; import org.solovyev.common.listeners.JEvent; @@ -63,14 +52,13 @@ import org.solovyev.common.listeners.JEventListeners; import org.solovyev.common.listeners.Listeners; import org.solovyev.common.threads.DelayedExecutor; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.Executor; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - /** * User: serso * Date: 12/1/12 @@ -111,8 +99,6 @@ public final class App { private static volatile Vibrator vibrator; @Nonnull private static volatile ScreenMetrics screenMetrics; - @Nonnull - private static volatile Plotter plotter; private App() { throw new AssertionError(); @@ -175,7 +161,6 @@ public final class App { } } App.languages.init(App.preferences); - App.plotter = Plot.newPlotter(application); App.initialized = true; } else { @@ -334,9 +319,4 @@ public final class App { // Create and show the dialog. dialogFragment.show(ft, fragmentTag); } - - @Nonnull - public static Plotter getPlotter() { - return plotter; - } } diff --git a/app/src/main/java/org/solovyev/android/calculator/plot/PlotterFragment.java b/app/src/main/java/org/solovyev/android/calculator/plot/PlotterFragment.java deleted file mode 100644 index 35e38934..00000000 --- a/app/src/main/java/org/solovyev/android/calculator/plot/PlotterFragment.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.solovyev.android.calculator.plot; - -import android.content.Intent; -import android.os.Bundle; -import android.os.Parcelable; -import android.support.annotation.ColorInt; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; - -import org.solovyev.android.calculator.App; -import org.solovyev.android.calculator.CalculatorFragment; -import org.solovyev.android.calculator.CalculatorFragmentType; -import org.solovyev.android.calculator.R; -import org.solovyev.android.calculator.preferences.PreferencesActivity; -import org.solovyev.android.plotter.PlotView; -import org.solovyev.android.plotter.Plotter; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public class PlotterFragment extends CalculatorFragment { - - @Nonnull - private final Plotter plotter = App.getPlotter(); - - private PlotView plotView; - - public PlotterFragment() { - super(CalculatorFragmentType.plotter); - } - - @Override - public void onCreate(@Nullable Bundle in) { - super.onCreate(in); - setHasOptionsMenu(true); - } - - @ColorInt - private int getBgColor() { - if (isPaneFragment()) { - return getBgColor(R.color.cpp_pane_bg_light, R.color.cpp_pane_bg); - } else { - return getBgColor(R.color.cpp_main_bg_light, R.color.cpp_main_bg); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = super.onCreateView(inflater, container, savedInstanceState); - plotView = (PlotView) view.findViewById(R.id.plotview); - plotView.setPlotter(plotter); - plotView.setBackgroundColor(getBgColor()); - - if (savedInstanceState != null) { - final Parcelable plotviewState = savedInstanceState.getParcelable("plotview"); - if (plotviewState != null) { - plotView.onRestoreInstanceState(plotviewState); - } - } - - final View zoomOutButton = view.findViewById(R.id.zoom_out_button); - zoomOutButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - plotView.zoom(false); - } - }); - final View zoom0Button = view.findViewById(R.id.zoom_0_button); - zoom0Button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - plotView.resetCamera(); - plotView.resetZoom(); - } - }); - final View zoomInButton = view.findViewById(R.id.zoom_in_button); - zoomInButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - plotView.zoom(true); - } - }); - final View plotModeButton = view.findViewById(R.id.plot_mode_button); - plotModeButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - plotter.set3d(!plotter.is3d()); - } - }); - - return view; - } - - @ColorInt - @SuppressWarnings("deprecation") - private int getBgColor(int lightColor, int darkColor) { - return getResources().getColor(App.getTheme().isLight() ? lightColor : darkColor); - } - - @Override - public void onSaveInstanceState(@Nonnull Bundle out) { - super.onSaveInstanceState(out); - final Parcelable plotViewState = plotView.onSaveInstanceState(); - out.putParcelable("plotview", plotViewState); - } - - @Override - public void onPause() { - plotView.onPause(); - super.onPause(); - } - - @Override - public void onResume() { - super.onResume(); - plotView.onResume(); - } - - @Override - public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater) { - super.onCreateOptionsMenu(menu, inflater); - inflater.inflate(R.menu.plot_menu, menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_plot_functions: - startActivity(new Intent(getActivity(), CalculatorPlotFunctionsActivity.class)); - return true; - case R.id.menu_plot_settings: - PreferencesActivity.start(getActivity(), R.xml.preferences_plot, R.string.prefs_graph_screen_title); - return true; - } - return super.onOptionsItemSelected(item); - } -} diff --git a/app/src/test/java/org/solovyev/android/AndroidNumeralBaseTest.java b/app/src/test/java/org/solovyev/android/AndroidNumeralBaseTest.java index 846a981b..250782f2 100644 --- a/app/src/test/java/org/solovyev/android/AndroidNumeralBaseTest.java +++ b/app/src/test/java/org/solovyev/android/AndroidNumeralBaseTest.java @@ -22,21 +22,23 @@ package org.solovyev.android; +import android.os.Build; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.annotation.Config; import org.solovyev.android.calculator.BuildConfig; +import org.solovyev.android.calculator.CalculatorTestUtils; import org.solovyev.android.calculator.units.CalculatorNumeralBase; import org.solovyev.common.units.Unit; import org.solovyev.common.units.UnitConverter; +import javax.annotation.Nonnull; import java.util.Date; import java.util.Random; -import javax.annotation.Nonnull; - import static org.junit.Assert.assertTrue; /** @@ -44,13 +46,18 @@ import static org.junit.Assert.assertTrue; * Date: 4/21/12 * Time: 8:24 PM */ -@Config(constants = BuildConfig.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(RobolectricGradleTestRunner.class) public class AndroidNumeralBaseTest { @Nonnull private final UnitConverter c = CalculatorNumeralBase.getConverter(); + @BeforeClass + public static void staticSetUp() throws Exception { + CalculatorTestUtils.staticSetUp(); + } + @Test public void testIsSupported() throws Exception { assertTrue(c.isSupported(CalculatorNumeralBase.bin, CalculatorNumeralBase.dec)); diff --git a/app/src/test/java/org/solovyev/android/calculator/AndroidCalculatorEditorViewTest.java b/app/src/test/java/org/solovyev/android/calculator/AndroidCalculatorEditorViewTest.java index f0ae17a9..54c1fe85 100644 --- a/app/src/test/java/org/solovyev/android/calculator/AndroidCalculatorEditorViewTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/AndroidCalculatorEditorViewTest.java @@ -45,7 +45,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * Time: 1:11 PM */ -@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP_MR1) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(value = RobolectricGradleTestRunner.class) public class AndroidCalculatorEditorViewTest { diff --git a/app/src/test/java/org/solovyev/android/calculator/CalculatorBroadcasterTest.java b/app/src/test/java/org/solovyev/android/calculator/CalculatorBroadcasterTest.java index 48c58fe6..c3fcdff1 100644 --- a/app/src/test/java/org/solovyev/android/calculator/CalculatorBroadcasterTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/CalculatorBroadcasterTest.java @@ -4,7 +4,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; - +import android.os.Build; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; @@ -13,6 +13,7 @@ import org.junit.runner.RunWith; import org.mockito.Mockito; import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowPreferenceManager; import javax.annotation.Nonnull; @@ -22,11 +23,9 @@ import static org.mockito.Mockito.verify; import static org.robolectric.RuntimeEnvironment.application; import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_DISPLAY_STATE_CHANGED; import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_EDITOR_STATE_CHANGED; -import static org.solovyev.android.calculator.CalculatorEventType.display_state_changed; -import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed; -import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed_light; +import static org.solovyev.android.calculator.CalculatorEventType.*; -@Config(constants = BuildConfig.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(RobolectricGradleTestRunner.class) public class CalculatorBroadcasterTest { @@ -35,7 +34,7 @@ public class CalculatorBroadcasterTest { @Before public void setUp() throws Exception { - broadcaster = new CalculatorBroadcaster(application, null); + broadcaster = new CalculatorBroadcaster(application, ShadowPreferenceManager.getDefaultSharedPreferences(application)); } @Test diff --git a/app/src/test/java/org/solovyev/android/calculator/CalculatorReceiverTest.java b/app/src/test/java/org/solovyev/android/calculator/CalculatorReceiverTest.java index 16988905..1ecf7bf7 100644 --- a/app/src/test/java/org/solovyev/android/calculator/CalculatorReceiverTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/CalculatorReceiverTest.java @@ -2,6 +2,7 @@ package org.solovyev.android.calculator; import android.content.Intent; +import android.os.Build; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -17,7 +18,7 @@ import static org.solovyev.android.calculator.CalculatorReceiver.ACTION_BUTTON_I import static org.solovyev.android.calculator.CalculatorReceiver.ACTION_BUTTON_PRESSED; import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent; -@Config(constants = BuildConfig.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(RobolectricGradleTestRunner.class) public class CalculatorReceiverTest { diff --git a/app/src/test/java/org/solovyev/android/calculator/view/AngleUnitsButtonTest.java b/app/src/test/java/org/solovyev/android/calculator/view/AngleUnitsButtonTest.java index 0ba6d628..843e036d 100644 --- a/app/src/test/java/org/solovyev/android/calculator/view/AngleUnitsButtonTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/view/AngleUnitsButtonTest.java @@ -2,6 +2,7 @@ package org.solovyev.android.calculator.view; import android.app.Activity; +import android.os.Build; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,7 +29,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp; -@Config(constants = BuildConfig.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(RobolectricGradleTestRunner.class) public class AngleUnitsButtonTest { diff --git a/app/src/test/java/org/solovyev/android/calculator/view/NumeralBasesButtonTest.java b/app/src/test/java/org/solovyev/android/calculator/view/NumeralBasesButtonTest.java index bfe71271..20578278 100644 --- a/app/src/test/java/org/solovyev/android/calculator/view/NumeralBasesButtonTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/view/NumeralBasesButtonTest.java @@ -2,6 +2,7 @@ package org.solovyev.android.calculator.view; import android.app.Activity; +import android.os.Build; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -9,8 +10,10 @@ import org.mockito.Mockito; import org.robolectric.Robolectric; import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.Shadows; +import org.robolectric.annotation.Config; import org.robolectric.res.Attribute; import org.robolectric.shadows.ShadowActivity; +import org.solovyev.android.calculator.BuildConfig; import java.util.ArrayList; @@ -26,6 +29,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp; +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(RobolectricGradleTestRunner.class) public class NumeralBasesButtonTest { diff --git a/app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivityTest.java b/app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivityTest.java index 6d52113a..edfb8c10 100644 --- a/app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivityTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardActivityTest.java @@ -23,35 +23,33 @@ package org.solovyev.android.calculator.wizard; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.Shadows; +import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowActivity; import org.robolectric.util.ActivityController; -import org.solovyev.android.CalculatorTestRunner; +import org.solovyev.android.calculator.BuildConfig; import org.solovyev.android.wizard.Wizard; import org.solovyev.android.wizard.WizardUi; import org.solovyev.android.wizard.Wizards; +import javax.annotation.Nonnull; import java.lang.reflect.Field; -import javax.annotation.Nonnull; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode; -@RunWith(value = CalculatorTestRunner.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) +@RunWith(value = RobolectricGradleTestRunner.class) public class CalculatorWizardActivityTest { private ActivityController controller; diff --git a/app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardTest.java b/app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardTest.java index 896cd897..1933d861 100644 --- a/app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/wizard/CalculatorWizardTest.java @@ -1,27 +1,24 @@ package org.solovyev.android.calculator.wizard; +import android.os.Build; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RuntimeEnvironment; -import org.solovyev.android.CalculatorTestRunner; +import org.robolectric.annotation.Config; +import org.solovyev.android.calculator.BuildConfig; import org.solovyev.android.wizard.Wizard; import org.solovyev.android.wizard.WizardFlow; import org.solovyev.android.wizard.Wizards; import javax.annotation.Nonnull; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode; -import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.last; -import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.welcome; +import static org.junit.Assert.*; +import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.*; -@RunWith(value = CalculatorTestRunner.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) +@RunWith(value = RobolectricGradleTestRunner.class) public class CalculatorWizardTest { @Nonnull diff --git a/app/src/test/java/org/solovyev/android/calculator/wizard/OnScreenCalculatorWizardStepTest.java b/app/src/test/java/org/solovyev/android/calculator/wizard/OnScreenCalculatorWizardStepTest.java index 2078f413..5b8cd449 100644 --- a/app/src/test/java/org/solovyev/android/calculator/wizard/OnScreenCalculatorWizardStepTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/wizard/OnScreenCalculatorWizardStepTest.java @@ -22,22 +22,25 @@ package org.solovyev.android.calculator.wizard; +import android.os.Build; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; import org.robolectric.util.ActivityController; -import org.solovyev.android.CalculatorTestRunner; +import org.solovyev.android.calculator.BuildConfig; import org.solovyev.android.wizard.WizardUi; -import java.lang.reflect.Field; - import javax.annotation.Nonnull; +import java.lang.reflect.Field; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -@RunWith(CalculatorTestRunner.class) +@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) +@RunWith(RobolectricGradleTestRunner.class) public class OnScreenCalculatorWizardStepTest { @Nonnull