Skip to content

Commit

Permalink
Rename the UndefinedStepException class to MissingStepDefinitionExcep…
Browse files Browse the repository at this point in the history
…tion

This pull request fixes #2026 - When a step definition is missing cucumber fails with a undefined step exception. This seems kinda misleading because its the step definition that was missing, not the step that was undefined.
  • Loading branch information
sailfishdev committed Jun 21, 2020
1 parent 1fdf68f commit a52ec88
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
Expand Up @@ -7,11 +7,11 @@

import static java.util.stream.Collectors.joining;

final class UndefinedStepException extends IncompleteExecutionException {
final class MissingStepDefinitionException extends IncompleteExecutionException {

private static final long serialVersionUID = 1L;

UndefinedStepException(List<Suggestion> suggestions) {
MissingStepDefinitionException(List<Suggestion> suggestions) {
super(createMessage(suggestions));
}

Expand Down
Expand Up @@ -22,7 +22,7 @@ void assertTestCasePassed() {
delegate.assertTestCasePassed(
TestAbortedException::new,
Function.identity(),
UndefinedStepException::new,
MissingStepDefinitionException::new,
Function.identity());
}

Expand Down
Expand Up @@ -223,7 +223,7 @@ void undefined() {
bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
bus.send(new TestCaseFinished(Instant.now(), testCase, result));
Exception exception = assertThrows(Exception.class, observer::assertTestCasePassed);
assertThat(exception.getCause(), instanceOf(UndefinedStepException.class));
assertThat(exception.getCause(), instanceOf(MissingStepDefinitionException.class));

assertThat(exception.getCause().getMessage(), is("" +
"The step \"mocked\" is undefined. You can implement it using the snippet(s) below:\n" +
Expand Down
4 changes: 2 additions & 2 deletions junit/src/main/java/io/cucumber/junit/JUnitReporter.java
Expand Up @@ -125,11 +125,11 @@ private void handleStepResult(PickleStepTestStep testStep, Result result) {
case UNDEFINED:
Collection<String> snippets = snippetsPerStep.remove(
new StepLocation(testStep.getUri(), testStep.getStepLine()));
stepErrors.add(new UndefinedStepException(
stepErrors.add(new MissingStepDefinitionException(
testStep.getStepText(),
snippets,
snippetsPerStep.values()));
stepNotifier.addFailure(error == null ? new UndefinedStepException(snippets) : error);
stepNotifier.addFailure(error == null ? new MissingStepDefinitionException(snippets) : error);
break;
default:
throw new IllegalStateException("Unexpected result status: " + result.getStatus());
Expand Down
Expand Up @@ -5,11 +5,11 @@
import java.util.Set;
import java.util.stream.Collectors;

final class UndefinedStepException extends RuntimeException {
final class MissingStepDefinitionException extends RuntimeException {

private static final long serialVersionUID = 1L;

UndefinedStepException(Collection<String> snippets) {
MissingStepDefinitionException(Collection<String> snippets) {
super(createMessage(snippets), null, false, false);
}

Expand All @@ -30,7 +30,7 @@ private static void appendSnippets(Collection<String> snippets, StringBuilder sb
});
}

UndefinedStepException(String stepText, Collection<String> snippets, Collection<Collection<String>> otherSnippets) {
MissingStepDefinitionException(String stepText, Collection<String> snippets, Collection<Collection<String>> otherSnippets) {
super(createMessage(stepText, snippets, otherSnippets), null, false, false);
}

Expand Down
Expand Up @@ -7,11 +7,11 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

class UndefinedStepExceptionTest {
class MissingStepDefinitionExceptionTest {

@Test
void should_generate_a_message_for_a_single_snippet() {
UndefinedStepException exception = new UndefinedStepException(singletonList("snippet"));
MissingStepDefinitionException exception = new MissingStepDefinitionException(singletonList("snippet"));
assertThat(exception.getMessage(), is("" +
"This step is undefined. You can implement it using the snippet(s) below:\n" +
"\n" +
Expand All @@ -20,7 +20,7 @@ void should_generate_a_message_for_a_single_snippet() {

@Test
void should_generate_a_message_for_step_without_additional_snippets() {
UndefinedStepException exception = new UndefinedStepException(
MissingStepDefinitionException exception = new MissingStepDefinitionException(
"step text",
singletonList("snippet"),
emptyList());
Expand All @@ -32,7 +32,7 @@ void should_generate_a_message_for_step_without_additional_snippets() {

@Test
void should_generate_a_message_for_step_with_additional_snippets() {
UndefinedStepException exception = new UndefinedStepException(
MissingStepDefinitionException exception = new MissingStepDefinitionException(
"step text",
singletonList("snippet"),
singletonList(singletonList("additional snippet")));
Expand All @@ -49,7 +49,7 @@ void should_generate_a_message_for_step_with_additional_snippets() {

@Test
void should_generate_a_message_for_step_with_additional_duplicated_snippets() {
UndefinedStepException exception = new UndefinedStepException(
MissingStepDefinitionException exception = new MissingStepDefinitionException(
"step text",
singletonList("snippet"),
singletonList(singletonList("snippet")));
Expand Down
Expand Up @@ -7,11 +7,11 @@

import static java.util.stream.Collectors.joining;

final class UndefinedStepException extends SkipException {
final class MissingStepDefinitionException extends SkipException {

private static final long serialVersionUID = 1L;

UndefinedStepException(List<Suggestion> suggestions) {
MissingStepDefinitionException(List<Suggestion> suggestions) {
super(createMessage(suggestions));
}

Expand Down
Expand Up @@ -25,7 +25,7 @@ void assertTestCasePassed() {
(exception) -> exception instanceof SkipException
? exception
: new SkipException(exception.getMessage(), exception),
UndefinedStepException::new,
MissingStepDefinitionException::new,
Function.identity());
}

Expand Down
Expand Up @@ -41,7 +41,7 @@ public void runScenarioWithUndefinedStepsStrict() {
PickleWrapper wrapper = (PickleWrapper) scenario[0];

assertThrows(
UndefinedStepException.class,
MissingStepDefinitionException.class,
() -> testNGCucumberRunner.runScenario(wrapper.getPickle()));
}

Expand Down

0 comments on commit a52ec88

Please sign in to comment.