package org.jbehave.scenario.steps;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.jbehave.Ensure.ensureThat;

import org.jbehave.scenario.ScenarioDefinition;
import org.jbehave.scenario.errors.PendingError;
import org.junit.Test;

public class UnmatchedToPendingStepCreatorBehaviour {

    @Test
    public void shouldMatchUpStepsAndScenarioDefinitionToCreateExecutableSteps() {
        // Given
        UnmatchedToPendingStepCreator creator = new UnmatchedToPendingStepCreator();
        
        CandidateStep candidate = mock(CandidateStep.class);
        Steps steps = mock(Steps.class);
        Step executableStep = mock(Step.class);
        
        stub(candidate.matches("my step")).toReturn(true);
        stub(candidate.createFrom("my step")).toReturn(executableStep);
        stub(steps.getSteps()).toReturn(new CandidateStep[] {candidate});
        
        // When
        Step[] executableSteps = creator.createStepsFrom(new ScenarioDefinition("", "my step"), steps);
        
        // Then
        ensureThat(executableSteps.length, equalTo(1));
        ensureThat(executableSteps[0], equalTo(executableStep));
    }

    @Test
    public void shouldProvidePendingStepsForAnyStepsWhichAreNotAvailable() {
        // Given
        UnmatchedToPendingStepCreator creator = new UnmatchedToPendingStepCreator();
        
        CandidateStep candidate = mock(CandidateStep.class);
        Steps steps = mock(Steps.class);
        Step executableStep = mock(Step.class);
        
        stub(candidate.matches("my step")).toReturn(false);
        stub(candidate.createFrom("my step")).toReturn(executableStep);
        stub(steps.getSteps()).toReturn(new CandidateStep[] {candidate});
        
        // When
        Step[] executableSteps = creator.createStepsFrom(new ScenarioDefinition("", "my step"), steps);
        
        // Then
        ensureThat(executableSteps.length, equalTo(1));
        StepResult result = executableSteps[0].perform();
        ensureThat(result.getThrowable().getMessage(), equalTo("Pending: my step"));
    }
}

@@ -34,88 +34,8 @@
 s;%0A%0A
-import static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.stub;%0A
 impo
@@ -128,56 +128,88 @@
 at;%0A
-%0A
 import 
-org.jbehave.scenario.ScenarioDefinition;
+static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.stub;%0A
 %0Aimp
@@ -237,27 +237,26 @@
 rio.
-errors.PendingError
+ScenarioDefinition
 ;%0Aim

Remove unused imports.