diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2022-01-26 00:48:10 +0000 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2022-01-26 00:48:10 +0000 |
| commit | 278aabf6966c67da0c70f785aa48fcabbab6780c (patch) | |
| tree | 197d8ba7f41e7d6fc6a28c0ffe5070c2566e9e9e /src/test/java/dev/submelon/pantry/ItemRepositoryTests.java | |
| parent | 11264e508d887a0f8e4317963c0ee032b551023d (diff) | |
| download | pantry-278aabf6966c67da0c70f785aa48fcabbab6780c.tar.gz pantry-278aabf6966c67da0c70f785aa48fcabbab6780c.tar.bz2 pantry-278aabf6966c67da0c70f785aa48fcabbab6780c.zip | |
Retrieve items by name
Diffstat (limited to 'src/test/java/dev/submelon/pantry/ItemRepositoryTests.java')
| -rw-r--r-- | src/test/java/dev/submelon/pantry/ItemRepositoryTests.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/test/java/dev/submelon/pantry/ItemRepositoryTests.java b/src/test/java/dev/submelon/pantry/ItemRepositoryTests.java new file mode 100644 index 0000000..9278599 --- /dev/null +++ b/src/test/java/dev/submelon/pantry/ItemRepositoryTests.java @@ -0,0 +1,51 @@ +package dev.submelon.pantry; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@TestInstance(Lifecycle.PER_CLASS) +@SpringBootTest +public class ItemRepositoryTests { + @Autowired + private ItemRepository itemRepository; + + @BeforeAll + public void before() throws Exception { + Item pb = new Item("Peanut Butter", "Crunchy", 14.0); + Item jelly = new Item("Strawberry Preserves", "The best", 12.8); + Item bread = new Item("Oatnut Bread", "Relatively healthy, right?", 10); + assertNull(pb.getId()); + assertNull(jelly.getId()); + assertNull(bread.getId()); + this.itemRepository.save(pb); + this.itemRepository.save(jelly); + this.itemRepository.save(bread); + assertNotNull(pb.getId()); + assertNotNull(jelly.getId()); + assertNotNull(bread.getId()); + } + + @Test + public void testFetchData() { + Item pb = itemRepository.findByName("Peanut Butter"); + assertNotNull(pb); + assertEquals(14.0, pb.getQuantity()); + Iterable<Item> items = itemRepository.findAll(); + + int count = 0; + for (Item item : items) { + assertNotNull(item); + count++; + } + + assertEquals(3, count); + } +} |
