- Revision
- 1542
- Author
- mauro
- Date
- 2010-02-05 11:35:19 -0600 (Fri, 05 Feb 2010)
Log Message
JBEHAVE-238: Added checks on the values provided.
Modified Paths
Diff
Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java (1541 => 1542)
--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java 2010-02-05 17:23:52 UTC (rev 1541) +++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java 2010-02-05 17:35:19 UTC (rev 1542) @@ -10,8 +10,8 @@ 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.i18n.I18nKeyWords.I18nKeywordNotFoundException; +import org.jbehave.scenario.i18n.I18nKeyWords.ResourceBundleNotFoundException; import org.jbehave.scenario.steps.StepType; import org.jbehave.scenario.steps.StepsConfiguration; import org.junit.Test; @@ -30,12 +30,12 @@ ensureKeywordsAreLocalisedFor(new Locale("it"), null); } - @Test(expected = ResourceBundleNotFoundExcepion.class) + @Test(expected = ResourceBundleNotFoundException.class) public void shouldFailIfResourceBundleIsNotFound() throws IOException { ensureKeywordsAreLocalisedFor(new Locale("en"), "unknown"); } - @Test(expected = KeywordNotFoundExcepion.class) + @Test(expected = I18nKeywordNotFoundException.class) public void shouldFailIfKeywordIsNotFound() throws IOException { ensureKeywordsAreLocalisedFor(new Locale("es"), null); }
Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java (1541 => 1542)
--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java 2010-02-05 17:23:52 UTC (rev 1541) +++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java 2010-02-05 17:35:19 UTC (rev 1542) @@ -71,22 +71,30 @@ } public KeyWords(Map<String, String> keywords, StringEncoder encoder) { - this.scenario = keywords.get(SCENARIO); - this.givenScenarios = keywords.get(GIVEN_SCENARIOS); - this.examplesTable = keywords.get(EXAMPLES_TABLE); - this.given = keywords.get(GIVEN); - this.when = keywords.get(WHEN); - this.then = keywords.get(THEN); - this.and = keywords.get(AND); - this.ignorable = keywords.get(IGNORABLE); - this.pending = keywords.get(PENDING); - this.notPerformed = keywords.get(NOT_PERFORMED); - this.failed = keywords.get(FAILED); - this.examplesTableRow = keywords.get(EXAMPLES_TABLE_ROW); + this.scenario = keyword(SCENARIO, keywords); + this.givenScenarios = keyword(GIVEN_SCENARIOS, keywords); + this.examplesTable = keyword(EXAMPLES_TABLE, keywords); + this.given = keyword(GIVEN, keywords); + this.when = keyword(WHEN, keywords); + this.then = keyword(THEN, keywords); + this.and = keyword(AND, keywords); + this.ignorable = keyword(IGNORABLE, keywords); + this.pending = keyword(PENDING, keywords); + this.notPerformed = keyword(NOT_PERFORMED, keywords); + this.failed = keyword(FAILED, keywords); + this.examplesTableRow = keyword(EXAMPLES_TABLE_ROW, keywords); this.others = new String[]{and, ignorable}; this.encoder = encoder; } + private String keyword(String name, Map<String, String> keywords) { + String keyword = keywords.get(name); + if ( keyword == null ){ + throw new KeywordNotFoundException(name, keywords); + } + return keyword; + } + /** * @deprecated Use KeyWords(Map<String,String>, StringEncoder) */ @@ -170,4 +178,12 @@ return value; } + @SuppressWarnings("serial") + public static final class KeywordNotFoundException extends RuntimeException { + + public KeywordNotFoundException(String name, Map<String, String> keywords) { + super("Keyword "+name+" not found amongst "+keywords); + } + + } }
Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/I18nKeyWords.java (1541 => 1542)
--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/I18nKeyWords.java 2010-02-05 17:23:52 UTC (rev 1541) +++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/I18nKeyWords.java 2010-02-05 17:35:19 UTC (rev 1542) @@ -56,7 +56,7 @@ try { return encoder.encode(bundle.getString(name)); } catch (MissingResourceException e) { - throw new KeywordNotFoundExcepion(name, bundle); + throw new I18nKeywordNotFoundException(name, bundle); } } @@ -67,14 +67,14 @@ } return getBundle(bundleName, locale); } catch (MissingResourceException e) { - throw new ResourceBundleNotFoundExcepion(bundleName, locale, classLoader, e); + throw new ResourceBundleNotFoundException(bundleName, locale, classLoader, e); } } @SuppressWarnings("serial") - public static final class ResourceBundleNotFoundExcepion extends RuntimeException { + public static final class ResourceBundleNotFoundException extends RuntimeException { - public ResourceBundleNotFoundExcepion(String bundleName, Locale locale, ClassLoader classLoader, + public ResourceBundleNotFoundException(String bundleName, Locale locale, ClassLoader classLoader, MissingResourceException cause) { super("Resource bundle " + bundleName + " not found for locale " + locale + " in classLoader " + classLoader, cause); @@ -83,10 +83,10 @@ } @SuppressWarnings("serial") - public static final class KeywordNotFoundExcepion extends RuntimeException { + public static final class I18nKeywordNotFoundException extends RuntimeException { - public KeywordNotFoundExcepion(String name, ResourceBundle bundle) { - super("Keyword " + name + " not found in resource bundle " + bundle); + public I18nKeywordNotFoundException(String name, ResourceBundle bundle) { + super("I18nKeyword " + name + " not found in resource bundle " + bundle); } }
To unsubscribe from this list please visit:
