Test modules
This commit is contained in:
112
android-app-core-tests/android-app-core-tests.iml
Normal file
112
android-app-core-tests/android-app-core-tests.iml
Normal file
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":android-app-core-tests" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="calculatorpp" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":android-app-core-tests" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
<option name="BUILD_FOLDER_PATH" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/classes/main" />
|
||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="android-app" exported="" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="robolectric-2.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="mockito-all-1.9.5" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="jsonassert-1.2.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="objenesis-1.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="sqlite4java-0.282" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="asm-5.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="asm-commons-5.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="asm-util-5.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="asm-analysis-5.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="commons-logging-1.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="commons-codec-1.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="httpclient-4.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="vtd-xml-2.11" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="support-v4-19.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="fest-util-1.2.5" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="fest-reflect-1.4.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-ant-tasks-2.1.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="json-20090211" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="asm-tree-5.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="httpcore-4.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="ant-1.8.0" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classworlds-1.1-alpha-2" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="plexus-container-default-1.0-alpha-9-stable-1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="plexus-utils-1.5.15" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="plexus-interpolation-1.11" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-artifact-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-artifact-manager-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-model-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-project-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-error-diagnostics-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-settings-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="wagon-file-1.0-beta-6" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="wagon-http-lightweight-1.0-beta-6" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="wagon-provider-api-1.0-beta-6" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="ant-launcher-1.8.0" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-repository-metadata-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="backport-util-concurrent-3.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-profile-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="maven-plugin-registry-2.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="wagon-http-shared-1.0-beta-6" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="xercesMinimal-1.9.6.2" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="nekohtml-1.9.6.2" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="simple-xml-2.6.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="core" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="commons-cli-1.2" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="annotations-2.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="stax-1.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="support-annotations-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="common-msg-1.0.5" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="common-listeners-1.0.7" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="guava-11.0.2" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="admob-6.4.1-r11.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="common-text-1.0.7" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="acra-4.5.0" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="internal_impl-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="common-core-1.0.7" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="jscl-1.0.8" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="common-security-1.0.7" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="classes" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="_home_serso_projects_java_serso_android_calculatorpp_android_app_build_intermediates_classes_debug" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="_home_serso_projects_java_serso_android_calculatorpp_android_app_build_intermediates_dependency_cache_debug" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="android" level="project" />
|
||||
</component>
|
||||
</module>
|
49
android-app-core-tests/build.gradle
Normal file
49
android-app-core-tests/build.gradle
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2014 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
def androidModule = project(':android-app')
|
||||
compile androidModule
|
||||
|
||||
testCompile androidModule.android.applicationVariants.toList().first().javaCompile.classpath
|
||||
testCompile androidModule.android.applicationVariants.toList().first().javaCompile.outputs.files
|
||||
testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())
|
||||
|
||||
testCompile 'junit:junit:4.+'
|
||||
testCompile 'org.robolectric:robolectric:2.3'
|
||||
testCompile "org.mockito:mockito-all:1.9.5"
|
||||
testCompile "org.skyscreamer:jsonassert:1.2.3"
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
scanForTestClasses = false
|
||||
include "**/*Test.class"
|
||||
exclude "**/*AngleUnitsButtonTest*"
|
||||
exclude "**/*NumeralBasesButtonTest*"
|
||||
}
|
||||
|
||||
test {
|
||||
maxParallelForks = 15
|
||||
forkEvery = 1
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.Robolectric.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.*;
|
||||
|
||||
@Config(manifest = Config.NONE)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CalculatorBroadcasterTest {
|
||||
|
||||
@Nonnull
|
||||
private CalculatorBroadcaster broadcaster;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
broadcaster = new CalculatorBroadcaster(application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSendEditorStateChangedIntent() throws Exception {
|
||||
assertIntentSent(editor_state_changed, ACTION_EDITOR_STATE_CHANGED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSendEditorStateChangedLiteIntent() throws Exception {
|
||||
assertIntentSent(editor_state_changed_light, ACTION_EDITOR_STATE_CHANGED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSendDisplayStateChangedIntent() throws Exception {
|
||||
assertIntentSent(display_state_changed, ACTION_DISPLAY_STATE_CHANGED);
|
||||
}
|
||||
|
||||
private void assertIntentSent(@Nonnull CalculatorEventType eventType, final String expectedAction) {
|
||||
final BroadcastReceiver receiver = Mockito.mock(BroadcastReceiver.class);
|
||||
application.registerReceiver(receiver, new IntentFilter(expectedAction));
|
||||
broadcaster.onCalculatorEvent(CalculatorEventDataImpl.newInstance(1L, 1L), eventType, null);
|
||||
verify(receiver, times(1)).onReceive(Mockito.<Context>any(), argThat(new BaseMatcher<Intent>() {
|
||||
@Override
|
||||
public boolean matches(Object o) {
|
||||
return ((Intent) o).getAction().equals(expectedAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Intent;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.robolectric.Robolectric.application;
|
||||
import static org.solovyev.android.calculator.CalculatorButton.four;
|
||||
import static org.solovyev.android.calculator.CalculatorReceiver.*;
|
||||
|
||||
@Config(manifest = Config.NONE)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CalculatorReceiverTest {
|
||||
|
||||
@Test
|
||||
public void testShouldPressButtonOnIntent() throws Exception {
|
||||
Locator.setKeyboard(mock(CalculatorKeyboard.class));
|
||||
|
||||
final Intent intent = newButtonClickedIntent(application, four);
|
||||
new CalculatorReceiver().onReceive(application, intent);
|
||||
|
||||
verify(Locator.getInstance().getKeyboard(), times(1)).buttonPressed(Mockito.anyString());
|
||||
verify(Locator.getInstance().getKeyboard(), times(1)).buttonPressed("4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldDoNothingIfButtonInvalid() throws Exception {
|
||||
Locator.setKeyboard(mock(CalculatorKeyboard.class));
|
||||
|
||||
final Intent intent = new Intent(application, CalculatorReceiver.class);
|
||||
intent.setAction(ACTION_BUTTON_PRESSED);
|
||||
intent.putExtra(ACTION_BUTTON_ID_EXTRA, "test!@");
|
||||
new CalculatorReceiver().onReceive(application, intent);
|
||||
|
||||
verify(Locator.getInstance().getKeyboard(), times(0)).buttonPressed(Mockito.anyString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import jscl.JsclMathEngine;
|
||||
import org.mockito.Mockito;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/7/12
|
||||
* Time: 8:56 PM
|
||||
*/
|
||||
public class CalculatorTestUtils {
|
||||
|
||||
public static void staticSetUp(@Nullable Context context) throws Exception {
|
||||
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
|
||||
Locator.getInstance().getEngine().init();
|
||||
|
||||
if (context != null) {
|
||||
initViews(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initViews(@Nonnull Context context) {
|
||||
final AndroidCalculatorEditorView editor = new AndroidCalculatorEditorView(context);
|
||||
editor.init();
|
||||
Locator.getInstance().getEditor().setView(editor);
|
||||
|
||||
final AndroidCalculatorDisplayView display = new AndroidCalculatorDisplayView(context);
|
||||
display.init(context);
|
||||
Locator.getInstance().getDisplay().setView(display);
|
||||
}
|
||||
|
||||
public static void staticSetUp() throws Exception {
|
||||
staticSetUp(null);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
static CalculatorEngineImpl newCalculatorEngine() {
|
||||
final MathEntityDao mathEntityDao = Mockito.mock(MathEntityDao.class);
|
||||
|
||||
final JsclMathEngine jsclEngine = JsclMathEngine.getInstance();
|
||||
|
||||
final CalculatorVarsRegistry varsRegistry = new CalculatorVarsRegistry(jsclEngine.getConstantsRegistry(), mathEntityDao);
|
||||
final CalculatorFunctionsMathRegistry functionsRegistry = new CalculatorFunctionsMathRegistry(jsclEngine.getFunctionsRegistry(), mathEntityDao);
|
||||
final CalculatorOperatorsMathRegistry operatorsRegistry = new CalculatorOperatorsMathRegistry(jsclEngine.getOperatorsRegistry(), mathEntityDao);
|
||||
final CalculatorPostfixFunctionsRegistry postfixFunctionsRegistry = new CalculatorPostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry(), mathEntityDao);
|
||||
|
||||
return new CalculatorEngineImpl(jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry, null);
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
package org.solovyev.android.calculator.view;
|
||||
|
||||
import android.app.Activity;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.res.Attribute;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static jscl.AngleUnit.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AngleUnitsButtonTest {
|
||||
|
||||
private AngleUnitsButton button;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
staticSetUp();
|
||||
|
||||
final Activity context = Robolectric.buildActivity(Activity.class).create().get();
|
||||
final ShadowActivity activity = Robolectric.shadowOf(context);
|
||||
button = new AngleUnitsButton(context, activity.createAttributeSet(new ArrayList<Attribute>(), AngleUnitsButton.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldReturnDifferentColorsForDifferentAngleUnits() throws Exception {
|
||||
button.setAngleUnit(deg);
|
||||
|
||||
assertEquals(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(deg.name()));
|
||||
assertEquals(button.getDirectionTextColor(grad.name()), button.getDirectionTextColor(rad.name()));
|
||||
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(rad.name()));
|
||||
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(grad.name()));
|
||||
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(turns.name()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsCurrentAngleUnits() throws Exception {
|
||||
button.setAngleUnit(rad);
|
||||
assertTrue(button.isCurrentAngleUnits(rad.name()));
|
||||
assertFalse(button.isCurrentAngleUnits(deg.name()));
|
||||
assertFalse(button.isCurrentAngleUnits(grad.name()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidateShouldBeCalledOnlyWhenChangeIsDone() throws Exception {
|
||||
button.setAngleUnit(rad);
|
||||
|
||||
button = Mockito.spy(button);
|
||||
|
||||
button.setAngleUnit(deg);
|
||||
verify(button, times(1)).invalidate();
|
||||
|
||||
button.setAngleUnit(deg);
|
||||
verify(button, times(1)).invalidate();
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
package org.solovyev.android.calculator.view;
|
||||
|
||||
import android.app.Activity;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.res.Attribute;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static jscl.NumeralBase.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.solovyev.android.calculator.CalculatorTestUtils.staticSetUp;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class NumeralBasesButtonTest {
|
||||
|
||||
private NumeralBasesButton button;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
staticSetUp();
|
||||
|
||||
final Activity context = Robolectric.buildActivity(Activity.class).create().get();
|
||||
final ShadowActivity activity = Robolectric.shadowOf(context);
|
||||
button = new NumeralBasesButton(context, activity.createAttributeSet(new ArrayList<Attribute>(), NumeralBasesButton.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldReturnDifferentColorsForDifferentNumeralBase() throws Exception {
|
||||
button.setNumeralBase(dec);
|
||||
|
||||
assertEquals(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(dec.name()));
|
||||
assertEquals(button.getDirectionTextColor(hex.name()), button.getDirectionTextColor(bin.name()));
|
||||
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(bin.name()));
|
||||
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(hex.name()));
|
||||
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(oct.name()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsCurrentNumeralBase() throws Exception {
|
||||
button.setNumeralBase(dec);
|
||||
assertTrue(button.isCurrentNumberBase(dec.name()));
|
||||
assertFalse(button.isCurrentNumberBase(hex.name()));
|
||||
assertFalse(button.isCurrentNumberBase(bin.name()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidateShouldBeCalledOnlyWhenChangeIsDone() throws Exception {
|
||||
button.setNumeralBase(dec);
|
||||
|
||||
button = Mockito.spy(button);
|
||||
|
||||
button.setNumeralBase(hex);
|
||||
verify(button, times(1)).invalidate();
|
||||
|
||||
button.setNumeralBase(hex);
|
||||
verify(button, times(1)).invalidate();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user