Unit test fixed

This commit is contained in:
serso 2016-01-06 12:18:15 +01:00
parent c015b44aa7
commit e7b2e584bb
12 changed files with 52 additions and 202 deletions

View File

@ -87,6 +87,7 @@ dependencies {
compile 'com.google.android.gms:play-services-analytics:8.4.0' compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.melnykov:floatingactionbutton:1.1.0' compile 'com.melnykov:floatingactionbutton:1.1.0'
compile(name: 'plotter', ext: 'aar') 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' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
compile 'org.solovyev:common-text:1.0.7' compile 'org.solovyev:common-text:1.0.7'

View File

@ -35,7 +35,6 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import org.solovyev.android.Android; import org.solovyev.android.Android;
import org.solovyev.android.UiThreadExecutor; import org.solovyev.android.UiThreadExecutor;
import org.solovyev.android.Views; 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.language.Languages;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
import org.solovyev.android.calculator.view.ScreenMetrics; import org.solovyev.android.calculator.view.ScreenMetrics;
import org.solovyev.android.calculator.widget.BaseCalculatorWidgetProvider; import org.solovyev.android.calculator.widget.*;
import org.solovyev.android.calculator.widget.CalculatorWidgetProvider; import org.solovyev.android.checkout.*;
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.plotter.Plot; import org.solovyev.android.plotter.Plot;
import org.solovyev.android.plotter.Plotter; import org.solovyev.android.plotter.Plotter;
import org.solovyev.common.listeners.JEvent; 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.listeners.Listeners;
import org.solovyev.common.threads.DelayedExecutor; import org.solovyev.common.threads.DelayedExecutor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/** /**
* User: serso * User: serso
* Date: 12/1/12 * Date: 12/1/12
@ -111,8 +99,6 @@ public final class App {
private static volatile Vibrator vibrator; private static volatile Vibrator vibrator;
@Nonnull @Nonnull
private static volatile ScreenMetrics screenMetrics; private static volatile ScreenMetrics screenMetrics;
@Nonnull
private static volatile Plotter plotter;
private App() { private App() {
throw new AssertionError(); throw new AssertionError();
@ -175,7 +161,6 @@ public final class App {
} }
} }
App.languages.init(App.preferences); App.languages.init(App.preferences);
App.plotter = Plot.newPlotter(application);
App.initialized = true; App.initialized = true;
} else { } else {
@ -334,9 +319,4 @@ public final class App {
// Create and show the dialog. // Create and show the dialog.
dialogFragment.show(ft, fragmentTag); dialogFragment.show(ft, fragmentTag);
} }
@Nonnull
public static Plotter getPlotter() {
return plotter;
}
} }

View File

@ -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);
}
}

View File

@ -22,21 +22,23 @@
package org.solovyev.android; package org.solovyev.android;
import android.os.Build;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.solovyev.android.calculator.BuildConfig; import org.solovyev.android.calculator.BuildConfig;
import org.solovyev.android.calculator.CalculatorTestUtils;
import org.solovyev.android.calculator.units.CalculatorNumeralBase; import org.solovyev.android.calculator.units.CalculatorNumeralBase;
import org.solovyev.common.units.Unit; import org.solovyev.common.units.Unit;
import org.solovyev.common.units.UnitConverter; import org.solovyev.common.units.UnitConverter;
import javax.annotation.Nonnull;
import java.util.Date; import java.util.Date;
import java.util.Random; import java.util.Random;
import javax.annotation.Nonnull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
@ -44,13 +46,18 @@ import static org.junit.Assert.assertTrue;
* Date: 4/21/12 * Date: 4/21/12
* Time: 8:24 PM * Time: 8:24 PM
*/ */
@Config(constants = BuildConfig.class) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
public class AndroidNumeralBaseTest { public class AndroidNumeralBaseTest {
@Nonnull @Nonnull
private final UnitConverter<String> c = CalculatorNumeralBase.getConverter(); private final UnitConverter<String> c = CalculatorNumeralBase.getConverter();
@BeforeClass
public static void staticSetUp() throws Exception {
CalculatorTestUtils.staticSetUp();
}
@Test @Test
public void testIsSupported() throws Exception { public void testIsSupported() throws Exception {
assertTrue(c.isSupported(CalculatorNumeralBase.bin, CalculatorNumeralBase.dec)); assertTrue(c.isSupported(CalculatorNumeralBase.bin, CalculatorNumeralBase.dec));

View File

@ -45,7 +45,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* Time: 1:11 PM * 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) @RunWith(value = RobolectricGradleTestRunner.class)
public class AndroidCalculatorEditorViewTest { public class AndroidCalculatorEditorViewTest {

View File

@ -4,7 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Build;
import org.hamcrest.BaseMatcher; import org.hamcrest.BaseMatcher;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.junit.Before; import org.junit.Before;
@ -13,6 +13,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowPreferenceManager;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -22,11 +23,9 @@ import static org.mockito.Mockito.verify;
import static org.robolectric.RuntimeEnvironment.application; 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_DISPLAY_STATE_CHANGED;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_EDITOR_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.*;
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed;
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed_light;
@Config(constants = BuildConfig.class) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
public class CalculatorBroadcasterTest { public class CalculatorBroadcasterTest {
@ -35,7 +34,7 @@ public class CalculatorBroadcasterTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
broadcaster = new CalculatorBroadcaster(application, null); broadcaster = new CalculatorBroadcaster(application, ShadowPreferenceManager.getDefaultSharedPreferences(application));
} }
@Test @Test

View File

@ -2,6 +2,7 @@ package org.solovyev.android.calculator;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito; 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.ACTION_BUTTON_PRESSED;
import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent; import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent;
@Config(constants = BuildConfig.class) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
public class CalculatorReceiverTest { public class CalculatorReceiverTest {

View File

@ -2,6 +2,7 @@ package org.solovyev.android.calculator.view;
import android.app.Activity; import android.app.Activity;
import android.os.Build;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -28,7 +29,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp; import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;
@Config(constants = BuildConfig.class) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
public class AngleUnitsButtonTest { public class AngleUnitsButtonTest {

View File

@ -2,6 +2,7 @@ package org.solovyev.android.calculator.view;
import android.app.Activity; import android.app.Activity;
import android.os.Build;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -9,8 +10,10 @@ import org.mockito.Mockito;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.Shadows; import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.res.Attribute; import org.robolectric.res.Attribute;
import org.robolectric.shadows.ShadowActivity; import org.robolectric.shadows.ShadowActivity;
import org.solovyev.android.calculator.BuildConfig;
import java.util.ArrayList; import java.util.ArrayList;
@ -26,6 +29,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp; import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
public class NumeralBasesButtonTest { public class NumeralBasesButtonTest {

View File

@ -23,35 +23,33 @@
package org.solovyev.android.calculator.wizard; package org.solovyev.android.calculator.wizard;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows; import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity; import org.robolectric.shadows.ShadowActivity;
import org.robolectric.util.ActivityController; 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.Wizard;
import org.solovyev.android.wizard.WizardUi; import org.solovyev.android.wizard.WizardUi;
import org.solovyev.android.wizard.Wizards; import org.solovyev.android.wizard.Wizards;
import javax.annotation.Nonnull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import javax.annotation.Nonnull; import static org.junit.Assert.*;
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.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode; 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 { public class CalculatorWizardActivityTest {
private ActivityController<WizardActivity> controller; private ActivityController<WizardActivity> controller;

View File

@ -1,27 +1,24 @@
package org.solovyev.android.calculator.wizard; package org.solovyev.android.calculator.wizard;
import android.os.Build;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RuntimeEnvironment; 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.Wizard;
import org.solovyev.android.wizard.WizardFlow; import org.solovyev.android.wizard.WizardFlow;
import org.solovyev.android.wizard.Wizards; import org.solovyev.android.wizard.Wizards;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse; import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.*;
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;
@RunWith(value = CalculatorTestRunner.class) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(value = RobolectricGradleTestRunner.class)
public class CalculatorWizardTest { public class CalculatorWizardTest {
@Nonnull @Nonnull

View File

@ -22,22 +22,25 @@
package org.solovyev.android.calculator.wizard; package org.solovyev.android.calculator.wizard;
import android.os.Build;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.util.ActivityController; import org.robolectric.util.ActivityController;
import org.solovyev.android.CalculatorTestRunner; import org.solovyev.android.calculator.BuildConfig;
import org.solovyev.android.wizard.WizardUi; import org.solovyev.android.wizard.WizardUi;
import java.lang.reflect.Field;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@RunWith(CalculatorTestRunner.class) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class)
public class OnScreenCalculatorWizardStepTest { public class OnScreenCalculatorWizardStepTest {
@Nonnull @Nonnull