From 2529e4132fa6d7cb0b7c48d19779bf6c60bca0c5 Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 27 Mar 2016 20:59:53 +0200 Subject: [PATCH] Fix history test --- app/build.gradle | 4 +- .../android/calculator/history/History.java | 4 ++ .../calculator/history/HistoryTest.java | 37 ++++++------------- .../jscl/math/NumeralBaseConversionTest.java | 12 +++--- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 34108ff6..1185b8f1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 23 - versionCode 143 - versionName '2.1.4' + versionCode 144 + versionName '2.2.0b' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" generatedDensities = [] } diff --git a/app/src/main/java/org/solovyev/android/calculator/history/History.java b/app/src/main/java/org/solovyev/android/calculator/history/History.java index dbb92e89..ca6408c8 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/History.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/History.java @@ -175,6 +175,10 @@ public class History { }); } + void setLoaded(boolean loaded) { + this.loaded = loaded; + } + @NonNull File getSavedHistoryFile() { return new File(filesDir, "history-saved.json"); diff --git a/app/src/test/java/org/solovyev/android/calculator/history/HistoryTest.java b/app/src/test/java/org/solovyev/android/calculator/history/HistoryTest.java index f33b2302..0e9eef5d 100644 --- a/app/src/test/java/org/solovyev/android/calculator/history/HistoryTest.java +++ b/app/src/test/java/org/solovyev/android/calculator/history/HistoryTest.java @@ -22,28 +22,10 @@ package org.solovyev.android.calculator.history; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.solovyev.android.calculator.Engine.Preferences.groupingSeparator; -import static org.solovyev.android.calculator.Tests.sameThreadExecutor; -import static org.solovyev.android.calculator.jscl.JsclOperation.numeric; - import android.content.SharedPreferences; import android.os.Handler; import android.os.Looper; - import com.squareup.otto.Bus; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -53,19 +35,21 @@ import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.solovyev.android.CalculatorTestRunner; -import org.solovyev.android.calculator.BuildConfig; -import org.solovyev.android.calculator.Display; -import org.solovyev.android.calculator.DisplayState; -import org.solovyev.android.calculator.Editor; -import org.solovyev.android.calculator.EditorState; -import org.solovyev.android.calculator.ErrorReporter; +import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.json.Json; import org.solovyev.android.io.FileSystem; +import javax.annotation.Nonnull; import java.io.File; import java.util.List; -import javax.annotation.Nonnull; +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; +import static org.solovyev.android.calculator.Engine.Preferences.groupingSeparator; +import static org.solovyev.android.calculator.Tests.sameThreadExecutor; +import static org.solovyev.android.calculator.jscl.JsclOperation.numeric; @Config(constants = BuildConfig.class, sdk = CalculatorTestRunner.SUPPORTED_SDK) @RunWith(RobolectricGradleTestRunner.class) @@ -87,6 +71,7 @@ public class HistoryTest { when(history.preferences.edit()).thenReturn(editor); when(editor.remove(anyString())).thenReturn(editor); history.editor = mock(Editor.class); + history.setLoaded(true); } @After @@ -308,7 +293,7 @@ public class HistoryTest { history.init(sameThreadExecutor()); Robolectric.flushForegroundThreadScheduler(); verify(history.fileSystem).write(eq(history.getSavedHistoryFile()), eq( - "[{\"e\":{\"t\":\"1+1\",\"s\":3},\"d\":{\"t\":\"Error\"},\"t\":100000000}]")); + "[{\"e\":{\"t\":\"1+1\",\"s\":3},\"d\":{\"t\":\"Error\",\"v\":true},\"t\":100000000}]")); } @Test diff --git a/jscl/src/test/java/jscl/math/NumeralBaseConversionTest.java b/jscl/src/test/java/jscl/math/NumeralBaseConversionTest.java index 3f8f37dd..4cc3636b 100644 --- a/jscl/src/test/java/jscl/math/NumeralBaseConversionTest.java +++ b/jscl/src/test/java/jscl/math/NumeralBaseConversionTest.java @@ -1,13 +1,13 @@ package jscl.math; import au.com.bytecode.opencsv.CSVReader; +import com.google.common.base.Function; import jscl.JsclMathEngine; import jscl.MathEngine; import jscl.text.ParseException; import jscl.util.ExpressionGeneratorWithInput; import org.junit.Assert; import org.junit.Test; -import org.solovyev.common.Functor; import javax.annotation.Nonnull; import java.io.InputStreamReader; @@ -21,7 +21,7 @@ import java.util.List; */ public class NumeralBaseConversionTest { - public static void testExpression(@Nonnull String[] line, @Nonnull Functor converter) throws ParseException { + public static void testExpression(@Nonnull String[] line, @Nonnull Function converter) throws ParseException { final String dec = line[0].toUpperCase(); final String hex = "0x:" + line[1].toUpperCase(); final String bin = "0b:" + line[2].toUpperCase(); @@ -96,7 +96,7 @@ public class NumeralBaseConversionTest { } } - private static class DummyExpression implements Functor { + private static class DummyExpression implements Function { @Nonnull @Override @@ -105,7 +105,7 @@ public class NumeralBaseConversionTest { } } - private static class Expression1 implements Functor { + private static class Expression1 implements Function { @Nonnull @Override @@ -114,7 +114,7 @@ public class NumeralBaseConversionTest { } } - private static class Expression2 implements Functor { + private static class Expression2 implements Function { @Nonnull @Override @@ -123,7 +123,7 @@ public class NumeralBaseConversionTest { } } - private static class Expression3 implements Functor { + private static class Expression3 implements Function { @Nonnull @Override