diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b661a5..f0d7b15 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/pom.xml b/pom.xml index 43c1af2..67fface 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,20 @@ io.zipcodewilmington ProductInventoryLab 1.0-SNAPSHOT + + + junit + junit + 4.13.1 + test + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + diff --git a/src/main/java/models/Pandas.java b/src/main/java/models/Pandas.java new file mode 100644 index 0000000..c1bfd9a --- /dev/null +++ b/src/main/java/models/Pandas.java @@ -0,0 +1,71 @@ +package models; + +public class Pandas { + private int id; + private String name; + private String species ; + private int age; + private int qty; + private float price; + + public Pandas() { + + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSpecies() { + return species; + } + + public void setSpecies(String species) { + this.species = species; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public int getQty() { + return qty; + } + + public void setQty(int qty) { + this.qty = qty; + } + + public float getPrice() { + return price; + } + + public void setPrice(float price) { + this.price = price; + } + + public Pandas(int id, String name, String species, int age, int qty, float price) { + this.id = id; + this.name = name; + this.species = species; + this.age = age; + this.qty = qty; + this.price = price; + } +} diff --git a/src/main/java/models/Toaster.java b/src/main/java/models/Toaster.java new file mode 100644 index 0000000..64a608b --- /dev/null +++ b/src/main/java/models/Toaster.java @@ -0,0 +1,74 @@ +package models; + +public class Toaster { + private int id; + private String name; + private String brand; + private int toastSlots; + private int qty; + private float price; + + public Toaster() { + + } + + + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public int getToastSlots() { + return toastSlots; + } + + public void setToastSlots(int toastSlots) { + this.toastSlots = toastSlots; + } + + public int getQty() { + return qty; + } + + public void setQty(int qty) { + this.qty = qty; + } + + public float getPrice() { + return price; + } + + public void setPrice(float price) { + this.price = price; + } + + public Toaster(int id, String name, String brand, int toastSlots, int qty, float price) { + this.id = id; + this.name = name; + this.brand = brand; + this.toastSlots = toastSlots; + this.qty = qty; + this.price = price; + } +} diff --git a/src/main/java/services/PandaService.java b/src/main/java/services/PandaService.java new file mode 100644 index 0000000..cfa22fc --- /dev/null +++ b/src/main/java/services/PandaService.java @@ -0,0 +1,25 @@ +package services; + +import models.Pandas; +import models.Toaster; + +import java.util.ArrayList; +import java.util.List; + +public class PandaService { + private static int nextId = 1; // (1) + + private List inventory = new ArrayList<>(); // (2) + + public Pandas create(String name, String species, int age, int quantity, float price) { + + // (2) + Pandas createdPanda = new Pandas(nextId++, name, species, age, quantity, price); + + // (3) + inventory.add(createdPanda); + + // (4) + return createdPanda; + } +} diff --git a/src/main/java/services/ToasterService.java b/src/main/java/services/ToasterService.java new file mode 100644 index 0000000..fc57429 --- /dev/null +++ b/src/main/java/services/ToasterService.java @@ -0,0 +1,24 @@ +package services; + +import models.Toaster; + +import java.util.ArrayList; +import java.util.List; + +public class ToasterService { + private static int nextId = 1; // (1) + + private List inventory = new ArrayList<>(); // (2) + + public Toaster create(String name, String brand, int toasterSlots, int quantity, float price) { + + // (2) + Toaster createdSneaker = new Toaster(nextId++, name, brand, toasterSlots, quantity, price); + + // (3) + inventory.add(createdSneaker); + + // (4) + return createdSneaker; + } +} diff --git a/src/test/java/models/PandasTest.java b/src/test/java/models/PandasTest.java new file mode 100644 index 0000000..7e64a8c --- /dev/null +++ b/src/test/java/models/PandasTest.java @@ -0,0 +1,43 @@ +package models; + +import org.junit.Test; +import org.junit.jupiter.api.Assertions; + +import static org.junit.jupiter.api.Assertions.*; + +public class PandasTest { + @Test + public void setNameTest() { + // given (1) + String expected = "OZWEEGO"; + + // when (2) + Pandas redpanda= new Pandas(); + redpanda.setName(expected); + + // then (3) + Assertions.assertEquals(expected, redpanda.getName()); + } + @Test // (1) + public void constructorTest(){ + + int expectedId = 6; + String expectedName = "Stan Smith"; + String expectedSpecies = "Adidas"; + int expectedAge = 2; + int expectedQty = 10; + float expectedPrice = 80.00f; + + // (3) + Toaster redpanda = new Toaster(expectedId, expectedName, expectedSpecies, + expectedAge, expectedQty,expectedPrice); + + // (4) + Assertions.assertEquals(expectedId, redpanda.getId()); + Assertions.assertEquals(expectedName, redpanda.getName()); + Assertions.assertEquals(expectedSpecies, redpanda.getBrand()); + Assertions.assertEquals(expectedAge, redpanda.getToastSlots()); + Assertions.assertEquals(expectedQty, redpanda.getQty()); + Assertions.assertEquals(expectedPrice, redpanda.getPrice()); + } +} \ No newline at end of file diff --git a/src/test/java/models/ToasterTest.java b/src/test/java/models/ToasterTest.java new file mode 100644 index 0000000..6219d64 --- /dev/null +++ b/src/test/java/models/ToasterTest.java @@ -0,0 +1,45 @@ +package models; + +import org.junit.Test; +import org.junit.jupiter.api.Assertions; + +import static org.junit.Assert.*; + +public class ToasterTest { + + @Test + public void setNameTest() { + // given (1) + String expected = "OZWEEGO"; + + // when (2) + Toaster toasty= new Toaster(); + toasty.setName(expected); + + // then (3) + Assertions.assertEquals(expected, toasty.getName()); + } + @Test // (1) + public void constructorTest(){ + + int expectedId = 6; + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + int expectedSport = 2; + int expectedQty = 10; + float expectedPrice = 80.00f; + + // (3) + Toaster toasty = new Toaster(expectedId, expectedName, expectedBrand, + expectedSport, expectedQty,expectedPrice); + + // (4) + Assertions.assertEquals(expectedId, toasty.getId()); + Assertions.assertEquals(expectedName, toasty.getName()); + Assertions.assertEquals(expectedBrand, toasty.getBrand()); + Assertions.assertEquals(expectedSport, toasty.getToastSlots()); + Assertions.assertEquals(expectedQty, toasty.getQty()); + Assertions.assertEquals(expectedPrice, toasty.getPrice()); + } + } + diff --git a/src/test/java/services/PandaServiceTest.java b/src/test/java/services/PandaServiceTest.java new file mode 100644 index 0000000..884f71e --- /dev/null +++ b/src/test/java/services/PandaServiceTest.java @@ -0,0 +1,44 @@ +package services; + +import models.Pandas; +import models.Toaster; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; + +import static org.junit.Assert.*; + +public class PandaServiceTest { + @Test + public void createTest(){ + + // (1) + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + int expectedSport = 2; + int expectedQty = 10; + float expectedPrice = 80.00f; + + // (2) + PandaService pandiService = new PandaService(); + Pandas testPandi = pandiService.create(expectedName, expectedBrand, + expectedSport, expectedQty, expectedPrice); + + // (3) + int actualId = testPandi.getId(); + String actualName = testPandi.getName(); + String actualBrand = testPandi.getSpecies(); + int actualSport = testPandi.getAge(); + int actualQty = testPandi.getQty(); + float actualPrice = testPandi.getPrice(); + + // (4) + Assertions.assertEquals(Integer.class.getName(), new Integer(actualId).getClass().getName()); + Assertions.assertEquals(expectedName, actualName); + Assertions.assertEquals(expectedBrand, actualBrand); + Assertions.assertEquals(expectedSport, actualSport); + Assertions.assertEquals(expectedQty, actualQty); + Assertions.assertEquals(expectedPrice, actualPrice); + + } + +} \ No newline at end of file diff --git a/src/test/java/services/ToasterServiceTest.java b/src/test/java/services/ToasterServiceTest.java new file mode 100644 index 0000000..c0b89e8 --- /dev/null +++ b/src/test/java/services/ToasterServiceTest.java @@ -0,0 +1,42 @@ +package services; + +import models.Toaster; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; + +import static org.junit.Assert.*; + +public class ToasterServiceTest { + @Test + public void createTest(){ + + // (1) + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + int expectedSport = 2; + int expectedQty = 10; + float expectedPrice = 80.00f; + + // (2) + ToasterService toasterService = new ToasterService(); + Toaster testSneaker = toasterService.create(expectedName, expectedBrand, + expectedSport, expectedQty, expectedPrice); + + // (3) + int actualId = testSneaker.getId(); + String actualName = testSneaker.getName(); + String actualBrand = testSneaker.getBrand(); + int actualSport = testSneaker.getToastSlots(); + int actualQty = testSneaker.getQty(); + float actualPrice = testSneaker.getPrice(); + + // (4) + Assertions.assertEquals(Integer.class.getName(), new Integer(actualId).getClass().getName()); + Assertions.assertEquals(expectedName, actualName); + Assertions.assertEquals(expectedBrand, actualBrand); + Assertions.assertEquals(expectedSport, actualSport); + Assertions.assertEquals(expectedQty, actualQty); + Assertions.assertEquals(expectedPrice, actualPrice); + + } +} \ No newline at end of file