package cucumber.internal;

import org.junit.Test;
import static org.junit.Assert.*;

import java.util.List;

public class StepMotherTest {
    @Test
    public void shouldInvokeSuccessfully() throws Throwable {
        StepMother mother = new StepMother();
        mother.add(CukeSteps.class);
        mother.newWorld();

        StepDefinition given = mother.getStepDefinitions().get(0);
        StepDefinition then = mother.getStepDefinitions().get(1);

        given.invokeOnTarget(new Object[]{"56", "green"});
        then.invokeOnTarget(new Object[]{"56", "green"});
    }

    @Test(expected=RuntimeException.class) 
    public void shouldInvokeWithFailure() throws Throwable {
        StepMother mother = new StepMother();
        mother.add(CukeSteps.class);
        mother.newWorld();

        StepDefinition given = mother.getStepDefinitions().get(0);
        StepDefinition then = mother.getStepDefinitions().get(1);

        given.invokeOnTarget(new Object[]{"56", "green"});
        then.invokeOnTarget(new Object[]{"99", "green"});
    }

    @Test
    public void shouldConvertLongs() throws Throwable {
        StepMother mother = new StepMother();
        mother.add(CukeSteps.class);
        mother.newWorld();

        StepDefinition given = mother.getStepDefinitions().get(2);
        given.invokeOnTarget(new Object[]{"33"});
    }

    @Test
    public void shouldCreateNewStepDefinitionsForEachNewWorld() throws Throwable {
        StepMother mother = new StepMother();
        mother.add(CukeSteps.class);
        mother.newWorld();
        List<StepDefinition> stepDefs1 = mother.getStepDefinitions();
        assertEquals(3, stepDefs1.size()); 

        mother.newWorld();
        List<StepDefinition> stepDefs2 = mother.getStepDefinitions();
        assertEquals(3, stepDefs2.size());
        
        for (int i = 0; i < 3; i++) {
        	assertNotSame(stepDefs1.get(i), stepDefs2.get(i));
        }
    }
}

@@ -79,16 +79,44 @@
 ert.*;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -1572,32 +1572,41 @@
 her.newWorld();%0A
+        %0A
         List%3CSte
@@ -1702,16 +1702,193 @@
 ize()); 
+%0A        %0A        List%3CStepDefinition%3E oldSteps = new ArrayList%3CStepDefinition%3E();%0A        for (StepDefinition stepDefinition : stepDefs1) %7B%0A%09%09%09oldSteps.add(stepDefinition);%0A%09%09%7D
 %0A%0A      
@@ -2091,25 +2091,24 @@
 NotSame(
-stepDefs1
+oldSteps
 .get(i),

Fix broken test