tests added
This commit is contained in:
parent
21e8581f1f
commit
46e2a1c736
@ -142,7 +142,7 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finishFlow() {
|
void finishFlow() {
|
||||||
if (flow != null && step != null) {
|
if (flow != null && step != null) {
|
||||||
Wizard.saveWizardFinished(flow, step);
|
Wizard.saveWizardFinished(flow, step);
|
||||||
}
|
}
|
||||||
@ -237,6 +237,18 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
|
|||||||
return flow;
|
return flow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
View getPrevButton() {
|
||||||
|
return prevButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
View getNextButton() {
|
||||||
|
return nextButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
View getFinishButton() {
|
||||||
|
return finishButton;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
|
@ -39,8 +39,8 @@ public final class Wizard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWizardFinished(@Nonnull String name, @Nonnull Context context) {
|
public static boolean isWizardFinished(@Nonnull String name) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||||
return preferences.getBoolean(makeFlowFinishedPreferenceKey(name), false);
|
return preferences.getBoolean(makeFlowFinishedPreferenceKey(name), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
|
||||||
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;
|
||||||
@ -12,7 +13,13 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.shadows.ShadowActivity;
|
import org.robolectric.shadows.ShadowActivity;
|
||||||
import org.robolectric.util.ActivityController;
|
import org.robolectric.util.ActivityController;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static android.view.View.GONE;
|
||||||
|
import static android.view.View.VISIBLE;
|
||||||
|
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.solovyev.android.calculator.wizard.CalculatorWizardActivity.startWizard;
|
import static org.solovyev.android.calculator.wizard.CalculatorWizardActivity.startWizard;
|
||||||
import static org.solovyev.android.calculator.wizard.WizardStep.choose_mode;
|
import static org.solovyev.android.calculator.wizard.WizardStep.choose_mode;
|
||||||
|
|
||||||
@ -69,8 +76,8 @@ public class CalculatorWizardActivityTest {
|
|||||||
intent.setClass(activity, CalculatorWizardActivity.class);
|
intent.setClass(activity, CalculatorWizardActivity.class);
|
||||||
intent.putExtra(Wizard.FLOW, Wizard.DEFAULT_WIZARD_FLOW);
|
intent.putExtra(Wizard.FLOW, Wizard.DEFAULT_WIZARD_FLOW);
|
||||||
controller = Robolectric.buildActivity(CalculatorWizardActivity.class).withIntent(intent);
|
controller = Robolectric.buildActivity(CalculatorWizardActivity.class).withIntent(intent);
|
||||||
|
controller.create();
|
||||||
activity = controller.get();
|
activity = controller.get();
|
||||||
controller.create(null);
|
|
||||||
assertEquals(Wizard.DEFAULT_WIZARD_FLOW, activity.getFlow().getName());
|
assertEquals(Wizard.DEFAULT_WIZARD_FLOW, activity.getFlow().getName());
|
||||||
assertEquals(activity.getFlow().getFirstStep(), activity.getStep());
|
assertEquals(activity.getFlow().getFirstStep(), activity.getStep());
|
||||||
|
|
||||||
@ -125,4 +132,52 @@ public class CalculatorWizardActivityTest {
|
|||||||
activity.setStep(choose_mode);
|
activity.setStep(choose_mode);
|
||||||
assertEquals(activity.getString(choose_mode.getTitleResId()), activity.getTitle().toString());
|
assertEquals(activity.getString(choose_mode.getTitleResId()), activity.getTitle().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNextButtonShouldNotBeShownAtTheEnd() throws Exception {
|
||||||
|
setLastStep();
|
||||||
|
assertEquals(VISIBLE, activity.getPrevButton().getVisibility());
|
||||||
|
assertEquals(GONE, activity.getNextButton().getVisibility());
|
||||||
|
assertEquals(VISIBLE, activity.getFinishButton().getVisibility());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setLastStep() {
|
||||||
|
activity.setStep(WizardStep.values()[WizardStep.values().length - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPrevButtonShouldNotBeShownAtTheStart() throws Exception {
|
||||||
|
setFirstStep();
|
||||||
|
assertEquals(VISIBLE, activity.getNextButton().getVisibility());
|
||||||
|
assertEquals(GONE, activity.getFinishButton().getVisibility());
|
||||||
|
assertEquals(GONE, activity.getPrevButton().getVisibility());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFirstStep() {
|
||||||
|
activity.setStep(WizardStep.values()[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShouldSaveLastWizardStateOnPause() throws Exception {
|
||||||
|
assertNull(Wizard.getLastSavedWizardStepName(activity.getFlow().getName()));
|
||||||
|
activity.setStep(WizardStep.drag_button_step);
|
||||||
|
activity.onPause();
|
||||||
|
assertEquals(WizardStep.drag_button_step.getName(), Wizard.getLastSavedWizardStepName(activity.getFlow().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShouldSaveFinishedIfLastStep() throws Exception {
|
||||||
|
assertFalse(Wizard.isWizardFinished(activity.getFlow().getName()));
|
||||||
|
setLastStep();
|
||||||
|
activity.finishFlow();
|
||||||
|
assertTrue(Wizard.isWizardFinished(activity.getFlow().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShouldNotSaveFinishedIfNotLastStep() throws Exception {
|
||||||
|
assertFalse(Wizard.isWizardFinished(activity.getFlow().getName()));
|
||||||
|
setFirstStep();
|
||||||
|
activity.finishFlow();
|
||||||
|
assertFalse(Wizard.isWizardFinished(activity.getFlow().getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user