-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from TNG/nosuperclass
Use JGiven by just using JUnit rules
- Loading branch information
Showing
5 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
jgiven-examples/src/test/java/com/tngtech/jgiven/examples/userguide/UsingRulesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.tngtech.jgiven.examples.userguide; | ||
|
||
import com.tngtech.jgiven.annotation.ScenarioStage; | ||
import com.tngtech.jgiven.junit.ScenarioExecutionRule; | ||
import com.tngtech.jgiven.junit.ScenarioReportRule; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
//tag::noPackage[] | ||
|
||
public class UsingRulesTest { | ||
|
||
@ClassRule | ||
public static final ScenarioReportRule writerRule = new ScenarioReportRule(); | ||
|
||
@Rule | ||
public final ScenarioExecutionRule scenarioRule = new ScenarioExecutionRule(); | ||
|
||
@ScenarioStage | ||
GivenSomeState someState; | ||
|
||
@ScenarioStage | ||
WhenSomeAction someAction; | ||
|
||
@ScenarioStage | ||
ThenSomeOutcome someOutcome; | ||
|
||
@Test | ||
public void something_should_happen() { | ||
someState.given().some_state(); | ||
someAction.when().some_action(); | ||
someOutcome.then().some_outcome(); | ||
} | ||
} | ||
//end::noPackage[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
jgiven-junit/src/test/java/com/tngtech/jgiven/junit/OnlyRulesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.tngtech.jgiven.junit; | ||
|
||
import com.tngtech.jgiven.annotation.ScenarioStage; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
|
||
import com.tngtech.jgiven.Stage; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Verifies that JGiven can be used without inheriting from any class, | ||
* just by using the two JGiven rules | ||
*/ | ||
public class OnlyRulesTest { | ||
|
||
@ClassRule | ||
public static final ScenarioReportRule writerRule = new ScenarioReportRule(); | ||
|
||
@Rule | ||
public final ScenarioExecutionRule scenarioRule = new ScenarioExecutionRule(); | ||
|
||
@ScenarioStage | ||
TestStage stage; | ||
|
||
@Test | ||
public void JGiven_can_be_used_just_by_using_JUnit_rules() { | ||
stage.given().something(); | ||
|
||
assertThat(scenarioRule.getScenario().getScenarioModel().getCase(0).getFirstStep().getLastWord().getValue()).isEqualTo("something"); | ||
} | ||
|
||
public static class TestStage extends Stage<TestStage> { | ||
public void something() { | ||
|
||
} | ||
} | ||
|
||
} |