Skip to content

Commit

Permalink
Merge branch 'issue22-rule-acceptance-test'
Browse files Browse the repository at this point in the history
* issue22-rule-acceptance-test:
  add rules acceptance test for junit4/ (#22)
aaschmid committed Jul 10, 2018
2 parents ce7ebd8 + b4b93df commit 2d2d266
Showing 1 changed file with 48 additions and 0 deletions.
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();
}
}

0 comments on commit 2d2d266

Please sign in to comment.