Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in datatable conversion using ClassWithStringAssignableConstructorConverter #735

Closed
ks-appendium opened this issue Jun 17, 2014 · 1 comment · Fixed by #736
Closed

Comments

@ks-appendium
Copy link

Hi, we have found an issue with the datatable conversion. It fails when there are different type of classes using ClassWithStringAssignableConstructorConverter

Feature: Convert datatable properly

  Scenario: I should be able to load a org.joda.time.LocalDate|org.joda.time.LocalTime|org.joda.time.LocalDate in that order
    When I load a table like
      | date1      | time1        | date2      |
      | 2014-06-17 | 17:30:00.000 | 2014-06-18 |

---

import org.joda.time.LocalDate;
import org.joda.time.LocalTime;

public class CucumberBug {
    private LocalDate date1;
    private LocalTime time1;
    private LocalDate date2;

    public LocalDate getDate1() {
        return date1;
    }

    public void setDate1(final LocalDate date1) {
        this.date1 = date1;
    }

    public LocalTime getTime1() {
        return time1;
    }

    public void setTime1(final LocalTime time1) {
        this.time1 = time1;
    }

    public LocalDate getDate2() {
        return date2;
    }

    public void setDate2(final LocalDate date2) {
        this.date2 = date2;
    }
}

---
public class CucumberBugSteps {
    @When("^I load a table like$")
    public void i_load_a_table_like(final DataTable table) throws Throwable {
        final List<CucumberBug> list = table.asList(CucumberBug.class);

        assertEquals(list.get(0).getDate1(), new LocalDate("2014-06-17"));
        assertEquals(list.get(0).getTime1(), new LocalTime("17:30:00"));
        assertEquals(list.get(0).getDate2(), new LocalDate("2014-06-18"));
    }
}

We think the problem is around the method com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType

First time, the method get called, it will add and return
LocalDate.class -> ClassWithStringAssignableConstructorConverter(ctor as Localdate assigned during canConvert) (line 56-57)

Second time, the method get called, it will add and return
LocalTime.class -> ClassWithStringAssignableConstructorConverter(ctor as LocalTime assigned during canConvert) (line 56-57)

Third time, the method get called, it will return a ClassWithStringAssignableConstructorConverter(ctor as LocalTime) for a LocalDate because it is now cached. (Line 51)

We are using cucumber-java 1.1.7

Re-ordering the table may work in the example above, but when there are various tables used it will not work.

Thanks,
Kenny

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant