Test modules
This commit is contained in:
@@ -86,6 +86,7 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="android-common-app-1.1.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="common-security-1.0.7" level="project" />
|
||||
<orderEntry type="library" exported="" name="admob-6.4.1-r11.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="actionbarsherlock-4.4.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-common-core-1.1.18" level="project" />
|
||||
@@ -97,8 +98,8 @@
|
||||
<orderEntry type="library" exported="" name="android-common-preferences-1.1.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-common-views-1.1.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="jscl-1.0.8" level="project" />
|
||||
<orderEntry type="library" exported="" name="stax-1.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="stax-1.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="guava-11.0.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="commons-cli-1.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="simple-xml-2.6.1" level="project" />
|
||||
|
@@ -34,12 +34,16 @@ android {
|
||||
versionCode version_code()
|
||||
versionName version_name()
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':core')
|
||||
compile 'org.solovyev:common-core:1.0.7'
|
||||
compile 'org.solovyev:common-text:1.0.7'
|
||||
compile 'org.solovyev:common-security:1.0.7'
|
||||
compile 'org.solovyev.android:android-common-views:1.1.18@aar'
|
||||
compile 'org.solovyev.android:android-common-menus:1.1.18@aar'
|
||||
compile 'org.solovyev.android:android-common-core:1.1.18@aar'
|
||||
|
Binary file not shown.
BIN
android-app-core/src/main/assets/fonts/Roboto-Regular.ttf
Normal file
BIN
android-app-core/src/main/assets/fonts/Roboto-Regular.ttf
Normal file
Binary file not shown.
@@ -1,71 +0,0 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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 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.display_state_changed;
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed;
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed_light;
|
||||
|
||||
@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) {
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
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.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.Robolectric.application;
|
||||
import static org.solovyev.android.calculator.CalculatorButton.four;
|
||||
import static org.solovyev.android.calculator.CalculatorReceiver.ACTION_BUTTON_ID_EXTRA;
|
||||
import static org.solovyev.android.calculator.CalculatorReceiver.ACTION_BUTTON_PRESSED;
|
||||
import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent;
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* 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 javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
package org.solovyev.android.calculator.view;
|
||||
|
||||
import android.app.Activity;
|
||||
import jscl.AngleUnit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Assert;
|
||||
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 static jscl.AngleUnit.deg;
|
||||
import static jscl.AngleUnit.grad;
|
||||
import static jscl.AngleUnit.rad;
|
||||
import static jscl.AngleUnit.turns;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
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();
|
||||
}
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
package org.solovyev.android.calculator.view;
|
||||
|
||||
import android.app.Activity;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
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 static jscl.AngleUnit.deg;
|
||||
import static jscl.AngleUnit.rad;
|
||||
import static jscl.NumeralBase.bin;
|
||||
import static jscl.NumeralBase.dec;
|
||||
import static jscl.NumeralBase.hex;
|
||||
import static jscl.NumeralBase.oct;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
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