Skip to content

Support for Assertions.byLessThan(Duration) and Assertions.within(Duration) #3486

Description

@khmarbaise

Feature summary

Enhance the byLessThan(..) and within to support the usage of Duration.

At the moment byLessThan(..) and within support the usage of a value combined with a TemporalUnit which looks like this:

assertThat(_07_10_20).isCloseTo(_07_11_45, byLessThan(1, ChronoUnit.MINUTES));
assertThat(_07_10_00).isCloseTo(_07_12_00, within(1, ChronoUnit.MINUTES));

Example

My suggestion is to enhance it in that way that you are able to use Duration instead of two different parameters like this:

assertThat(_07_10_20).isCloseTo(_07_11_45, byLessThan(Duration.ofMinutes(1)));
assertThat(_07_10_20).isCloseTo(_07_11_45, byLessThan(Duration.ofSeconds(45)));

or as example for within:

assertThat(_07_10_00).isCloseTo(_07_12_00, within(Duration.ofMinutes(1)));

Activity

  1. scordio commented on May 22, 2024

    @scordio
    Member

    Indeed, it would be a nice addition!

  2. etrandafir93 commented on Jun 20, 2024

    @etrandafir93
    Contributor

    @scordio - I guess we just need some simple static factory methods.

    I have added my changes and created this small PR.

  3. added this to the 3.27.0 milestone on Sep 25, 2024
  4. added a commit that references this issue on Nov 11, 2024
    a587528
  5. changed the title [-]Support for Duration in Assertions.byLessThan, Assertions.within[/-] [+]Support for `Assertions.byLessThan(Duration)` and `Assertions.within(Duration)`[/+] on Dec 14, 2024
  6. added a commit that references this issue on Mar 4, 2025
    f09cc3b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions