Permalink
Browse files

Implemented and . See #433

  • Loading branch information...
1 parent 8beba84 commit aa6dda966e63e12c076a65fff935c8da62708ffa @aslakhellesoy aslakhellesoy committed Dec 6, 2012
@@ -188,4 +188,20 @@ public TableConverter getTableConverter() {
return result;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof DataTable)) return false;
+
+ DataTable dataTable = (DataTable) o;
+
+ if (!raw.equals(dataTable.raw)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return raw.hashCode();
+ }
}
@@ -74,7 +74,6 @@
*/
public abstract class Transformer<T> implements SingleValueConverter {
private final Type type;
- private ParameterInfo parameterInfo;
private Locale locale;
public Transformer() {
@@ -100,18 +99,10 @@ public boolean canConvert(Class type) {
public abstract T transform(String value);
public void setParameterInfoAndLocale(ParameterInfo parameterInfo, Locale locale) {
- this.parameterInfo = parameterInfo;
this.locale = locale;
}
/**
- * @return info about the current parameter
- */
- protected ParameterInfo getParameterInfo() {
- return parameterInfo;
- }
-
- /**
* @return the current locale
*/
protected Locale getLocale() {
@@ -32,7 +32,7 @@
import static java.util.Arrays.asList;
/**
- * This class converts a {@link cucumber.api.DataTable to various other types}
+ * This class converts a {@link cucumber.api.DataTable} to various other types.
*/
public class TableConverter {
private static final List<Comment> NO_COMMENTS = Collections.emptyList();
@@ -53,16 +53,6 @@ public void converts_with_custom_joda_time_transform_and_format() throws NoSuchM
public void withJodaTimeAndFormat(@Transform(JodaTransformer.class) @Format("S-") LocalDate date) {
}
- public static class JodaFormatTransformer extends Transformer<LocalDate> {
- @Override
- public LocalDate transform(String value) {
- String format = getParameterInfo().getFormat();
- DateTimeFormatter dateTimeFormatter = DateTimeFormat.forStyle(format);
- dateTimeFormatter = dateTimeFormatter.withLocale(getLocale());
- return dateTimeFormatter.parseLocalDate(value);
- }
- }
-
@Test
public void converts_with_custom_joda_time_transform() throws NoSuchMethodException {
ParameterInfo parameterInfo = ParameterInfo.fromMethod(getClass().getMethod("withJodaTimeAndFormat", LocalDate.class)).get(0);
@@ -12,6 +12,8 @@
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
public class DataTableTest {
@@ -59,10 +61,27 @@ public void asMaps_is_immutable() {
createSimpleTable().asMaps().remove(0);
}
+ @Test
+ public void two_identical_tables_are_considered_equal() {
+ assertEquals(createSimpleTable(), createSimpleTable());
+ assertEquals(createSimpleTable().hashCode(), createSimpleTable().hashCode());
+ }
+
+ @Test
+ public void two_different_tables_are_considered_non_equal() {
+ assertFalse(createSimpleTable().equals(createTable(asList("one"))));
+ assertNotSame(createSimpleTable().hashCode(), createTable(asList("one")).hashCode());
+ }
+
public DataTable createSimpleTable() {
+ return createTable(asList("one", "four", "seven"), asList("4444", "55555", "666666"));
+ }
+
+ private DataTable createTable(List<String>... rows) {
List<DataTableRow> simpleRows = new ArrayList<DataTableRow>();
- simpleRows.add(new DataTableRow(new ArrayList<Comment>(), asList("one", "four", "seven"), 1));
- simpleRows.add(new DataTableRow(new ArrayList<Comment>(), asList("4444", "55555", "666666"), 2));
+ for (int i = 0; i < rows.length; i++) {
+ simpleRows.add(new DataTableRow(new ArrayList<Comment>(), rows[i], i + 1));
+ }
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
LocalizedXStreams.LocalizedXStream xStream = new LocalizedXStreams(classLoader).get(Locale.US);
return new DataTable(simpleRows, new TableConverter(xStream, null));

0 comments on commit aa6dda9

Please sign in to comment.