Created
December 2, 2020 13:43
-
-
Save dariahervieux/d2b8b4947686e19563b575c0117d8dd5 to your computer and use it in GitHub Desktop.
Testing temporal values with AssertJ (within)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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