Skip to content

Commit

Permalink
Implemented and . See #433
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Dec 6, 2012
1 parent 8beba84 commit aa6dda9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
16 changes: 16 additions & 0 deletions core/src/main/java/cucumber/api/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,20 @@ public List<String> flatten() {
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();
}
}
9 changes: 0 additions & 9 deletions core/src/main/java/cucumber/api/Transformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
*/
public abstract class Transformer<T> implements SingleValueConverter {
private final Type type;
private ParameterInfo parameterInfo;
private Locale locale;

public Transformer() {
Expand All @@ -100,17 +99,9 @@ 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 0 additions & 10 deletions core/src/test/java/cucumber/runtime/ParameterInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 21 additions & 2 deletions core/src/test/java/cucumber/runtime/table/DataTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit aa6dda9

Please sign in to comment.