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

TimeSpecimen Cannot be Created for Valid Implementations #111

Open
Nylle opened this issue Sep 9, 2024 · 1 comment
Open

TimeSpecimen Cannot be Created for Valid Implementations #111

Nylle opened this issue Sep 9, 2024 · 1 comment
Labels

Comments

@Nylle
Copy link
Owner

Nylle commented Sep 9, 2024

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.

@Nylle Nylle added the bug label Sep 9, 2024
@Nylle
Copy link
Owner Author

Nylle commented Sep 10, 2024

Here are a few more tests:

@Test
void shouldNotThrowEither() {
    var actual = fixture().create(TemporalAdjuster.class);

    assertThat(actual).isInstanceOf(MonthDay.class);
}

@Test
void thisWorksAndShouldKeepWorking() {
    var actual = fixture().create(MonthDay.class);

    assertThat(actual).isInstanceOf(MonthDay.class);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant