Title: [1397] trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps: JBEHAVE-212: Applied patch by Cristiano Gavi?\195?\163o.
Revision
1397
Author
mauro
Date
2009-12-03 15:47:24 -0600 (Thu, 03 Dec 2009)

Log Message

JBEHAVE-212:  Applied patch by Cristiano Gavi?\195?\163o.  Added test to verify behaviour.

Modified Paths

Diff

Modified: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java (1396 => 1397)

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java	2009-12-03 12:09:48 UTC (rev 1396)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java	2009-12-03 21:47:24 UTC (rev 1397)
@@ -1,15 +1,19 @@
 package org.jbehave.scenario.i18n;
-
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.jbehave.Ensure.ensureThat;
 import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Properties;
 
 import org.jbehave.scenario.definition.KeyWords;
 import org.jbehave.scenario.i18n.I18nKeyWords.KeywordNotFoundExcepion;
 import org.jbehave.scenario.i18n.I18nKeyWords.ResourceBundleNotFoundExcepion;
+import org.jbehave.scenario.steps.StepType;
+import org.jbehave.scenario.steps.StepsConfiguration;
 import org.junit.Test;
 
 public class I18nKeywordsBehaviour {
@@ -36,6 +40,23 @@
 		ensureKeywordsAreLocalisedFor(new Locale("es"), null);
 	}
 
+	@Test
+    public void shouldAllowKeywordsToBeOverriddenInStepsConfiguration() {
+        StepsConfiguration configuration = new StepsConfiguration();
+        ensureKeywordsAreLocalised(configuration, new Locale("en"));
+        configuration.useKeyWords(new I18nKeyWords(new Locale("it")));
+        ensureKeywordsAreLocalised(configuration, new Locale("it"));
+    }
+
+    private void ensureKeywordsAreLocalised(StepsConfiguration configuration, Locale locale) {
+        Map<StepType, String> startingWordsByType = configuration.getStartingWordsByType();
+        KeyWords keywords = keyWordsFor(locale, null);
+        ensureThat(startingWordsByType.get(StepType.GIVEN), equalTo(keywords.given()));
+        ensureThat(startingWordsByType.get(StepType.WHEN), equalTo(keywords.when()));
+        ensureThat(startingWordsByType.get(StepType.THEN), equalTo(keywords.then()));
+        ensureThat(startingWordsByType.get(StepType.AND), equalTo(keywords.and()));
+    }
+    
 	private void ensureKeywordsAreLocalisedFor(Locale locale, String bundleName)
 			throws IOException {
 		KeyWords keywords = keyWordsFor(locale, bundleName);

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java (1396 => 1397)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java	2009-12-03 12:09:48 UTC (rev 1396)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/steps/StepsConfiguration.java	2009-12-03 21:47:24 UTC (rev 1397)
@@ -62,9 +62,13 @@
 		this.paranamer = paranamer;
 		this.parameterConverters = parameterConverters;
 		this.keywords = keywords;
-		this.startingWords = startingWordsFrom(this.keywords);
+		startingWordsFromKeywords();
+	}
+
+    private void startingWordsFromKeywords() {
+        this.startingWords = startingWordsFrom(this.keywords);
 		this.startingWordsByType = startingWordsByType(this.keywords);
-	}
+    }
 	
 	/**
 	 * @deprecated Use StepsConfiguration(KeyWords)
@@ -170,7 +174,7 @@
 
 	public void useKeyWords(KeyWords keywords) {
 		this.keywords = keywords;
-		this.startingWords = startingWordsFrom(this.keywords);
+		startingWordsFromKeywords();
 	}
 
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to