-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rules acceptance test for junit4/ (#22)
* hint: only works for 4.9 <= junit < 5.0) Signed-off-by: Andreas Schmid <[email protected]>
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
junit4/src/integTest/java/com/tngtech/test/java/junit/dataprovider/RuleAcceptanceTest.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,48 @@ | ||
package com.tngtech.test.java.junit.dataprovider; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestWatcher; | ||
import org.junit.runner.Description; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | ||
|
||
@RunWith(DataProviderRunner.class) | ||
public class RuleAcceptanceTest { | ||
|
||
public static class SomeTestRule extends TestWatcher { | ||
boolean started; | ||
|
||
@Override | ||
protected void starting(Description description) { | ||
started = true; | ||
} | ||
|
||
@Override | ||
protected void finished(Description description) { | ||
assertThat(started).as("Rule was not started, but 'finished' called").isTrue(); | ||
} | ||
} | ||
|
||
@ClassRule | ||
public static final SomeTestRule classRule = new SomeTestRule(); | ||
|
||
@Rule | ||
public SomeTestRule rule = new SomeTestRule(); | ||
|
||
@Test | ||
public void testClassRuleShouldBeStartedBeforeTest() { | ||
// Expected: | ||
assertThat(classRule.started).as("'@ClassRule' was not started").isTrue(); | ||
} | ||
|
||
@Test | ||
public void testRuleShouldBeStartedBeforeTest() { | ||
// Expected: | ||
assertThat(rule.started).as("'@Rule' was not started").isTrue(); | ||
} | ||
} |