Skip to content

TimeSpecimen Cannot be Created for Valid Implementations #111

@Nylle

Description

@Nylle

The following test will throw an exception:

public static class TemporalAdjusterImpl implements TemporalAdjuster {
    private final String value;

    public TemporalAdjusterImpl(String value) {
        this.value = value;
    }

    @Override
    public Temporal adjustInto(Temporal temporal) { return null; }

    public String getValue() { return value; }
}

@Test
void shouldNotThrow() {
    var actual = fixture().create(TemporalAdjusterImpl.class);

    assertThat(actual).isInstanceOf(TemporalAdjusterImpl.class);
    assertThat(actual.getValue()).isNotEmpty();
}

Exception:

com.github.nylle.javafixture.SpecimenException: Unsupported type: class com.github.nylle.javafixture.FixtureTest$TemporalAdjusterImpl

Reason is a mistmatch between detecting the specimen in SpecimenType.isTimeType() and creating an instance in TimeSpecimen.create().

For this particular test, SpecimenType.isTimeType() returns true for any type that implements TemporalAdjuster, but when creating the instance, TimeSpecimen only checks for the specific implementation MonthDay and throws otherwise.

So we either have to relax the TimeSpecimen to return MonthDay for any TemporalAdjuster-implementation, or we make SpecimenType.isTimeType() stricter in detecting temporal types. I'd prefer the latter.

I also assume, the same problem happens for the TemporalAmount-interface while the Temporal-interface seems properly covered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions