diff --git a/ProductInventoryLab.iml b/ProductInventoryLab.iml deleted file mode 100644 index 78b2cc5..0000000 --- a/ProductInventoryLab.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 43c1af2..98c32ae 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,16 @@ ProductInventoryLab 1.0-SNAPSHOT + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + + + + diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java new file mode 100644 index 0000000..5b1a018 --- /dev/null +++ b/src/main/java/models/Sneaker.java @@ -0,0 +1,48 @@ +package models; + +public class Sneaker { + + private int id; + private String name; + private String brand; + private String sport; + private float size; + private int qty; + private float price; + + public Sneaker(int id, String name, String brand, String sport, float size, int quantity, float price){ + this.id = id; + this.name = name; + this.brand = brand; + this.sport = sport; + this.size = size; + this.qty = quantity; + this.price = price; + } + + public void setName(String name) { this.name = name;} + + public String getName() { return this.name; } + + public String getBrand() { return this.brand; } + + public void setBrand(String brand) { this.brand = brand; } + + public void setSport(String sport) { this.sport = sport; } + + public String getSport() { return this.sport; } + + public float getSize() { return this.size; } + + public void setSize(float size) { this.size = size; } + + public int getQty() { return this.qty; } + + public void setQty(int qty) { this.qty = qty; } + + public float getPrice() { return this.price; } + + public void setPrice(float price) { this.price = price; } + + public int getId() { return this.id; } +} diff --git a/src/main/java/models/Whiskey.java b/src/main/java/models/Whiskey.java new file mode 100644 index 0000000..4d7e339 --- /dev/null +++ b/src/main/java/models/Whiskey.java @@ -0,0 +1,37 @@ +package models; + +public class Whiskey { + + private String brand; + private int id; + private int qty; + private float price; + + + + public Whiskey(String brand, int id, int quantity, float price){ + this.brand = brand; + this.id = id; + this.qty = quantity; + this.price = price; + } + + public String getBrand() { return this.brand; } + + public void setBrand(String brand) { this.brand = brand; } + + public int getQty() { return this.qty; } + + public void setQty(int qty) { this.qty = qty; } + + public int getId() { return this.id; } + + public void setId(int id) { this.id = id; } + public float getPrice() { + return this.price; + } + + public void setPrice(float price) { + this.price = price; + } +} diff --git a/src/main/java/services/SneakerService.java b/src/main/java/services/SneakerService.java new file mode 100644 index 0000000..60b9a61 --- /dev/null +++ b/src/main/java/services/SneakerService.java @@ -0,0 +1,24 @@ +package services; + +import models.Sneaker; + +import java.util.ArrayList; + +public class SneakerService { + + private static int nextId = 1; + private ArrayList inventory = new ArrayList<>(); + + + public Sneaker create(String name, String brand, String sport, float size, int quantity, float price) { + + // (2) + Sneaker createdSneaker = new Sneaker(nextId++, name, brand, sport, size, quantity, price); + + // (3) + inventory.add(createdSneaker); + + // (4) + return createdSneaker; + } +} diff --git a/src/main/java/services/WhiskeyService.java b/src/main/java/services/WhiskeyService.java new file mode 100644 index 0000000..ceccf98 --- /dev/null +++ b/src/main/java/services/WhiskeyService.java @@ -0,0 +1,24 @@ +package services; + +import models.Whiskey; + +import java.util.ArrayList; + +public class WhiskeyService { + + private static int nextId = 1; + private ArrayList inventory = new ArrayList<>(); + + + public Whiskey create(String brand, int quantity, float price) { + + // (2) + Whiskey createdWhiskey = new Whiskey(brand, nextId++ ,quantity, price); + + // (3) + this.inventory.add(createdWhiskey); + + // (4) + return createdWhiskey; + } +} diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java new file mode 100644 index 0000000..8237190 --- /dev/null +++ b/src/test/java/models/SneakerTest.java @@ -0,0 +1,86 @@ +package models; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SneakerTest { + + int expectedId = 6; + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + String expectedSport = "Tennnis"; + float expectedSize = 10.5f; + int expectedQty = 10; + float expectedPrice = 80.00f; + + Sneaker testSneaker = new Sneaker(expectedId,expectedName,expectedBrand,expectedSport,expectedSize,expectedQty,expectedId); + + @Test + public void testSetGetName() { + String expected = "oleg"; + + testSneaker.setName(expected); + Assertions.assertEquals(expected, testSneaker.getName()); + + } + + @Test + public void testSetGetBrand() { + String expected = "valentin"; + + testSneaker.setBrand(expected); + Assertions.assertEquals(expected, testSneaker.getBrand()); + + } + + @Test + public void testSetGetSize(){ + float expected = 23f; + + testSneaker.setSize(expected); + Assertions.assertEquals(expected,testSneaker.getSize()); + } + + @Test + public void testSetGetQty(){ + int expected = 32; + + testSneaker.setQty(expected); + Assertions.assertEquals(expected,testSneaker.getQty()); + } + + @Test + public void testSetGetPrice(){ + float expected = 120.00f; + + testSneaker.setPrice(expected); + Assertions.assertEquals(expected,testSneaker.getPrice()); + } + + @Test + public void testSetGetSport(){ + String expected = "Soccer"; + + testSneaker.setSport(expected); + Assertions.assertEquals(expected,testSneaker.getSport()); + } + + @Test // (1) + public void constructorTest(){ + + // (2) + + + // (3) + Sneaker testSneaker = new Sneaker(expectedId, expectedName, expectedBrand, + expectedSport, expectedSize, expectedQty,expectedPrice); + + // (4) + Assertions.assertEquals(expectedId, testSneaker.getId()); + Assertions.assertEquals(expectedName, testSneaker.getName()); + Assertions.assertEquals(expectedBrand, testSneaker.getBrand()); + Assertions.assertEquals(expectedSport, testSneaker.getSport()); + Assertions.assertEquals(expectedQty, testSneaker.getQty()); + Assertions.assertEquals(expectedPrice, testSneaker.getPrice()); + } +} diff --git a/src/test/java/models/WhiskeyTest.java b/src/test/java/models/WhiskeyTest.java new file mode 100644 index 0000000..30e61b7 --- /dev/null +++ b/src/test/java/models/WhiskeyTest.java @@ -0,0 +1,48 @@ +package models; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + + +public class WhiskeyTest { + + private String expectedBrand = "Johnny"; + private int expectedId = 1; + private int expectedQty = 2; + private float expectedPrice = 50f; + Whiskey testWhiskey = new Whiskey(expectedBrand,expectedId,expectedQty,expectedPrice); + + @Test + public void testSetGetBrand() { + String expected = "valentin"; + + testWhiskey.setBrand(expected); + Assertions.assertEquals(expected, testWhiskey.getBrand()); + + } + + @Test + public void testSetGetQty(){ + int expected = 32; + + testWhiskey.setQty(expected); + Assertions.assertEquals(expected,testWhiskey.getQty()); + } + + @Test + public void testSetGetId(){ + int expected = 32097; + + testWhiskey.setId(expected); + Assertions.assertEquals(expected,testWhiskey.getId()); + } + + @Test + public void testConstructor(){ + Whiskey newTest = new Whiskey(expectedBrand,expectedId,expectedQty,expectedPrice); + Assertions.assertEquals(expectedPrice,testWhiskey.getPrice()); + Assertions.assertEquals(expectedBrand,testWhiskey.getBrand()); + Assertions.assertEquals(expectedId,testWhiskey.getId()); + Assertions.assertEquals(expectedQty,testWhiskey.getQty()); + } +} diff --git a/src/test/java/services/SneakerServicesTest.java b/src/test/java/services/SneakerServicesTest.java new file mode 100644 index 0000000..2b21712 --- /dev/null +++ b/src/test/java/services/SneakerServicesTest.java @@ -0,0 +1,43 @@ +package services; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import models.Sneaker; + +public class SneakerServicesTest { + @Test + public void createTest(){ + + // (1) + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + String expectedSport = "Tennis"; + float expectedSize = 10.5f; + int expectedQty = 10; + float expectedPrice = 80.00f; + + // (2) + SneakerService sneakerService = new SneakerService(); + Sneaker testSneaker = sneakerService.create(expectedName, expectedBrand, + expectedSport, expectedSize, expectedQty, expectedPrice); + + // (3) + int actualId = testSneaker.getId(); + String actualName = testSneaker.getName(); + String actualBrand = testSneaker.getBrand(); + String actualSport = testSneaker.getSport(); + float actualSize = testSneaker.getSize(); + 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(expectedSize, actualSize); + Assertions.assertEquals(expectedQty, actualQty); + Assertions.assertEquals(expectedPrice, actualPrice); + + } +} diff --git a/src/test/java/services/WhiskeyServicesTest.java b/src/test/java/services/WhiskeyServicesTest.java new file mode 100644 index 0000000..93349f0 --- /dev/null +++ b/src/test/java/services/WhiskeyServicesTest.java @@ -0,0 +1,33 @@ +package services; + +import models.Whiskey; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class WhiskeyServicesTest { + @Test + public void createTest() { + + // (1) + String expectedBrand = "Johnny"; + int expectedQty = 10; + float expectedPrice = 80.00f; + + // (2) + WhiskeyService whiskeyService = new WhiskeyService(); + Whiskey testWhiskey = whiskeyService.create(expectedBrand, expectedQty, expectedPrice); + + // (3) + int actualId = testWhiskey.getId(); + String actualBrand = testWhiskey.getBrand(); + int actualQty = testWhiskey.getQty(); + float actualPrice = testWhiskey.getPrice(); + + // (4) + Assertions.assertEquals(Integer.class.getName(), new Integer(actualId).getClass().getName()); + Assertions.assertEquals(expectedBrand, actualBrand); + Assertions.assertEquals(expectedQty, actualQty); + Assertions.assertEquals(expectedPrice, actualPrice); + + } +}