Styling
This commit is contained in:
@@ -35,6 +35,8 @@ import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -50,7 +52,7 @@ public class TextHighlighterTest {
|
||||
|
||||
@Test
|
||||
public void testProcess() throws Exception {
|
||||
TextProcessor<?, String> textHighlighter = new TextHighlighter(0, false);
|
||||
TextProcessor<?, String> textHighlighter = new TextHighlighter(Color.TRANSPARENT, false);
|
||||
|
||||
final Random random = new Random(new Date().getTime());
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
@@ -176,4 +178,19 @@ public class TextHighlighterTest {
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("Total time, ms: " + (endTime - startTime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDarkColor() throws Exception {
|
||||
final TextProcessor<?, String> textHighlighter = new TextHighlighter(Color.BLACK, false);
|
||||
assertEquals("", textHighlighter.process("sin(2cos(3))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDark() throws Exception {
|
||||
assertFalse(TextHighlighter.isDark(Color.WHITE));
|
||||
assertFalse(TextHighlighter.isDark(Color.LTGRAY));
|
||||
assertTrue(TextHighlighter.isDark(Color.DKGRAY));
|
||||
assertTrue(TextHighlighter.isDark(Color.BLACK));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -22,21 +22,19 @@
|
||||
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.util.ActivityController;
|
||||
import org.solovyev.android.CalculatorTestRunner;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.wizard.WizardUi;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(CalculatorTestRunner.class)
|
||||
public class OnScreenCalculatorWizardStepTest {
|
||||
@@ -86,22 +84,4 @@ public class OnScreenCalculatorWizardStepTest {
|
||||
controller.restart();
|
||||
assertFalse(fragment.getCheckbox().isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeEnabledIfIconIsShown() throws Exception {
|
||||
testShouldBeEqualsToIconState(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeDisabledIfIconIsNotShown() throws Exception {
|
||||
testShouldBeEqualsToIconState(false);
|
||||
}
|
||||
|
||||
private void testShouldBeEqualsToIconState(boolean iconEnabled) throws IllegalAccessException {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(Robolectric.application);
|
||||
Preferences.OnscreenCalculator.showAppIcon.putPreference(preferences, iconEnabled);
|
||||
createActivity();
|
||||
setFragment();
|
||||
assertEquals(iconEnabled, fragment.isOnscreenCalculatorEnabled());
|
||||
}
|
||||
}
|
||||
|
@@ -1,181 +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.wizard;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.solovyev.android.CalculatorTestRunner;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
|
||||
import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator;
|
||||
import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator_mobile;
|
||||
import static org.solovyev.android.calculator.Preferences.OnscreenCalculator.showAppIcon;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.big_buttons;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.optimized;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorMode.simple;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.*;
|
||||
import static org.solovyev.android.calculator.wizard.ChooseLayoutWizardStep.LAYOUT;
|
||||
import static org.solovyev.android.calculator.wizard.ChooseModeWizardStep.MODE;
|
||||
import static org.solovyev.android.calculator.wizard.OnScreenCalculatorWizardStep.ONSCREEN_CALCULATOR_ENABLED;
|
||||
|
||||
@RunWith(CalculatorTestRunner.class)
|
||||
public class WizardStepTest {
|
||||
|
||||
private FragmentActivity activity;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
activity = Robolectric.buildActivity(FragmentActivity.class).create().get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFragmentsShouldBeInstantiated() throws Exception {
|
||||
for (CalculatorWizardStep wizardStep : CalculatorWizardStep.values()) {
|
||||
Fragment.instantiate(Robolectric.application, wizardStep.getFragmentClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeMainMobileLayout() throws Exception {
|
||||
chooseLayout(big_buttons);
|
||||
chooseMode(engineer);
|
||||
|
||||
assertUiLayoutEquals(main_calculator_mobile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeMainLayout() throws Exception {
|
||||
chooseLayout(optimized);
|
||||
chooseMode(engineer);
|
||||
|
||||
assertUiLayoutEquals(main_calculator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeSimpleLayout() throws Exception {
|
||||
chooseLayout(optimized);
|
||||
chooseMode(simple);
|
||||
|
||||
assertUiLayoutEquals(Preferences.Gui.Layout.simple);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeSimpleMobileLayout() throws Exception {
|
||||
chooseLayout(big_buttons);
|
||||
chooseMode(simple);
|
||||
|
||||
assertUiLayoutEquals(Preferences.Gui.Layout.simple_mobile);
|
||||
}
|
||||
|
||||
private void assertUiLayoutEquals(Preferences.Gui.Layout uiLayout) {
|
||||
Assert.assertEquals(uiLayout, Preferences.Gui.layout.getPreference(PreferenceManager.getDefaultSharedPreferences(Robolectric.application)));
|
||||
}
|
||||
|
||||
private void chooseMode(CalculatorMode mode) {
|
||||
final ChooseModeWizardStep modeFragment = mock(ChooseModeWizardStep.class);
|
||||
when(modeFragment.getSelectedMode()).thenReturn(mode);
|
||||
when(modeFragment.getActivity()).thenReturn(activity);
|
||||
CalculatorWizardStep.choose_mode.onNext(modeFragment);
|
||||
}
|
||||
|
||||
private void chooseLayout(CalculatorLayout layout) {
|
||||
final ChooseLayoutWizardStep layoutFragment = mock(ChooseLayoutWizardStep.class);
|
||||
when(layoutFragment.getSelectedLayout()).thenReturn(layout);
|
||||
when(layoutFragment.getActivity()).thenReturn(activity);
|
||||
choose_layout.onNext(layoutFragment);
|
||||
}
|
||||
|
||||
/* @Config(qualifiers = "large")
|
||||
@Test
|
||||
public void testChooseLayoutShouldBeVisibleForTablet() throws Exception {
|
||||
assertTrue(CalculatorWizardStep.choose_layout.isVisible());
|
||||
}*/
|
||||
|
||||
@Config(qualifiers = "normal")
|
||||
@Test
|
||||
public void testChooseLayoutShouldNotBeVisibleForMobile() throws Exception {
|
||||
assertFalse(choose_layout.isVisible());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnscreenCalculatorShouldNotBeShown() throws Exception {
|
||||
doOnscreenStep(false);
|
||||
assertFalse(showAppIcon.getPreference(getPreferences()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnscreenCalculatorShouldBeShown() throws Exception {
|
||||
doOnscreenStep(true);
|
||||
assertTrue(showAppIcon.getPreference(getPreferences()));
|
||||
}
|
||||
|
||||
|
||||
private void doOnscreenStep(boolean onscreenCalculatorEnabled) {
|
||||
final OnScreenCalculatorWizardStep f = mock(OnScreenCalculatorWizardStep.class);
|
||||
when(f.isOnscreenCalculatorEnabled()).thenReturn(onscreenCalculatorEnabled);
|
||||
when(f.getActivity()).thenReturn(activity);
|
||||
CalculatorWizardStep.on_screen_calculator.onNext(f);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void testChooseLayoutFragmentArgs() throws Exception {
|
||||
Preferences.Gui.layout.putPreference(getPreferences(), Preferences.Gui.Layout.simple);
|
||||
assertEquals(CalculatorLayout.optimized, choose_layout.getFragmentArgs().getSerializable(LAYOUT));
|
||||
|
||||
Preferences.Gui.layout.putPreference(getPreferences(), Preferences.Gui.Layout.simple_mobile);
|
||||
assertEquals(CalculatorLayout.big_buttons, choose_layout.getFragmentArgs().getSerializable(LAYOUT));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void testChooseModeFragmentArgs() throws Exception {
|
||||
Preferences.Gui.layout.putPreference(getPreferences(), Preferences.Gui.Layout.main_calculator);
|
||||
assertEquals(CalculatorMode.engineer, choose_mode.getFragmentArgs().getSerializable(MODE));
|
||||
|
||||
Preferences.Gui.layout.putPreference(getPreferences(), Preferences.Gui.Layout.simple_mobile);
|
||||
assertEquals(CalculatorMode.simple, choose_mode.getFragmentArgs().getSerializable(MODE));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void testOnscreenFragmentArgs() throws Exception {
|
||||
Preferences.OnscreenCalculator.showAppIcon.putPreference(getPreferences(), true);
|
||||
assertTrue(on_screen_calculator.getFragmentArgs().getBoolean(ONSCREEN_CALCULATOR_ENABLED));
|
||||
|
||||
Preferences.OnscreenCalculator.showAppIcon.putPreference(getPreferences(), false);
|
||||
assertFalse(on_screen_calculator.getFragmentArgs().getBoolean(ONSCREEN_CALCULATOR_ENABLED));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user