Commit 73df0940 authored by Khalid Ali's avatar Khalid Ali
Browse files

Add findById repository test

parent 178074ea
......@@ -10,6 +10,8 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.Date;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -37,4 +39,33 @@ public class ListingEntityRepositoryIntegrationTest {
assertThat(found.get(0).getIsbn())
.isEqualTo(alex.getIsbn());
}
@Test
public void whenFindById_thenReturnListing() {
//given
ListingEntity book1 = new ListingEntity(123456, 3, 14.99,
new Date(), 192838079872L, 2879878394L, "Title Calc 3");
ListingEntity book2 = new ListingEntity(123456, 3, 14.99,
new Date(), 192838079872L, 2879878394L, "Title Calc 3");
ListingEntity book3 = new ListingEntity(123456, 3, 14.99,
new Date(), 192838079872L, 2879878394L, "Title Calc 3");
testEntityManager.persist(book1);
testEntityManager.persist(book2);
testEntityManager.persist(book3);
// when
Optional<ListingEntity> found2 = listingRepository.findById(book2.getId());
Optional<ListingEntity> found3 = listingRepository.findById(book3.getId());
Optional<ListingEntity> found1 = listingRepository.findById(book1.getId());
// then
assertThat(found2.isPresent()).isTrue();
assertThat(found2.get().getId()).isEqualTo(book2.getId());
assertThat(found3.isPresent()).isTrue();
assertThat(found3.get().getId()).isEqualTo(book3.getId());
assertThat(found1.isPresent()).isTrue();
assertThat(found1.get().getId()).isEqualTo(book1.getId());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment