wizard added

This commit is contained in:
Sergey Solovyev 2013-06-18 00:44:44 +04:00
parent 6ef4354f2c
commit 4840b6e25b
14 changed files with 289 additions and 196 deletions

View File

@ -123,9 +123,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.pivotallabs</groupId> <groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId> <artifactId>robolectric</artifactId>
<version>1.2</version> <version>2.1.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@ -8,23 +8,28 @@
# project structure. # project structure.
# Project target. # Project target.
target=android-15 target=android-17
android.library.reference.1=../android-app-core android.library.reference.1=../android-app-core
android.library.reference.2=../android-app-widget android.library.reference.2=../android-app-widget
android.library.reference.3=../android-app-onscreen android.library.reference.3=../android-app-onscreen
android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-all_1.0.7-SNAPSHOT android.library.reference.4=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-all_1.1.1-SNAPSHOT
android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.7-SNAPSHOT android.library.reference.5=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-ads_1.1.1-SNAPSHOT
android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.7-SNAPSHOT android.library.reference.6=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-core_1.1.1-SNAPSHOT
android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-billing_1.0.7-SNAPSHOT android.library.reference.7=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-billing_1.1.1-SNAPSHOT
android.library.reference.8=gen-external-apklibs/org.solovyev.android_android-common-db_1.0.7-SNAPSHOT android.library.reference.8=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-db_1.1.1-SNAPSHOT
android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-http_1.0.7-SNAPSHOT android.library.reference.9=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-security_1.1.1-SNAPSHOT
android.library.reference.10=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.7-SNAPSHOT android.library.reference.10=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-http_1.1.1-SNAPSHOT
android.library.reference.11=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.7-SNAPSHOT android.library.reference.11=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-lists_1.1.1-SNAPSHOT
android.library.reference.12=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.7-SNAPSHOT android.library.reference.12=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-views_1.1.1-SNAPSHOT
android.library.reference.13=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.7-SNAPSHOT android.library.reference.13=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-preferences_1.1.1-SNAPSHOT
android.library.reference.14=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.7-SNAPSHOT android.library.reference.14=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-menus_1.1.1-SNAPSHOT
android.library.reference.15=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.7-SNAPSHOT android.library.reference.15=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-other_1.1.1-SNAPSHOT
android.library.reference.16=gen-external-apklibs/com.actionbarsherlock_actionbarsherlock_4.2.0 android.library.reference.16=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.1.1-SNAPSHOT
android.library.reference.17=gen-external-apklibs/org.solovyev.android_android-common-keyboard_1.0.7-SNAPSHOT android.library.reference.17=gen-external-apklibs/com.actionbarsherlock_actionbarsherlock_4.2.0
android.library.reference.18=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-keyboards_1.1.1-SNAPSHOT
android.library.reference.19=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-app_1.1.1-SNAPSHOT
android.library.reference.20=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-networks_1.1.1-SNAPSHOT
android.library.reference.21=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-fragments_1.1.1-SNAPSHOT
android.library.reference.22=../android-app-widget/gen-external-apklibs/org.solovyev.android_android-common-tasks_1.1.1-SNAPSHOT

View File

@ -0,0 +1,50 @@
package org.solovyev.android.calculator.wizard;
import android.content.SharedPreferences;
import jscl.AngleUnit;
import org.solovyev.android.calculator.CalculatorPreferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import javax.annotation.Nonnull;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator;
/**
* User: serso
* Date: 6/17/13
* Time: 9:30 PM
*/
enum CalculatorMode {
simple(R.string.cpp_wizard_mode_simple) {
@Override
protected void apply(@Nonnull SharedPreferences preferences) {
CalculatorPreferences.Gui.layout.putPreference(preferences, CalculatorPreferences.Gui.Layout.simple);
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.deg);
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, false);
AndroidCalculatorEngine.Preferences.roundResult.putPreference(preferences, true);
}
},
engineer(R.string.cpp_wizard_mode_engineer) {
@Override
protected void apply(@Nonnull SharedPreferences preferences) {
CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator);
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.rad);
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, true);
AndroidCalculatorEngine.Preferences.roundResult.putPreference(preferences, false);
}
};
private final int nameResId;
CalculatorMode(int nameResId) {
this.nameResId = nameResId;
}
int getNameResId() {
return nameResId;
}
protected abstract void apply(@Nonnull SharedPreferences preferences);
}

View File

@ -5,7 +5,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
@ -46,7 +45,6 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
private View prevButton; private View prevButton;
private View nextButton; private View nextButton;
private View finishButton; private View finishButton;
private ViewGroup wizardContent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -56,7 +54,6 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
prevButton = findViewById(R.id.wizard_prev_button); prevButton = findViewById(R.id.wizard_prev_button);
nextButton = findViewById(R.id.wizard_next_button); nextButton = findViewById(R.id.wizard_next_button);
finishButton = findViewById(R.id.wizard_finish_button); finishButton = findViewById(R.id.wizard_finish_button);
wizardContent = (ViewGroup) findViewById(R.id.wizard_content);
String wizardName = null; String wizardName = null;
WizardStep step = null; WizardStep step = null;
@ -79,33 +76,48 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
final FragmentManager fm = getSupportFragmentManager(); final FragmentManager fm = getSupportFragmentManager();
final FragmentTransaction ft = fm.beginTransaction(); final FragmentTransaction ft = fm.beginTransaction();
if (this.step != null) { hideFragment(fm, ft);
final Fragment oldFragment = fm.findFragmentByTag(this.step.getFragmentTag());
if (oldFragment != null) {
ft.hide(oldFragment);
}
}
this.step = step; this.step = step;
Fragment newFragment = fm.findFragmentByTag(step.getFragmentTag()); showFragment(fm, ft);
if(newFragment == null) {
newFragment = Fragment.instantiate(this, step.getFragmentClass().getName());
ft.add(R.id.wizard_content, newFragment, step.getFragmentTag());
} else {
ft.show(newFragment);
}
ft.commit(); ft.commit();
initNextButton();
initPrevButton();
}
}
private void initPrevButton() {
final WizardStep prevStep = flow.getPrevStep(step);
if (prevStep == null) {
prevButton.setVisibility(GONE);
prevButton.setOnClickListener(null);
} else {
prevButton.setVisibility(VISIBLE);
prevButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (tryGoPrev()) {
setStep(prevStep);
}
}
});
}
}
private void initNextButton() {
final WizardStep nextStep = flow.getNextStep(step); final WizardStep nextStep = flow.getNextStep(step);
if (nextStep == null) { if (nextStep == null) {
finishButton.setVisibility(VISIBLE); finishButton.setVisibility(VISIBLE);
finishButton.setOnClickListener(new View.OnClickListener() { finishButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (tryGoNext()) {
finish(); finish();
} }
}
}); });
nextButton.setVisibility(GONE); nextButton.setVisibility(GONE);
@ -118,23 +130,59 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
nextButton.setOnClickListener(new View.OnClickListener() { nextButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (tryGoNext()) {
setStep(nextStep); setStep(nextStep);
} }
}
}); });
} }
}
final WizardStep prevStep = flow.getPrevStep(step); private boolean tryGoPrev() {
if (prevStep == null) { if (this.step == null) {
prevButton.setVisibility(GONE); return true;
prevButton.setOnClickListener(null);
} else { } else {
prevButton.setVisibility(VISIBLE); final Fragment fragment = getSupportFragmentManager().findFragmentByTag(this.step.getFragmentTag());
prevButton.setOnClickListener(new View.OnClickListener() { if (fragment != null) {
@Override return this.step.onPrev(fragment);
public void onClick(View v) { } else {
setStep(prevStep); return true;
} }
}); }
}
private boolean tryGoNext() {
if (this.step == null) {
return true;
} else {
final Fragment fragment = getSupportFragmentManager().findFragmentByTag(this.step.getFragmentTag());
if (fragment != null) {
return this.step.onNext(fragment);
} else {
return true;
}
}
}
@Nonnull
private Fragment showFragment(@Nonnull FragmentManager fm, @Nonnull FragmentTransaction ft) {
Fragment newFragment = fm.findFragmentByTag(this.step.getFragmentTag());
if (newFragment == null) {
newFragment = Fragment.instantiate(this, this.step.getFragmentClass().getName());
ft.add(R.id.wizard_content, newFragment, this.step.getFragmentTag());
} else {
ft.show(newFragment);
}
return newFragment;
}
private void hideFragment(@Nonnull FragmentManager fm, @Nonnull FragmentTransaction ft) {
if (this.step != null) {
final Fragment oldFragment = fm.findFragmentByTag(this.step.getFragmentTag());
if (oldFragment != null) {
ft.hide(oldFragment);
} }
} }
} }
@ -146,4 +194,11 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
out.putSerializable(STEP, step); out.putSerializable(STEP, step);
} }
WizardStep getStep() {
return step;
}
WizardFlow getFlow() {
return flow;
}
} }

View File

@ -1,39 +1,30 @@
package org.solovyev.android.calculator.wizard; package org.solovyev.android.calculator.wizard;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import jscl.AngleUnit; import com.actionbarsherlock.app.SherlockFragment;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.CalculatorPreferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.list.ListItem; import org.solovyev.android.list.ListItem;
import org.solovyev.android.list.ListItemAdapter; import org.solovyev.android.list.ListItemAdapter;
import com.actionbarsherlock.app.SherlockFragment; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator; import static org.solovyev.android.calculator.wizard.CalculatorMode.simple;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple;
/** /**
* User: serso * User: serso
* Date: 6/16/13 * Date: 6/16/13
* Time: 9:59 PM * Time: 9:59 PM
*/ */
public final class ChooseModeWizardStep extends SherlockFragment implements WizardStepFragment { public final class ChooseModeWizardStep extends SherlockFragment {
@Nullable @Nullable
private Spinner layoutSpinner; private Spinner layoutSpinner;
@ -49,33 +40,25 @@ public final class ChooseModeWizardStep extends SherlockFragment implements Wiza
layoutSpinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner); layoutSpinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
final List<ModeListItem> listItems = new ArrayList<ModeListItem>(); final List<ModeListItem> listItems = new ArrayList<ModeListItem>();
for (Mode mode : Mode.values()) { for (CalculatorMode mode : CalculatorMode.values()) {
listItems.add(new ModeListItem(mode)); listItems.add(new ModeListItem(mode));
} }
layoutSpinner.setAdapter(ListItemAdapter.newInstance(getActivity(), listItems)); layoutSpinner.setAdapter(ListItemAdapter.newInstance(getActivity(), listItems));
} }
@Override @Nonnull
public boolean onNext() { CalculatorMode getSelectedMode() {
CalculatorMode mode = simple;
if (layoutSpinner != null) { if (layoutSpinner != null) {
final int position = layoutSpinner.getSelectedItemPosition(); final int position = layoutSpinner.getSelectedItemPosition();
final Mode mode; if (position >= 0 && position < CalculatorMode.values().length) {
if (position >= 0 && position < Mode.values().length) { mode = CalculatorMode.values()[position];
mode = Mode.values()[position]; }
} else {
mode = Mode.Simple;
} }
mode.apply(PreferenceManager.getDefaultSharedPreferences(getActivity())); return mode;
}
return true;
}
@Override
public boolean onPrev() {
return true;
} }
/* /*
@ -89,9 +72,9 @@ public final class ChooseModeWizardStep extends SherlockFragment implements Wiza
private static final class ModeListItem implements ListItem { private static final class ModeListItem implements ListItem {
@Nonnull @Nonnull
private final Mode mode; private final CalculatorMode mode;
private ModeListItem(@Nonnull Mode mode) { private ModeListItem(@Nonnull CalculatorMode mode) {
this.mode = mode; this.mode = mode;
} }
@ -122,37 +105,4 @@ public final class ChooseModeWizardStep extends SherlockFragment implements Wiza
} }
} }
private static enum Mode {
Simple(R.string.cpp_wizard_mode_simple) {
@Override
protected void apply(@Nonnull SharedPreferences preferences) {
CalculatorPreferences.Gui.layout.putPreference(preferences, simple);
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.deg);
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, false);
AndroidCalculatorEngine.Preferences.roundResult.putPreference(preferences, true);
}
},
Engineer(R.string.cpp_wizard_mode_engineer) {
@Override
protected void apply(@Nonnull SharedPreferences preferences) {
CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator);
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.rad);
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, true);
AndroidCalculatorEngine.Preferences.roundResult.putPreference(preferences, false);
}
};
private final int nameResId;
Mode(int nameResId) {
this.nameResId = nameResId;
}
private int getNameResId() {
return nameResId;
}
protected abstract void apply(@Nonnull SharedPreferences preferences);
}
} }

View File

@ -1,5 +1,6 @@
package org.solovyev.android.calculator.wizard; package org.solovyev.android.calculator.wizard;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -11,8 +12,34 @@ import javax.annotation.Nonnull;
*/ */
enum WizardStep { enum WizardStep {
welcome(WelcomeWizardStep.class), welcome(WelcomeWizardStep.class) {
choose_mode(ChooseModeWizardStep.class); @Override
boolean onNext(@Nonnull Fragment fragment) {
return true;
}
@Override
boolean onPrev(@Nonnull Fragment fragment) {
return true;
}
},
choose_mode(ChooseModeWizardStep.class) {
@Override
boolean onNext(@Nonnull Fragment f) {
final ChooseModeWizardStep fragment = (ChooseModeWizardStep) f;
final CalculatorMode mode = fragment.getSelectedMode();
mode.apply(PreferenceManager.getDefaultSharedPreferences(f.getActivity()));
return true;
}
@Override
boolean onPrev(@Nonnull Fragment fragment) {
return true;
}
};
@Nonnull @Nonnull
private final Class<? extends Fragment> fragmentClass; private final Class<? extends Fragment> fragmentClass;
@ -29,4 +56,7 @@ enum WizardStep {
Class<? extends Fragment> getFragmentClass() { Class<? extends Fragment> getFragmentClass() {
return fragmentClass; return fragmentClass;
} }
abstract boolean onNext(@Nonnull Fragment fragment);
abstract boolean onPrev(@Nonnull Fragment fragment);
} }

View File

@ -1,8 +0,0 @@
package org.solovyev.android.calculator.wizard;
public interface WizardStepFragment {
public boolean onNext();
public boolean onPrev();
}

View File

@ -4,13 +4,16 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
/** /**
* User: serso * User: serso
* Date: 10/13/12 * Date: 10/13/12
* Time: 1:11 PM * Time: 1:11 PM
*/ */
@RunWith(value = CalculatorppTestRunner.class) @Config(manifest = Config.DEFAULT)
@RunWith(value = RobolectricTestRunner.class)
public class AndroidCalculatorEditorViewTest { public class AndroidCalculatorEditorViewTest {
@BeforeClass @BeforeClass

View File

@ -1,30 +0,0 @@
package org.solovyev.android.calculator;
import com.xtremelabs.robolectric.RobolectricConfig;
import com.xtremelabs.robolectric.RobolectricTestRunner;
import org.junit.runners.model.InitializationError;
import javax.annotation.Nonnull;
import java.io.File;
/**
* User: serso
* Date: 10/7/12
* Time: 5:36 PM
*/
public class CalculatorppTestRunner extends RobolectricTestRunner {
public CalculatorppTestRunner(@Nonnull Class<?> testClass) throws InitializationError {
super(testClass, new File("."));
}
@Override
public void setupApplicationState(RobolectricConfig robolectricConfig) {
try {
CalculatorTestUtils.staticSetUp();
} catch (Exception e) {
throw new AssertionError(e);
}
super.setupApplicationState(robolectricConfig);
}
}

View File

@ -7,13 +7,14 @@
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator.model;
import jscl.math.function.IConstant; import jscl.math.function.IConstant;
import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
import org.simpleframework.xml.Serializer; import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister; import org.simpleframework.xml.core.Persister;
import java.io.StringWriter; import java.io.StringWriter;
import static org.junit.Assert.assertEquals;
/** /**
* User: serso * User: serso
* Date: 11/7/11 * Date: 11/7/11
@ -49,7 +50,7 @@ public class VarTest {
final Serializer serializer = new Persister(); final Serializer serializer = new Persister();
serializer.write(vars, sw); serializer.write(vars, sw);
Assert.assertEquals(xml, sw.toString()); assertEquals(xml, sw.toString());
final Vars result = serializer.read(Vars.class, xml); final Vars result = serializer.read(Vars.class, xml);
final IConstant actualFirst = result.getEntities().get(0); final IConstant actualFirst = result.getEntities().get(0);
@ -61,8 +62,8 @@ public class VarTest {
} }
private void areEqual(IConstant expected, IConstant actual) { private void areEqual(IConstant expected, IConstant actual) {
Assert.assertEquals(expected.getName(), actual.getName()); assertEquals(expected.getName(), actual.getName());
Assert.assertEquals(expected.getDescription(), actual.getDescription()); assertEquals(expected.getDescription(), actual.getDescription());
Assert.assertEquals(expected.getValue(), actual.getValue()); assertEquals(expected.getValue(), actual.getValue());
} }
} }

View File

@ -1,8 +1,9 @@
package org.solovyev.android.calculator.plot; package org.solovyev.android.calculator.plot;
import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
/** /**
* User: serso * User: serso
* Date: 1/15/13 * Date: 1/15/13
@ -12,19 +13,19 @@ public class CalculatorGraph2dViewTest {
@Test @Test
public void testFormatTick() throws Exception { public void testFormatTick() throws Exception {
Assert.assertEquals("23324", CalculatorGraph2dView.formatTick(23324.0f, 0)); assertEquals("23324", CalculatorGraph2dView.formatTick(23324.0f, 0));
Assert.assertEquals("23324.1", CalculatorGraph2dView.formatTick(23324.1f, 1)); assertEquals("23324.1", CalculatorGraph2dView.formatTick(23324.1f, 1));
} }
@Test @Test
public void testCountTickDigits() throws Exception { public void testCountTickDigits() throws Exception {
Assert.assertEquals(0, CalculatorGraph2dView.countTickDigits(1)); assertEquals(0, CalculatorGraph2dView.countTickDigits(1));
Assert.assertEquals(0, CalculatorGraph2dView.countTickDigits(10)); assertEquals(0, CalculatorGraph2dView.countTickDigits(10));
Assert.assertEquals(0, CalculatorGraph2dView.countTickDigits(100)); assertEquals(0, CalculatorGraph2dView.countTickDigits(100));
Assert.assertEquals(1, CalculatorGraph2dView.countTickDigits(0.9f)); assertEquals(1, CalculatorGraph2dView.countTickDigits(0.9f));
Assert.assertEquals(1, CalculatorGraph2dView.countTickDigits(0.2f)); assertEquals(1, CalculatorGraph2dView.countTickDigits(0.2f));
Assert.assertEquals(1, CalculatorGraph2dView.countTickDigits(0.1f)); assertEquals(1, CalculatorGraph2dView.countTickDigits(0.1f));
Assert.assertEquals(2, CalculatorGraph2dView.countTickDigits(0.099f)); assertEquals(2, CalculatorGraph2dView.countTickDigits(0.099f));
Assert.assertEquals(3, CalculatorGraph2dView.countTickDigits(0.009f)); assertEquals(3, CalculatorGraph2dView.countTickDigits(0.009f));
} }
} }

View File

@ -0,0 +1,36 @@
package org.solovyev.android.calculator.wizard;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.util.ActivityController;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* User: serso
* Date: 6/17/13
* Time: 9:57 PM
*/
@Config(manifest = "android-app/AndroidManifest.xml")
@RunWith(value = RobolectricTestRunner.class)
public class CalculatorWizardActivityTest {
@Test
public void testRestoreState() throws Exception {
final ActivityController<CalculatorWizardActivity> controller = Robolectric.buildActivity(CalculatorWizardActivity.class);
controller.attach();
controller.create();
final CalculatorWizardActivity activity = controller.get();
activity.onCreate(null);
assertNotNull(activity.getFlow());
assertNotNull(activity.getStep());
assertEquals(activity.getFlow().getFirstStep(), activity.getStep());
}
}

View File

@ -1,15 +1,15 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import jscl.JsclMathEngine; import jscl.JsclMathEngine;
import junit.framework.Assert; import org.junit.Assert;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.solovyev.android.calculator.external.CalculatorExternalListenersContainer; import org.solovyev.android.calculator.external.CalculatorExternalListenersContainer;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.CalculatorHistory;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.*; import java.io.*;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
public class CalculatorTestUtils { public class CalculatorTestUtils {
// in seconds // in seconds
public static final int TIMEOUT = 3; public static final int TIMEOUT = 10;
public static void staticSetUp() throws Exception { public static void staticSetUp() 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(CalculatorExternalListenersContainer.class), Mockito.mock(CalculatorPlotter.class)); 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(CalculatorExternalListenersContainer.class), Mockito.mock(CalculatorPlotter.class));

View File

@ -256,7 +256,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version> <version>2.15</version>
<configuration> <configuration>
<forkMode>always</forkMode> <forkMode>always</forkMode>
</configuration> </configuration>