From 48c5a6970a898be89ea57deae89d78109ee276a2 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Sat, 26 Oct 2019 16:33:50 -0400 Subject: [PATCH 01/13] Add junit testing suite --- ProductInventoryLab.iml | 2 -- pom.xml | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) delete mode 100644 ProductInventoryLab.iml 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 + + + + From 8089999a2baaa7069672319e4e0ea692a88c9822 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Sat, 26 Oct 2019 16:52:58 -0400 Subject: [PATCH 02/13] Add sneaker/whiskey models and services --- src/main/java/models/Sneaker.java | 4 ++++ src/main/java/models/Whiskey.java | 4 ++++ src/main/java/services/SneakerService.java | 4 ++++ src/main/java/services/WhiskeyService.java | 4 ++++ src/test/java/models/SneakerTest.java | 4 ++++ src/test/java/models/WhiskeyTest.java | 4 ++++ src/test/java/services/SneakerServicesTest.java | 4 ++++ src/test/java/services/WhiskeyServicesTest.java | 4 ++++ 8 files changed, 32 insertions(+) create mode 100644 src/main/java/models/Sneaker.java create mode 100644 src/main/java/models/Whiskey.java create mode 100644 src/main/java/services/SneakerService.java create mode 100644 src/main/java/services/WhiskeyService.java create mode 100644 src/test/java/models/SneakerTest.java create mode 100644 src/test/java/models/WhiskeyTest.java create mode 100644 src/test/java/services/SneakerServicesTest.java create mode 100644 src/test/java/services/WhiskeyServicesTest.java diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java new file mode 100644 index 0000000..fa150ec --- /dev/null +++ b/src/main/java/models/Sneaker.java @@ -0,0 +1,4 @@ +package models; + +public class Sneaker { +} diff --git a/src/main/java/models/Whiskey.java b/src/main/java/models/Whiskey.java new file mode 100644 index 0000000..bb9e5d5 --- /dev/null +++ b/src/main/java/models/Whiskey.java @@ -0,0 +1,4 @@ +package models; + +public class Whiskey { +} diff --git a/src/main/java/services/SneakerService.java b/src/main/java/services/SneakerService.java new file mode 100644 index 0000000..a022353 --- /dev/null +++ b/src/main/java/services/SneakerService.java @@ -0,0 +1,4 @@ +package services; + +public class SneakerService { +} diff --git a/src/main/java/services/WhiskeyService.java b/src/main/java/services/WhiskeyService.java new file mode 100644 index 0000000..1307c24 --- /dev/null +++ b/src/main/java/services/WhiskeyService.java @@ -0,0 +1,4 @@ +package services; + +public class WhiskeyService { +} diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java new file mode 100644 index 0000000..c63eae0 --- /dev/null +++ b/src/test/java/models/SneakerTest.java @@ -0,0 +1,4 @@ +package models; + +public class SneakerTest { +} diff --git a/src/test/java/models/WhiskeyTest.java b/src/test/java/models/WhiskeyTest.java new file mode 100644 index 0000000..81c7672 --- /dev/null +++ b/src/test/java/models/WhiskeyTest.java @@ -0,0 +1,4 @@ +package models; + +public class WhiskeyTest { +} diff --git a/src/test/java/services/SneakerServicesTest.java b/src/test/java/services/SneakerServicesTest.java new file mode 100644 index 0000000..ecc0c96 --- /dev/null +++ b/src/test/java/services/SneakerServicesTest.java @@ -0,0 +1,4 @@ +package services; + +public class SneakerServicesTest { +} diff --git a/src/test/java/services/WhiskeyServicesTest.java b/src/test/java/services/WhiskeyServicesTest.java new file mode 100644 index 0000000..d6261d1 --- /dev/null +++ b/src/test/java/services/WhiskeyServicesTest.java @@ -0,0 +1,4 @@ +package services; + +public class WhiskeyServicesTest { +} From 64dda9fb513259dec7f4b02bab8f8849d4e5be5c Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 8 Nov 2019 11:52:09 -0500 Subject: [PATCH 03/13] add properties --- src/main/java/models/Sneaker.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index fa150ec..6fdc469 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -1,4 +1,14 @@ package models; public class Sneaker { + + private int id; + private String name; + private String brand; + private String sport; + private int size; + private int qty; + private float price; + + } From 799534f1d13e05ffdb610fdacc36092e3307bdd2 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 8 Nov 2019 12:22:47 -0500 Subject: [PATCH 04/13] add properties to whiskey --- src/main/java/models/Whiskey.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/models/Whiskey.java b/src/main/java/models/Whiskey.java index bb9e5d5..32d2151 100644 --- a/src/main/java/models/Whiskey.java +++ b/src/main/java/models/Whiskey.java @@ -1,4 +1,10 @@ package models; public class Whiskey { + + private String brand; + private int id; + private int qty; + + } From 45fd088cfe998f7826ecd48cae5d3d955a777edf Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Tue, 12 Nov 2019 15:34:02 -0500 Subject: [PATCH 05/13] Add get/set for sneaker name --- src/main/java/models/Sneaker.java | 10 +++++++++- src/test/java/models/SneakerTest.java | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index 6fdc469..65d0b40 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -6,9 +6,17 @@ public class Sneaker { private String name; private String brand; private String sport; - private int size; + private float size; private int qty; private float price; + public void setName(String name) { + this.name = name; + } + + public String getName(){ + return this.name; + } + } diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index c63eae0..1c1403d 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -1,4 +1,17 @@ package models; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + public class SneakerTest { + Sneaker testSneaker = new Sneaker(); + + @Test + public void setgetTestName(){ + String expected = "oleg"; + + testSneaker.setName (expected); + Assertions.assertEquals(expected,testSneaker.getName()); + + } } From 14320c717798410bb2420faa98fd0fa9eaaf8986 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Tue, 12 Nov 2019 15:36:44 -0500 Subject: [PATCH 06/13] Add get/set for sneaker brand --- src/main/java/models/Sneaker.java | 10 +++++++++- src/test/java/models/SneakerTest.java | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index 65d0b40..e2ab44e 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -14,9 +14,17 @@ public void setName(String name) { this.name = name; } - public String getName(){ + public String getName() { return this.name; } + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + } diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index 1c1403d..4e9a772 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -7,11 +7,20 @@ public class SneakerTest { Sneaker testSneaker = new Sneaker(); @Test - public void setgetTestName(){ + public void testSetGetName() { String expected = "oleg"; - testSneaker.setName (expected); - Assertions.assertEquals(expected,testSneaker.getName()); + testSneaker.setName(expected); + Assertions.assertEquals(expected, testSneaker.getName()); + + } + + @Test + public void testSetGetBrand() { + String expected = "valentin"; + + testSneaker.setBrand(expected); + Assertions.assertEquals(expected, testSneaker.getBrand()); } } From a9ab1dec843a2ac0e444c0eecd8076ed820ed54f Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Tue, 12 Nov 2019 15:41:10 -0500 Subject: [PATCH 07/13] Add get/set for sneaker sport --- src/main/java/models/Sneaker.java | 8 +++++++- src/test/java/models/SneakerTest.java | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index e2ab44e..c4cca7c 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -19,12 +19,18 @@ public String getName() { } public String getBrand() { - return brand; + 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; + } } diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index 4e9a772..df06e2b 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -23,4 +23,12 @@ public void testSetGetBrand() { Assertions.assertEquals(expected, testSneaker.getBrand()); } + + @Test + public void testSetGetSport(){ + String expected = "soccer"; + + testSneaker.setSport(expected); + Assertions.assertEquals(expected,testSneaker.getSport()); + } } From 7a60f7af83f1e48e81c1b6ac5fcee12474d4b018 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Tue, 12 Nov 2019 15:49:24 -0500 Subject: [PATCH 08/13] Finished adding getters and setters for the rest of the fields --- src/main/java/models/Sneaker.java | 36 +++++++++++++-------------- src/test/java/models/SneakerTest.java | 26 ++++++++++++++++++- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index c4cca7c..2469518 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -10,27 +10,27 @@ public class Sneaker { private int qty; private float price; - public void setName(String name) { - this.name = name; - } + public void setName(String name) { this.name = name;} - public String getName() { - return this.name; - } + public String getName() { return this.name; } - public String getBrand() { - return this.brand; - } + public String getBrand() { return this.brand; } - public void setBrand(String brand) { - this.brand = brand; - } + public void setBrand(String brand) { this.brand = brand; } - public void setSport(String sport){ - this.sport = sport; - } + public void setSport(String sport) { this.sport = sport; } - public String getSport(){ - return this.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; } } diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index df06e2b..88964c8 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -24,9 +24,33 @@ public void testSetGetBrand() { } + @Test + public void testSetGetSize(){ + float expected = 23L; + + 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 = 120L; + + testSneaker.setPrice(expected); + Assertions.assertEquals(expected,testSneaker.getPrice()); + } + @Test public void testSetGetSport(){ - String expected = "soccer"; + String expected = "Soccer"; testSneaker.setSport(expected); Assertions.assertEquals(expected,testSneaker.getSport()); From 51bcc731d7f2c67eaac0154ccbf1ea954b2bfa06 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Tue, 12 Nov 2019 15:54:07 -0500 Subject: [PATCH 09/13] Add tests/logic for whiskey class --- src/main/java/models/Whiskey.java | 10 +++++++++ src/test/java/models/WhiskeyTest.java | 31 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/main/java/models/Whiskey.java b/src/main/java/models/Whiskey.java index 32d2151..f847968 100644 --- a/src/main/java/models/Whiskey.java +++ b/src/main/java/models/Whiskey.java @@ -6,5 +6,15 @@ public class Whiskey { private int id; private int qty; + 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; } } diff --git a/src/test/java/models/WhiskeyTest.java b/src/test/java/models/WhiskeyTest.java index 81c7672..b3e06a9 100644 --- a/src/test/java/models/WhiskeyTest.java +++ b/src/test/java/models/WhiskeyTest.java @@ -1,4 +1,35 @@ package models; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + + public class WhiskeyTest { + + Whiskey testWhiskey = new Whiskey(); + + @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()); + } } From 3e6c10c794e89fc96ac76c6a06f10850a57cb42f Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Mon, 18 Nov 2019 13:18:36 -0500 Subject: [PATCH 10/13] Add sneaker constructor --- src/main/java/models/Sneaker.java | 12 ++++++ src/main/java/services/SneakerService.java | 20 ++++++++++ src/test/java/models/SneakerTest.java | 34 ++++++++++++++-- .../java/services/SneakerServicesTest.java | 39 +++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index 2469518..8e7a917 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -10,6 +10,16 @@ public class Sneaker { 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; } @@ -33,4 +43,6 @@ public class Sneaker { public float getPrice() { return this.price; } public void setPrice(float price) { this.price = price; } + + public float getId() { return this.id; } } diff --git a/src/main/java/services/SneakerService.java b/src/main/java/services/SneakerService.java index a022353..e211cac 100644 --- a/src/main/java/services/SneakerService.java +++ b/src/main/java/services/SneakerService.java @@ -1,4 +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, int 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/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index 88964c8..8237190 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -4,7 +4,16 @@ import org.junit.jupiter.api.Test; public class SneakerTest { - Sneaker testSneaker = new Sneaker(); + + 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() { @@ -26,7 +35,7 @@ public void testSetGetBrand() { @Test public void testSetGetSize(){ - float expected = 23L; + float expected = 23f; testSneaker.setSize(expected); Assertions.assertEquals(expected,testSneaker.getSize()); @@ -42,7 +51,7 @@ public void testSetGetQty(){ @Test public void testSetGetPrice(){ - float expected = 120L; + float expected = 120.00f; testSneaker.setPrice(expected); Assertions.assertEquals(expected,testSneaker.getPrice()); @@ -55,4 +64,23 @@ public void testSetGetSport(){ 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/services/SneakerServicesTest.java b/src/test/java/services/SneakerServicesTest.java index ecc0c96..6879f3f 100644 --- a/src/test/java/services/SneakerServicesTest.java +++ b/src/test/java/services/SneakerServicesTest.java @@ -1,4 +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.getQuantity +// 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); + + } } From 8d51cc3104befb7a50b9e2bd956cee120b0dd623 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Mon, 18 Nov 2019 13:24:09 -0500 Subject: [PATCH 11/13] Add constructor for the rest of the models --- src/main/java/models/Whiskey.java | 6 ++++++ src/test/java/models/WhiskeyTest.java | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/models/Whiskey.java b/src/main/java/models/Whiskey.java index f847968..18028ed 100644 --- a/src/main/java/models/Whiskey.java +++ b/src/main/java/models/Whiskey.java @@ -6,6 +6,12 @@ public class Whiskey { private int id; private int qty; + public Whiskey(String brand, int id, int quantity){ + this.brand = brand; + this.id = id; + this.qty = quantity; + } + public String getBrand() { return this.brand; } public void setBrand(String brand) { this.brand = brand; } diff --git a/src/test/java/models/WhiskeyTest.java b/src/test/java/models/WhiskeyTest.java index b3e06a9..8bec560 100644 --- a/src/test/java/models/WhiskeyTest.java +++ b/src/test/java/models/WhiskeyTest.java @@ -6,7 +6,10 @@ public class WhiskeyTest { - Whiskey testWhiskey = new Whiskey(); + private String expectedBrand = "Johnny"; + private int expectedId = 1; + private int expectedQty = 2; + Whiskey testWhiskey = new Whiskey(expectedBrand,expectedId,expectedQty); @Test public void testSetGetBrand() { @@ -32,4 +35,13 @@ public void testSetGetId(){ testWhiskey.setId(expected); Assertions.assertEquals(expected,testWhiskey.getId()); } + + @Test + public void testConstructor(){ + Whiskey newTest = new Whiskey(expectedBrand,expectedId,expectedQty); + + Assertions.assertEquals(expectedBrand,testWhiskey.getBrand()); + Assertions.assertEquals(expectedId,testWhiskey.getId()); + Assertions.assertEquals(expectedQty,testWhiskey.getQty()); + } } From 0a94b73dac42699fea8d22f76746c3ee51aa7da7 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Tue, 19 Nov 2019 15:36:13 -0500 Subject: [PATCH 12/13] Add sneaker service --- src/main/java/models/Sneaker.java | 2 +- src/main/java/services/SneakerService.java | 2 +- .../java/services/SneakerServicesTest.java | 62 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index 8e7a917..5b1a018 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -44,5 +44,5 @@ public Sneaker(int id, String name, String brand, String sport, float size, int public void setPrice(float price) { this.price = price; } - public float getId() { return this.id; } + public int getId() { return this.id; } } diff --git a/src/main/java/services/SneakerService.java b/src/main/java/services/SneakerService.java index e211cac..60b9a61 100644 --- a/src/main/java/services/SneakerService.java +++ b/src/main/java/services/SneakerService.java @@ -10,7 +10,7 @@ public class SneakerService { private ArrayList inventory = new ArrayList<>(); - public Sneaker create(String name, String brand, String sport, int size, int quantity, float price) { + 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); diff --git a/src/test/java/services/SneakerServicesTest.java b/src/test/java/services/SneakerServicesTest.java index 6879f3f..2b21712 100644 --- a/src/test/java/services/SneakerServicesTest.java +++ b/src/test/java/services/SneakerServicesTest.java @@ -7,37 +7,37 @@ 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.getQuantity -// 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); + + // (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); } } From b3249f2abb111169e48afd72fdf9a218951d4dfb Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Tue, 19 Nov 2019 15:56:46 -0500 Subject: [PATCH 13/13] Add whiskey service --- src/main/java/models/Whiskey.java | 13 ++++++++- src/main/java/services/WhiskeyService.java | 20 +++++++++++++ src/test/java/models/WhiskeyTest.java | 7 +++-- .../java/services/WhiskeyServicesTest.java | 29 +++++++++++++++++++ 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/main/java/models/Whiskey.java b/src/main/java/models/Whiskey.java index 18028ed..4d7e339 100644 --- a/src/main/java/models/Whiskey.java +++ b/src/main/java/models/Whiskey.java @@ -5,11 +5,15 @@ public class Whiskey { private String brand; private int id; private int qty; + private float price; - public Whiskey(String brand, int id, int quantity){ + + + 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; } @@ -23,4 +27,11 @@ public Whiskey(String brand, int id, int quantity){ 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/WhiskeyService.java b/src/main/java/services/WhiskeyService.java index 1307c24..ceccf98 100644 --- a/src/main/java/services/WhiskeyService.java +++ b/src/main/java/services/WhiskeyService.java @@ -1,4 +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/WhiskeyTest.java b/src/test/java/models/WhiskeyTest.java index 8bec560..30e61b7 100644 --- a/src/test/java/models/WhiskeyTest.java +++ b/src/test/java/models/WhiskeyTest.java @@ -9,7 +9,8 @@ public class WhiskeyTest { private String expectedBrand = "Johnny"; private int expectedId = 1; private int expectedQty = 2; - Whiskey testWhiskey = new Whiskey(expectedBrand,expectedId,expectedQty); + private float expectedPrice = 50f; + Whiskey testWhiskey = new Whiskey(expectedBrand,expectedId,expectedQty,expectedPrice); @Test public void testSetGetBrand() { @@ -38,8 +39,8 @@ public void testSetGetId(){ @Test public void testConstructor(){ - Whiskey newTest = new Whiskey(expectedBrand,expectedId,expectedQty); - + 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/WhiskeyServicesTest.java b/src/test/java/services/WhiskeyServicesTest.java index d6261d1..93349f0 100644 --- a/src/test/java/services/WhiskeyServicesTest.java +++ b/src/test/java/services/WhiskeyServicesTest.java @@ -1,4 +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); + + } }