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

Date assertions isInSameXXX don't perform a chronogical comparison (as stated in javadoc) but a field by field comparison #145

Open
joel-costigliola opened this issue Feb 5, 2013 · 0 comments

Comments

@joel-costigliola
Copy link
Contributor

Let's see that on an example :

Date date = parseDatetime("2003-04-26T13:01:02"); // 0 ms
Date dateMinusOneMs = new Date(date.getTime() - 1);
// The assertion below fails as seconds fields are different 
// even though dates difference is only 1ms
// If we expect a chronological comparison then it should succeed
// If we expect a field by field comparison then it fails as expected
assertThat(date).isInSameSecondAs(dateMinusOneMs); 

I suggest to

  • rename isInSameSecondAs to isEqualToIgnoringMs
  • add new assertions for chronological comparison with isInSameSecondWindowAs
Date date = parseDatetime("2003-04-26T13:01:02"); // 0 ms
Date dateMinusOneMs = new Date(date.getTime() - 1);
// should fail
assertThat(date).isEqualToIgnoringMilliseconds(dateMinusOneMs); 
// should succeed
assertThat(date).isInSameSecondWindowAs(dateMinusOneMs); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant