Skip to content

Instantly share code, notes, and snippets.

@dariahervieux
Created December 2, 2020 13:43
Show Gist options
  • Save dariahervieux/d2b8b4947686e19563b575c0117d8dd5 to your computer and use it in GitHub Desktop.
Save dariahervieux/d2b8b4947686e19563b575c0117d8dd5 to your computer and use it in GitHub Desktop.
Testing temporal values with AssertJ (within)
import static org.assertj.core.api.Assertions.within;
//...
public class UserTest {
private UserService userService = new UserService();
@Test
public void given_valid_inputs_creation_is_ok() throws Exception {
User userToCreate = new User("name");
User user = userService.create(userToCreate);
//...
// the date of user creation is close to 'now'
assertThat(user.getCreationDate()).isCloseTo(LocalDateTime.now(), within(1, ChronoUnit.SECONDS));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment