|
| 1 | +package cucumber.runtime.java8; |
| 2 | + |
| 3 | +import cucumber.runtime.HookDefinition; |
| 4 | +import cucumber.runtime.StepDefinition; |
| 5 | +import cucumber.runtime.java.LambdaGlueRegistry; |
| 6 | +import org.hamcrest.CustomTypeSafeMatcher; |
| 7 | +import org.junit.Rule; |
| 8 | +import org.junit.Test; |
| 9 | +import org.junit.rules.ExpectedException; |
| 10 | + |
| 11 | +public class Java8LambdaStepDefinitionMarksCorrectStackElementTest { |
| 12 | + |
| 13 | + @Rule |
| 14 | + public ExpectedException expectedException = ExpectedException.none(); |
| 15 | + |
| 16 | + private final MyLambdaGlueRegistry myLambdaGlueRegistry = new MyLambdaGlueRegistry(); |
| 17 | + |
| 18 | + @Test |
| 19 | + public void exception_from_step_should_be_defined_at_step_definition_class() throws Throwable { |
| 20 | + LambdaGlueRegistry.INSTANCE.set(myLambdaGlueRegistry); |
| 21 | + new SomeLambdaStepDefs(); |
| 22 | + final StepDefinition stepDefinition = myLambdaGlueRegistry.getStepDefinition(); |
| 23 | + |
| 24 | + expectedException.expect(new CustomTypeSafeMatcher<Throwable>("exception with matching stack trace") { |
| 25 | + @Override |
| 26 | + protected boolean matchesSafely(Throwable item) { |
| 27 | + for (StackTraceElement stackTraceElement : item.getStackTrace()) { |
| 28 | + if(stepDefinition.isDefinedAt(stackTraceElement)){ |
| 29 | + return SomeLambdaStepDefs.class.getName().equals(stackTraceElement.getClassName()); |
| 30 | + } |
| 31 | + |
| 32 | + } |
| 33 | + return false; |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + stepDefinition.execute("en", new Object[0]); |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + private class MyLambdaGlueRegistry implements LambdaGlueRegistry { |
| 42 | + |
| 43 | + private StepDefinition stepDefinition; |
| 44 | + |
| 45 | + @Override |
| 46 | + public void addStepDefinition(StepDefinition stepDefinition) { |
| 47 | + this.stepDefinition = stepDefinition; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public void addBeforeHookDefinition(HookDefinition beforeHook) { |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void addAfterHookDefinition(HookDefinition afterHook) { |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + public StepDefinition getStepDefinition() { |
| 61 | + return stepDefinition; |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments