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

Temporal type not available on assertThat #3404

Closed
xenoterracide opened this issue Mar 19, 2024 · 2 comments
Closed

Temporal type not available on assertThat #3404

xenoterracide opened this issue Mar 19, 2024 · 2 comments
Assignees
Labels
type: new feature A new feature
Milestone

Comments

@xenoterracide
Copy link

Describe the bug
A clear and concise description of what the bug is.

  • assertj core version: org.assertj:assertj-core:3.25.3
  • java version: 21.0.2
  • test framework version: org.junit:junit-bom:5.10.2
  • os (if relevant):

Test case reproducing the bug

Add a test case showing the bug that we can run

  @ParameterizedTest
  @ArgumentsSource(TimeClassProvider.class)
  void timeAvailableInTransaction(Class<? extends Temporal> timeClass) {
    Temporal now = context.getBean(timeClass);
    assertThat(now).isCloseTo(Instant.now(), within(1, ChronoUnit.SECONDS))
  }
  
  static class TimeClassProvider implements ArgumentsProvider {

    @Override
    public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
      return Stream.of(
        Arguments.of(Instant.class),
        Arguments.of(ZonedDateTime.class),
        Arguments.of(OffsetDateTime.class)
      );
    }
  }

note: context is a Spring BeanFactory with signature, obviously if you want real runtime you could just pass instances though...

	<T> T getBean(Class<T> requiredType) throws BeansException;
@xenoterracide
Copy link
Author

xenoterracide commented Mar 19, 2024

oh, I wrote this instead

    switch (now) {
      case Instant instant -> {
        assertThat(instant).isCloseTo(Instant.now(), within(1, ChronoUnit.SECONDS));
      }
      case ZonedDateTime zonedDateTime -> {
        assertThat(zonedDateTime).isCloseTo(ZonedDateTime.now(), within(1, ChronoUnit.SECONDS));
      }
      case OffsetDateTime offsetDateTime -> {
        assertThat(offsetDateTime).isCloseTo(OffsetDateTime.now(), within(1, ChronoUnit.SECONDS));
      }
      default -> throw new IllegalStateException("Unexpected value: " + now);
    }

I suspect? that isCloseTo could always take an instant, although that's not true here. I could be wrong, I have played with temporal enough right now to be certain of that.

@joel-costigliola joel-costigliola added this to the 3.26.0 milestone Mar 19, 2024
@joel-costigliola joel-costigliola self-assigned this Mar 19, 2024
@joel-costigliola joel-costigliola added the type: new feature A new feature label Mar 19, 2024
@joel-costigliola
Copy link
Member

joel-costigliola commented Mar 19, 2024

Indeed, we don't have a TemporalAssert class while we already have AbstractTemporalAssert. It's fairly easy to add one (I'm already on it).

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

No branches or pull requests

2 participants