Added StepState and StepController to execute different actions on the same "And." calls.

This commit is contained in:
magenoxx 2010-12-20 10:16:29 +03:00
parent d898c083d4
commit f299e31237
6 changed files with 51 additions and 4 deletions

View file

@ -0,0 +1,19 @@
package org.mage.test.bdd;
/**
* Controls steps of bdd calls.
* Uses step for the same "And" calls depending on previous calls.
* So "And." can be either "Given." or "Then." depending on "Given" or "Then" was called previously.
*
* Example:
*
* Given.I.have.a.card("Island"); // remember step here
* And.battlefield.has("Plains"); // "And" replaced and Given.battlefield.has("Plains"); is called
*
* Then.graveyards.empty(); // remember step here
* And.battlefield.has("Plains"); // "And" replaced and Then.battlefield.has("Plains"); is called
*
*/
public class StepController {
public static StepState currentState = StepState.NONE;
}

View file

@ -0,0 +1,8 @@
package org.mage.test.bdd;
public enum StepState {
GIVEN,
WHEN,
THEN,
NONE
}

View file

@ -1,13 +1,20 @@
package org.mage.test.bdd.given; package org.mage.test.bdd.given;
import org.mage.test.base.MageBase; import org.mage.test.base.MageBase;
import org.mage.test.bdd.StepController;
import org.mage.test.bdd.StepState;
public class A { public class A {
public static void card(String cardName) throws Exception { private StepState step;
public A(StepState step) {
this.step = step;
}
public void card(String cardName) throws Exception {
MageBase.getInstance().giveme(cardName); MageBase.getInstance().giveme(cardName);
Thread.sleep(4000); Thread.sleep(4000);
if (!MageBase.getInstance().checkIhave(cardName)) { if (!MageBase.getInstance().checkIhave(cardName)) {
throw new IllegalStateException("Couldn't find a card in hand: " + cardName); throw new IllegalStateException("Couldn't find a card in hand: " + cardName);
} }
StepController.currentState = this.step;
} }
} }

View file

@ -1,8 +1,9 @@
package org.mage.test.bdd.given; package org.mage.test.bdd.given;
import org.mage.test.bdd.StepState;
import org.mage.test.bdd.and.Phase; import org.mage.test.bdd.and.Phase;
public class Given { public class Given {
public static I I; public static I I = new I(StepState.GIVEN);
public static Phase phase; public static Phase phase;
} }

View file

@ -1,5 +1,11 @@
package org.mage.test.bdd.given; package org.mage.test.bdd.given;
import org.mage.test.bdd.StepController;
import org.mage.test.bdd.StepState;
public class Have { public class Have {
public static A a; public Have(StepState step) {
a = new A(step);
}
public A a;
} }

View file

@ -1,5 +1,11 @@
package org.mage.test.bdd.given; package org.mage.test.bdd.given;
import org.mage.test.bdd.StepController;
import org.mage.test.bdd.StepState;
public class I { public class I {
public static Have have; public I(StepState step) {
have = new Have(step);
}
public Have have;
} }