Title: [1491] trunk/core/jbehave-pico/src/main/java/org/jbehave/scenario/steps/pico: better implementation for container passing
Revision
1491
Author
paul
Date
2010-01-04 15:27:53 -0600 (Mon, 04 Jan 2010)

Log Message

better implementation for container passing

Modified Paths


Diff

Modified: trunk/core/jbehave-pico/src/behaviour/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStepBehaviour.java (1490 => 1491)

--- trunk/core/jbehave-pico/src/behaviour/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStepBehaviour.java	2010-01-04 09:36:55 UTC (rev 1490)
+++ trunk/core/jbehave-pico/src/behaviour/java/org/jbehave/scenario/steps/pico/PicoEnabledCandidateStepBehaviour.java	2010-01-04 21:27:53 UTC (rev 1491)
@@ -57,6 +57,7 @@
     @Before
     public void setup() {
         parent = new DefaultPicoContainer(new Caching().wrap(new ConstructorInjection()));
+        parent.as(Characteristics.NO_CACHE).addComponent(new PicoEnabledStepsConfiguration(parent));
     }
 
 
@@ -211,7 +212,7 @@
     @Test
     @Ignore
     public void shouldCreateStepFromTableValuesViaAnnotations() throws Exception {
-    	AnnotationNamedParameterSteps steps = new AnnotationNamedParameterSteps();
+    	AnnotationNamedParameterSteps steps = new AnnotationNamedParameterSteps(parent.getComponent(PicoEnabledStepsConfiguration.class));
     	tableRow.put("ith", "first");
     	tableRow.put("nth", "ground");
         CandidateStep candidateStep = new CandidateStep("I live on the ith floor but some call it the nth",
@@ -261,7 +262,6 @@
     public void shouldCreateStepsOfDifferentTypesWithSameMatchingPattern() throws Throwable {
         parent.addComponent(NamedTypeSteps.class);
         NamedTypeSteps steps = parent.getComponent(NamedTypeSteps.class);
-        steps.withParentContainer(parent);
         CandidateStep[] candidateSteps = steps.getSteps();
         ensureThat(candidateSteps.length, equalTo(2));
         guard(candidateSteps[0].createFrom(tableRow, "Given foo named xyz").perform());
@@ -281,7 +281,6 @@
     public void shouldNotCreateStepOfWrongType() {
         parent.addComponent(NamedTypeSteps.class);
         NamedTypeSteps steps = parent.getComponent(NamedTypeSteps.class);
-        steps.withParentContainer(parent);
         CandidateStep[] candidateSteps = steps.getSteps();
         ensureThat(candidateSteps.length, equalTo(2));
         candidateSteps[0].createFrom(tableRow, "Given foo named xyz").perform();
@@ -294,6 +293,10 @@
         String givenName;
         String whenName;
 
+        public NamedTypeSteps(PicoEnabledStepsConfiguration configuration) {
+            super(configuration);
+        }
+
         @Given("foo named $name")
         public void givenFoo(String name) {
         	givenName = name;
@@ -310,6 +313,10 @@
     	String ith;
         String nth;
 
+        public AnnotationNamedParameterSteps(PicoEnabledStepsConfiguration configuration) {
+            super(configuration);
+        }
+
         public void methodWithNamedParametersInNaturalOrder(@Named("ith") String ithName, @Named("nth") String nthName){
     		this.ith = ithName;
     		this.nth = nthName;
@@ -326,6 +333,10 @@
     	String ith;
         String nth;
 
+        public ParanamerNamedParameterSteps(PicoEnabledStepsConfiguration configuration) {
+            super(configuration);
+        }
+
         public void methodWithNamedParametersInNaturalOrder(String ith, String nth){
     		this.ith = ith;
     		this.nth = nth;

Modified: trunk/core/jbehave-pico/src/main/java/org/jbehave/scenario/steps/pico/PicoEnabledSteps.java (1490 => 1491)

--- trunk/core/jbehave-pico/src/main/java/org/jbehave/scenario/steps/pico/PicoEnabledSteps.java	2010-01-04 09:36:55 UTC (rev 1490)
+++ trunk/core/jbehave-pico/src/main/java/org/jbehave/scenario/steps/pico/PicoEnabledSteps.java	2010-01-04 21:27:53 UTC (rev 1491)
@@ -8,37 +8,18 @@
 
 public class PicoEnabledSteps extends Steps {
 
-    private PicoContainer parent;
-
-    public PicoEnabledSteps() {
-        super();
-    }
-
-    public PicoEnabledSteps(KeyWords keywords) {
-        super(keywords);
-    }
-
-    public PicoEnabledSteps(ParameterConverters converters) {
-        super(converters);
-    }
-
-    public PicoEnabledSteps(StepsConfiguration configuration) {
+    public PicoEnabledSteps(PicoEnabledStepsConfiguration configuration) {
         super(configuration);
     }
 
-    public PicoEnabledSteps withParentContainer(PicoContainer parent) {
-        this.parent = parent;
-        return this;
-    }
-
     protected CandidateStep createCandidateStep(Method method, StepType stepType, String stepPatternAsString, StepsConfiguration configuration) {
-        if (parent == null) {
-            throw new NullPointerException("Parent container should be provided via PicoEnabledSteps#withParentContainer(PicoContainer)");
+        if (!(configuration instanceof PicoEnabledStepsConfiguration)) {
+            throw new PicoEnabledException("StepsConfiguration parameter should be instanceof PicoEnabledStepsConfiguration");
         }
         return new PicoEnabledCandidateStep(stepPatternAsString, stepType, method,
                 this, configuration.getPatternBuilder(),
                 configuration.getParameterConverters(),
-                configuration.getStartingWordsByType(), parent);
+                configuration.getStartingWordsByType(), ((PicoEnabledStepsConfiguration) configuration).getParentContainer());
     }
 
 


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to