Permalink
Browse files

Remove redundant Locale argument in a bunch of places. Some reformatt…

…ing.
  • Loading branch information...
1 parent bdbd0b4 commit 926379ff40cf225f1e731786dc90bfa0ff080fbd @aslakhellesoy aslakhellesoy committed Mar 12, 2013
@@ -3,7 +3,6 @@
import gherkin.I18n;
import gherkin.formatter.model.Step;
-import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;
@@ -1,7 +1,7 @@
package cucumber.runtime;
-import cucumber.api.Format;
import cucumber.api.Delimiter;
+import cucumber.api.Format;
import cucumber.api.Transform;
import cucumber.api.Transformer;
import cucumber.deps.com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -14,7 +14,6 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
-import java.util.Locale;
/**
* This class composes all interesting parameter information into one object.
@@ -85,20 +84,20 @@ public String toString() {
return type.toString();
}
- public Object convert(String value, LocalizedXStreams.LocalizedXStream xStream, Locale locale) {
+ public Object convert(String value, LocalizedXStreams.LocalizedXStream xStream) {
try {
xStream.setParameterType(this);
SingleValueConverter converter;
xStream.processAnnotations(getRawType());
if (transformer != null) {
- transformer.setParameterInfoAndLocale(this, locale);
+ transformer.setParameterInfoAndLocale(this, xStream.getLocale());
converter = transformer;
} else {
if (List.class.isAssignableFrom(getRawType())) {
- converter = getListConverter(type, xStream, locale);
+ converter = getListConverter(type, xStream);
} else {
- converter = getConverter(getRawType(), xStream, locale);
+ converter = getConverter(getRawType(), xStream);
}
if (converter == null) {
throw new CucumberException(String.format(
@@ -121,22 +120,22 @@ public Object convert(String value, LocalizedXStreams.LocalizedXStream xStream,
}
}
- private SingleValueConverter getListConverter(Type type, LocalizedXStreams.LocalizedXStream xStream, Locale locale) {
+ private SingleValueConverter getListConverter(Type type, LocalizedXStreams.LocalizedXStream xStream) {
Class elementType = type instanceof ParameterizedType
? getRawType(((ParameterizedType) type).getActualTypeArguments()[0])
: Object.class;
- SingleValueConverter elementConverter = getConverter(elementType, xStream, locale);
+ SingleValueConverter elementConverter = getConverter(elementType, xStream);
if (elementConverter == null) {
return null;
} else {
return xStream.createListConverter(delimiter, elementConverter);
}
}
- private SingleValueConverter getConverter(Class<?> type, LocalizedXStreams.LocalizedXStream xStream, Locale locale) {
+ private SingleValueConverter getConverter(Class<?> type, LocalizedXStreams.LocalizedXStream xStream) {
if (type.isEnum()) {
- return xStream.createEnumConverter(locale, (Class<? extends Enum>) type);
+ return xStream.createEnumConverter((Class<? extends Enum>) type);
} else {
return xStream.getSingleValueConverter(type);
}
@@ -11,7 +11,6 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -64,15 +64,10 @@ public void runStep(I18n i18n) throws Throwable {
List<Object> result = new ArrayList<Object>();
- List<ParameterInfo> parameterInfos = new ArrayList<ParameterInfo>();
int n = 0;
for (Argument a : getArguments()) {
- Object arg;
-
ParameterInfo parameterInfo = getParameterType(n, String.class);
- parameterInfos.add(parameterInfo);
-
- arg = parameterInfo.convert(a.getVal(), xStream, locale);
+ Object arg = parameterInfo.convert(a.getVal(), xStream);
result.add(arg);
n++;
}
@@ -238,7 +238,7 @@ public void updateElement(Document doc, Element tc) {
child = doc.createElement("system-out");
child.appendChild(doc.createCDATASection(sb.toString()));
}
-
+
Node existingChild = tc.getFirstChild();
if (existingChild == null) {
tc.appendChild(child);
@@ -6,7 +6,6 @@
import gherkin.formatter.model.BasicStatement;
import gherkin.formatter.model.Step;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -31,7 +30,7 @@ public void step(Step step) {
void format(Formatter formatter) {
statement.replay(formatter);
}
-
+
void formatSteps(Formatter formatter) {
for (Step step : getSteps()) {
formatter.step(step);
@@ -105,8 +105,12 @@ public SingleValueConverter createListConverter(String delimiter, SingleValueCon
return new ListConverter(delimiter, elementConverter);
}
- public SingleValueConverter createEnumConverter(Locale locale, Class<? extends Enum> type) {
+ public SingleValueConverter createEnumConverter(Class<? extends Enum> type) {
return new EnumConverter(locale, type);
}
+
+ public Locale getLocale() {
+ return locale;
+ }
}
}
@@ -51,7 +51,7 @@ public String toString(Object obj) {
@Override
public void setParameterInfoAndLocale(ParameterInfo parameterInfo, Locale locale) {
super.setParameterInfoAndLocale(parameterInfo, locale);
- if(parameterInfo.getFormat() != null) {
+ if (parameterInfo.getFormat() != null) {
onlyFormat = new SimpleDateFormat(parameterInfo.getFormat(), locale);
onlyFormat.setLenient(false);
}
@@ -18,16 +18,16 @@
public class ParameterInfoTest {
- private static final Locale LOCALE = Locale.US;
- private static final LocalizedXStreams.LocalizedXStream X = new LocalizedXStreams(Thread.currentThread().getContextClassLoader()).get(LOCALE);
+ private static final LocalizedXStreams.LocalizedXStream US = new LocalizedXStreams(Thread.currentThread().getContextClassLoader()).get(Locale.US);
+ private static final LocalizedXStreams.LocalizedXStream FR = new LocalizedXStreams(Thread.currentThread().getContextClassLoader()).get(Locale.FRANCE);
public void withInt(int i) {
}
@Test
public void converts_with_built_in_converter() throws NoSuchMethodException {
ParameterInfo pt = ParameterInfo.fromMethod(getClass().getMethod("withInt", Integer.TYPE)).get(0);
- assertEquals(23, pt.convert("23", X, LOCALE));
+ assertEquals(23, pt.convert("23", US));
}
public void withJodaTime(@Transform(JodaTransformer.class) LocalDate date) {
@@ -45,9 +45,9 @@ public LocalDate transform(String value) {
@Test
public void converts_with_custom_joda_time_transform_and_format() throws NoSuchMethodException {
ParameterInfo parameterInfo = ParameterInfo.fromMethod(getClass().getMethod("withJodaTime", LocalDate.class)).get(0);
- LocalDate aslaksBirthday = new LocalDate(1971,2,28);
- assertEquals(aslaksBirthday, parameterInfo.convert("28/02/1971", X, Locale.FRANCE));
- assertEquals(aslaksBirthday, parameterInfo.convert("02/28/1971", X, Locale.US));
+ LocalDate aslaksBirthday = new LocalDate(1971, 2, 28);
+ assertEquals(aslaksBirthday, parameterInfo.convert("28/02/1971", FR));
+ assertEquals(aslaksBirthday, parameterInfo.convert("02/28/1971", US));
}
public void withJodaTimeAndFormat(@Transform(JodaTransformer.class) @Format("S-") LocalDate date) {
@@ -56,9 +56,9 @@ public void withJodaTimeAndFormat(@Transform(JodaTransformer.class) @Format("S-"
@Test
public void converts_with_custom_joda_time_transform() throws NoSuchMethodException {
ParameterInfo parameterInfo = ParameterInfo.fromMethod(getClass().getMethod("withJodaTimeAndFormat", LocalDate.class)).get(0);
- LocalDate aslaksBirthday = new LocalDate(1971,2,28);
- assertEquals(aslaksBirthday, parameterInfo.convert("28/02/1971", X, Locale.FRANCE));
- assertEquals(aslaksBirthday, parameterInfo.convert("02/28/1971", X, Locale.US));
+ LocalDate aslaksBirthday = new LocalDate(1971, 2, 28);
+ assertEquals(aslaksBirthday, parameterInfo.convert("28/02/1971", FR));
+ assertEquals(aslaksBirthday, parameterInfo.convert("02/28/1971", US));
}
public void withJodaTimeWithoutTransform(LocalDate date) {
@@ -68,7 +68,7 @@ public void withJodaTimeWithoutTransform(LocalDate date) {
public void converts_to_joda_time_using_object_ctor_and_default_locale() throws NoSuchMethodException {
ParameterInfo parameterInfo = ParameterInfo.fromMethod(getClass().getMethod("withJodaTimeWithoutTransform", LocalDate.class)).get(0);
LocalDate localDate = new LocalDate("1971");
- assertEquals(localDate, parameterInfo.convert("1971", X, Locale.FRANCE));
+ assertEquals(localDate, parameterInfo.convert("1971", US));
}
public static class FortyTwoTransformer extends Transformer<Integer> {
@@ -84,7 +84,7 @@ public void intWithCustomTransform(@Transform(FortyTwoTransformer.class) int n)
@Test
public void converts_int_with_custom_transform() throws NoSuchMethodException {
ParameterInfo pt = ParameterInfo.fromMethod(getClass().getMethod("intWithCustomTransform", Integer.TYPE)).get(0);
- assertEquals(42, pt.convert("hello", X, LOCALE));
+ assertEquals(42, pt.convert("hello", US));
}
public void listWithNoDelimiter(List<String> list) {
@@ -93,8 +93,8 @@ public void listWithNoDelimiter(List<String> list) {
@Test
public void converts_list_with_default_delimiter() throws NoSuchMethodException {
ParameterInfo pt = ParameterInfo.fromMethod(getClass().getMethod("listWithNoDelimiter", List.class)).get(0);
- assertEquals(Arrays.asList("hello", "world"), pt.convert("hello, world", X, LOCALE));
- assertEquals(Arrays.asList("hello", "world"), pt.convert("hello,world", X, LOCALE));
+ assertEquals(Arrays.asList("hello", "world"), pt.convert("hello, world", US));
+ assertEquals(Arrays.asList("hello", "world"), pt.convert("hello,world", US));
}
public void listWithCustomDelimiter(@Delimiter("\\|") List<String> list) {
@@ -103,7 +103,7 @@ public void listWithCustomDelimiter(@Delimiter("\\|") List<String> list) {
@Test
public void converts_list_with_custom_delimiter() throws NoSuchMethodException {
ParameterInfo pt = ParameterInfo.fromMethod(getClass().getMethod("listWithCustomDelimiter", List.class)).get(0);
- assertEquals(Arrays.asList("hello", "world"), pt.convert("hello|world", X, LOCALE));
+ assertEquals(Arrays.asList("hello", "world"), pt.convert("hello|world", US));
}
public void listWithNoTypeArgument(List list) {
@@ -112,6 +112,6 @@ public void listWithNoTypeArgument(List list) {
@Test
public void converts_list_with_no_type_argument() throws NoSuchMethodException {
ParameterInfo pt = ParameterInfo.fromMethod(getClass().getMethod("listWithNoTypeArgument", List.class)).get(0);
- assertEquals(Arrays.asList("hello", "world"), pt.convert("hello, world", X, LOCALE));
+ assertEquals(Arrays.asList("hello", "world"), pt.convert("hello, world", US));
}
}
@@ -2,14 +2,13 @@
import org.junit.Test;
-import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.regex.Pattern;
import static java.util.Arrays.asList;
-import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -9,7 +9,7 @@
import java.util.List;
import static java.util.Arrays.asList;
-import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -1,11 +1,11 @@
package cucumber.runtime.formatter;
-import static java.util.Arrays.asList;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import cucumber.runtime.Backend;
+import cucumber.runtime.Runtime;
+import cucumber.runtime.RuntimeOptions;
+import cucumber.runtime.io.ClasspathResourceLoader;
import gherkin.formatter.model.Step;
+import org.junit.Test;
import java.io.File;
import java.io.IOException;
@@ -14,12 +14,11 @@
import java.util.Properties;
import java.util.Scanner;
-import org.junit.Test;
-
-import cucumber.runtime.Backend;
-import cucumber.runtime.Runtime;
-import cucumber.runtime.RuntimeOptions;
-import cucumber.runtime.io.ClasspathResourceLoader;
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class JSONPrettyFormatterTest {
@@ -20,7 +20,7 @@
import java.util.Properties;
import static java.util.Arrays.asList;
-import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -9,7 +9,6 @@
import java.lang.reflect.Type;
import java.util.Date;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@@ -5,8 +5,6 @@
import gherkin.TagExpression;
import gherkin.formatter.model.Tag;
import org.jruby.RubyObject;
-import org.jruby.javasupport.JavaEmbedUtils;
-import org.jruby.runtime.builtin.IRubyObject;
import java.util.Collection;
import java.util.List;
@@ -34,7 +34,7 @@ public static void run(Class<?> testClass, boolean debug) {
if (output.contains(INSANITY)) {
throw new RuntimeException("Something went wrong\n" + output);
}
- if(debug) {
+ if (debug) {
System.out.println("===== " + testClass.getName());
System.out.println(output);
System.out.println("=====");
@@ -18,15 +18,15 @@
@Test
public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario() throws Exception {
List<CucumberFeature> features = CucumberFeature.load(
- new ClasspathResourceLoader(this.getClass().getClassLoader()),
- asList("cucumber/runtime/junit/fb.feature"),
- Collections.emptyList()
+ new ClasspathResourceLoader(this.getClass().getClassLoader()),
+ asList("cucumber/runtime/junit/fb.feature"),
+ Collections.emptyList()
);
ExecutionUnitRunner runner = new ExecutionUnitRunner(
- null,
- (CucumberScenario) features.get(0).getFeatureElements().get(0),
- null
+ null,
+ (CucumberScenario) features.get(0).getFeatureElements().get(0),
+ null
);
// fish out the two occurrences of the same step and check whether we really got them
@@ -44,19 +44,17 @@ public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInASc
}
@Test
- public void shouldIncludeScenarioNameAsClassNameInStepDescriptions()
- throws Exception {
-
+ public void shouldIncludeScenarioNameAsClassNameInStepDescriptions() throws Exception {
List<CucumberFeature> features = CucumberFeature.load(
- new ClasspathResourceLoader(this.getClass().getClassLoader()),
- asList("cucumber/runtime/junit/feature_with_same_steps_in_different_scenarios.feature"),
- Collections.emptyList()
+ new ClasspathResourceLoader(this.getClass().getClassLoader()),
+ asList("cucumber/runtime/junit/feature_with_same_steps_in_different_scenarios.feature"),
+ Collections.emptyList()
);
ExecutionUnitRunner runner = new ExecutionUnitRunner(
- null,
- (CucumberScenario) features.get(0).getFeatureElements().get(0),
- null
+ null,
+ (CucumberScenario) features.get(0).getFeatureElements().get(0),
+ null
);
// fish out the data from runner
@@ -5,7 +5,7 @@
import javax.inject.Inject;
-import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
public class BellyStepdefs {
Oops, something went wrong.

0 comments on commit 926379f

Please sign in to comment.