Skip to content

Commit

Permalink
Updating JUnit with ExpectedException
Browse files Browse the repository at this point in the history
  • Loading branch information
zutshiy committed Apr 7, 2019
1 parent 5a70a10 commit 15eda70
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions junit/src/test/java/cucumber/runtime/junit/CucumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.runtime.CucumberException;
import gherkin.ParserException.CompositeParserException;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.ParallelComputer;
import org.junit.rules.ExpectedException;
import org.junit.runner.Description;
import org.junit.runner.Request;
import org.junit.runner.RunWith;
Expand All @@ -22,15 +25,17 @@

import static java.util.Collections.emptyList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.isA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.hamcrest.CoreMatchers.containsString;
import static org.mockito.ArgumentMatchers.argThat;

public class CucumberTest {

@Rule
public ExpectedException thrownException = ExpectedException.none();
private String dir;

@Before
Expand Down Expand Up @@ -61,15 +66,11 @@ public void finds_features_based_on_explicit_root_package() throws Initializatio
assertEquals("Feature: Feature A", cucumber.getChildren().get(0).getName());
}

@Test
public void testThatParsingErrorsIsNicelyReported() throws Exception {
try {
new Cucumber(LexerErrorFeature.class);
fail("Expecting error");
} catch (CucumberException e) {
assertThat(e.getCause().toString(), containsString("gherkin.ParserException$CompositeParserException: Parser errors:"));
}
}
@Test
public void testThatParsingErrorsIsNicelyReported() throws Exception {
thrownException.expectCause(isA(CompositeParserException.class));
new Cucumber(LexerErrorFeature.class);
}

@Test
public void testThatFileIsNotCreatedOnParsingError() throws Exception {
Expand Down

0 comments on commit 15eda70

Please sign in to comment.