Fix some Robolectric unit tests
This commit is contained in:
parent
bd0c3233a3
commit
fa9288ada1
@ -17,6 +17,9 @@ import org.mockito.ArgumentMatcher;
|
|||||||
import org.solovyev.android.calculator.calculations.CalculationFailedEvent;
|
import org.solovyev.android.calculator.calculations.CalculationFailedEvent;
|
||||||
import org.solovyev.android.calculator.calculations.CalculationFinishedEvent;
|
import org.solovyev.android.calculator.calculations.CalculationFinishedEvent;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
import org.solovyev.common.msg.Message;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public abstract class BaseCalculatorTest {
|
public abstract class BaseCalculatorTest {
|
||||||
protected Calculator calculator;
|
protected Calculator calculator;
|
||||||
@ -91,7 +94,8 @@ public abstract class BaseCalculatorTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void describeTo(Description description) {
|
public void describeTo(Description description) {
|
||||||
description.appendText(expected);
|
description.appendText(new CalculationFinishedEvent(operation, expression, 0, null, expected,
|
||||||
|
Collections.<Message>emptyList()).toString());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -22,36 +22,6 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
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;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.Robolectric;
|
|
||||||
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.Engine;
|
|
||||||
import org.solovyev.android.calculator.ErrorReporter;
|
|
||||||
import org.solovyev.android.calculator.json.Json;
|
|
||||||
import org.solovyev.android.io.FileSystem;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
@ -67,8 +37,39 @@ import static org.mockito.Mockito.when;
|
|||||||
import static org.solovyev.android.calculator.Tests.sameThreadExecutor;
|
import static org.solovyev.android.calculator.Tests.sameThreadExecutor;
|
||||||
import static org.solovyev.android.calculator.jscl.JsclOperation.numeric;
|
import static org.solovyev.android.calculator.jscl.JsclOperation.numeric;
|
||||||
|
|
||||||
@Config(constants = BuildConfig.class, sdk = CalculatorTestRunner.SUPPORTED_SDK)
|
import android.content.SharedPreferences;
|
||||||
@RunWith(RobolectricGradleTestRunner.class)
|
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;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
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.Engine;
|
||||||
|
import org.solovyev.android.calculator.ErrorReporter;
|
||||||
|
import org.solovyev.android.calculator.json.Json;
|
||||||
|
import org.solovyev.android.io.FileSystem;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import dagger.Lazy;
|
||||||
|
|
||||||
|
@Config(constants = BuildConfig.class, manifest = Config.NONE)
|
||||||
|
@RunWith(value = RobolectricTestRunner.class)
|
||||||
public class HistoryTest {
|
public class HistoryTest {
|
||||||
|
|
||||||
private History history;
|
private History history;
|
||||||
@ -77,6 +78,12 @@ public class HistoryTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
history = new History();
|
history = new History();
|
||||||
history.backgroundThread = sameThreadExecutor();
|
history.backgroundThread = sameThreadExecutor();
|
||||||
|
history.filesDir = new Lazy<File>() {
|
||||||
|
@Override
|
||||||
|
public File get() {
|
||||||
|
return new File(".");
|
||||||
|
}
|
||||||
|
};
|
||||||
history.application = RuntimeEnvironment.application;
|
history.application = RuntimeEnvironment.application;
|
||||||
history.bus = mock(Bus.class);
|
history.bus = mock(Bus.class);
|
||||||
history.errorReporter = mock(ErrorReporter.class);
|
history.errorReporter = mock(ErrorReporter.class);
|
||||||
|
@ -22,6 +22,20 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.model;
|
package org.solovyev.android.calculator.model;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.solovyev.android.calculator.BaseCalculatorTest;
|
||||||
|
import org.solovyev.android.calculator.BuildConfig;
|
||||||
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
import org.solovyev.android.calculator.variables.CppVariable;
|
||||||
|
|
||||||
import jscl.AngleUnit;
|
import jscl.AngleUnit;
|
||||||
import jscl.JsclMathEngine;
|
import jscl.JsclMathEngine;
|
||||||
import jscl.MathEngine;
|
import jscl.MathEngine;
|
||||||
@ -29,15 +43,9 @@ import jscl.NumeralBase;
|
|||||||
import jscl.math.Expression;
|
import jscl.math.Expression;
|
||||||
import jscl.math.function.CustomFunction;
|
import jscl.math.function.CustomFunction;
|
||||||
import jscl.text.ParseException;
|
import jscl.text.ParseException;
|
||||||
import junit.framework.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.solovyev.android.calculator.BaseCalculatorTest;
|
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
|
||||||
import org.solovyev.android.calculator.variables.CppVariable;
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
|
@Config(constants = BuildConfig.class, manifest = Config.NONE)
|
||||||
|
@RunWith(value = RobolectricTestRunner.class)
|
||||||
public class AndroidEngineTest extends BaseCalculatorTest {
|
public class AndroidEngineTest extends BaseCalculatorTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -154,7 +162,7 @@ public class AndroidEngineTest extends BaseCalculatorTest {
|
|||||||
assertEval("e", "e*0x:ABCDEF/0x:ABCDEF");
|
assertEval("e", "e*0x:ABCDEF/0x:ABCDEF");
|
||||||
assertEval("30 606 154.462", "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF");
|
assertEval("30 606 154.462", "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF");
|
||||||
assertEval("30 606 154.462", "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C");
|
assertEval("30 606 154.462", "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C");
|
||||||
assertEval("1 446 257 064 651.832", "28*28 * sin(28) - 0b:1101 + √(28) + exp ( 28) ");
|
assertEval("1 446 257 064 651.832", "28*28 * sin(28) - 0b:1101 + √(28) + exp (28)");
|
||||||
assertEval("13", "0b:1101");
|
assertEval("13", "0b:1101");
|
||||||
|
|
||||||
assertError("0b:π");
|
assertError("0b:π");
|
||||||
@ -163,7 +171,7 @@ public class AndroidEngineTest extends BaseCalculatorTest {
|
|||||||
try {
|
try {
|
||||||
me.setNumeralBase(NumeralBase.bin);
|
me.setNumeralBase(NumeralBase.bin);
|
||||||
assertEval("101", "10+11");
|
assertEval("101", "10+11");
|
||||||
assertEval("0.101", "10/11");
|
assertEval("0.1011", "10/11");
|
||||||
|
|
||||||
me.setNumeralBase(NumeralBase.hex);
|
me.setNumeralBase(NumeralBase.hex);
|
||||||
assertEval("63 7B", "56CE+CAD");
|
assertEval("63 7B", "56CE+CAD");
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
package org.solovyev.android.calculator.wizard;
|
package org.solovyev.android.calculator.wizard;
|
||||||
|
|
||||||
import android.os.Build;
|
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 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.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.solovyev.android.calculator.BuildConfig;
|
import org.solovyev.android.calculator.BuildConfig;
|
||||||
@ -14,11 +23,8 @@ import org.solovyev.android.wizard.Wizards;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
@Config(constants = BuildConfig.class, manifest = Config.NONE)
|
||||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.*;
|
@RunWith(value = RobolectricTestRunner.class)
|
||||||
|
|
||||||
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
@RunWith(value = RobolectricGradleTestRunner.class)
|
|
||||||
public class CalculatorWizardTest {
|
public class CalculatorWizardTest {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
Loading…
Reference in New Issue
Block a user