Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.assertj.core.api.Assertions.assertThat;
- @RunWith(SpringRunner.class)
- @DataJpaTest
- public class StudentRepositoryTest {
- @Autowired
- private TestEntityManager testEntityManager;
- @Autowired
- private StudentRepository studentRepository;
- private static final String STUDENT_ID = "sw25/2013";
- private static final String STUDENT_FIRST_NAME = "Mina";
- private static final String STUDENT_LAST_NAME = "Medic";
- @Test
- public void shouldReturnEmptyOptionalWhenFindingNonExistingStudentByID() {
- Optional<Student> student = studentRepository.findByIdentificationNumber(STUDENT_ID);
- assertFalse("Student is not present.", student.isPresent());
- }
- @Test
- public void shouldReturnStudentWhenFindingExistingStudentByID() {
- Student student = new Student(null, STUDENT_FIRST_NAME, STUDENT_LAST_NAME, STUDENT_ID);
- testEntityManager.persist(student);
- testEntityManager.flush();
- Optional<Student> foundStudent = studentRepository.findByIdentificationNumber(STUDENT_ID);
- assertThat(foundStudent.get()).isEqualToComparingFieldByField(student);
- }
- }
Add Comment
Please, Sign In to add comment