From 89cc1cd59c02b89c9008710343c48ef0d7a20760 Mon Sep 17 00:00:00 2001 From: Manny Date: Sat, 3 Jul 2021 23:54:23 -0400 Subject: [PATCH 01/11] add junit testing suite --- .idea/compiler.xml | 1 + .idea/jarRepositories.xml | 20 ++++++++++++++++++++ pom.xml | 18 +++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .idea/jarRepositories.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 7a4bf35..4f08829 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,6 +6,7 @@ + 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/pom.xml b/pom.xml index 43c1af2..0d277dd 100644 --- a/pom.xml +++ b/pom.xml @@ -22,4 +22,20 @@ - \ No newline at end of file + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + + + org.junit.jupiter + junit-jupiter-api + 5.4.2 + test + + + + + From cf3124f50f661ed1e4267c514a2095d138a5d3ae Mon Sep 17 00:00:00 2001 From: Manny Date: Sun, 4 Jul 2021 01:13:04 -0400 Subject: [PATCH 02/11] add sneaker/hat models and services --- src/main/java/models/Hat.java | 4 ++++ src/main/java/models/Sneaker.java | 4 ++++ src/main/java/services/HatService.java | 4 ++++ src/main/java/services/SneakerService.java | 4 ++++ src/test/java/models/HatTest.java | 4 ++++ src/test/java/models/SneakerTest.java | 4 ++++ src/test/java/services/HatServiceTest.java | 4 ++++ src/test/java/services/SneakerServiceTest.java | 4 ++++ 8 files changed, 32 insertions(+) create mode 100644 src/main/java/models/Hat.java create mode 100644 src/main/java/models/Sneaker.java create mode 100644 src/main/java/services/HatService.java create mode 100644 src/main/java/services/SneakerService.java create mode 100644 src/test/java/models/HatTest.java create mode 100644 src/test/java/models/SneakerTest.java create mode 100644 src/test/java/services/HatServiceTest.java create mode 100644 src/test/java/services/SneakerServiceTest.java diff --git a/src/main/java/models/Hat.java b/src/main/java/models/Hat.java new file mode 100644 index 0000000..9185436 --- /dev/null +++ b/src/main/java/models/Hat.java @@ -0,0 +1,4 @@ +package models; + +public class Hat { +} 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/services/HatService.java b/src/main/java/services/HatService.java new file mode 100644 index 0000000..6b2119f --- /dev/null +++ b/src/main/java/services/HatService.java @@ -0,0 +1,4 @@ +package services; + +public class HatService { +} 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/test/java/models/HatTest.java b/src/test/java/models/HatTest.java new file mode 100644 index 0000000..b21936f --- /dev/null +++ b/src/test/java/models/HatTest.java @@ -0,0 +1,4 @@ +package models; + +public class HatTest { +} 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/services/HatServiceTest.java b/src/test/java/services/HatServiceTest.java new file mode 100644 index 0000000..540baf3 --- /dev/null +++ b/src/test/java/services/HatServiceTest.java @@ -0,0 +1,4 @@ +package services; + +public class HatServiceTest { +} diff --git a/src/test/java/services/SneakerServiceTest.java b/src/test/java/services/SneakerServiceTest.java new file mode 100644 index 0000000..3ae2e9a --- /dev/null +++ b/src/test/java/services/SneakerServiceTest.java @@ -0,0 +1,4 @@ +package services; + +public class SneakerServiceTest { +} From 164574f3499e6c00f4088725a78bdf248c007698 Mon Sep 17 00:00:00 2001 From: Manny Date: Sun, 4 Jul 2021 16:20:24 -0400 Subject: [PATCH 03/11] added sneaker properties --- src/main/java/models/Sneaker.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index fa150ec..ac89b4a 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -1,4 +1,11 @@ package models; public class Sneaker { + private int id; + private String name; + private String brand; + private String sport; + private int size; + private int quantity; + private float price; } From 13f4a683019f074121d45e296f2d4f922ca83914 Mon Sep 17 00:00:00 2001 From: Manny Date: Sun, 4 Jul 2021 16:29:28 -0400 Subject: [PATCH 04/11] added hat properties --- src/main/java/models/Hat.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/models/Hat.java b/src/main/java/models/Hat.java index 9185436..9f19eb5 100644 --- a/src/main/java/models/Hat.java +++ b/src/main/java/models/Hat.java @@ -1,4 +1,11 @@ package models; public class Hat { + private int id; + private String type; //fitted, snapback or strapback + private String sport; //baseball, basketball, NFL + private String team; + private int size; + private int quantity; + private float price; } From bbc507b85674c5fac1d795e4a84859cd51beddd5 Mon Sep 17 00:00:00 2001 From: Manny Date: Sun, 4 Jul 2021 18:12:27 -0400 Subject: [PATCH 05/11] added SneakerTest --- src/main/java/models/Sneaker.java | 66 +++++++++++++++++- src/test/java/models/SneakerTest.java | 96 +++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 1 deletion(-) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index ac89b4a..8d57259 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -5,7 +5,71 @@ public class Sneaker { private String name; private String brand; private String sport; - private int size; + private double size; private int quantity; private float price; + + + //================ SETTERS ================// + public void setId(int id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public void setSport(String sport) { + this.sport = sport; + } + + public void setSize(double size) { + this.size = size; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public void setPrice(float price) { + this.price = price; + } + + + //================ GETTERS ================// + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public String getBrand() { + return brand; + } + + public String getSport() { + return sport; + } + + public double getSize() { + return size; + } + + public int getQuantity() { + return quantity; + } + + public float getPrice() { + return price; + } + + } + + diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index c63eae0..4cd4d65 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -1,4 +1,100 @@ package models; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + public class SneakerTest { + + @Test + public void setIdTest() { + //Given + int expected = 7001; + + // When + Sneaker testSneaker = new Sneaker(); + testSneaker.setId(expected); + + // Then + Assertions.assertEquals(expected, testSneaker.getId()); + } + + @Test + public void setNameTest() { + // Given + String expected = "YeezyBoost 700"; + + // When + Sneaker testSneaker = new Sneaker(); + testSneaker.setName(expected); + + // Then + Assertions.assertEquals(expected, testSneaker.getName()); + } + + @Test + public void setBrandTest() { + //Given + String expected = "Adidas"; + + // When + Sneaker testSneaker = new Sneaker(); + testSneaker.setBrand(expected); + + // Then + Assertions.assertEquals(expected, testSneaker.getBrand()); + } + + @Test + public void setSportTest() { + //Given + String expected = "Running"; + + // When + Sneaker testSneaker = new Sneaker(); + testSneaker.setSport(expected); + + // Then + Assertions.assertEquals(expected, testSneaker.getSport()); + } + + @Test + public void setSizeTest() { + //Given + double expected = 10.5; + + // When + Sneaker testSneaker = new Sneaker(); + testSneaker.setSize(expected); + + // Then + Assertions.assertEquals(expected, testSneaker.getSize()); + } + + @Test + public void setQuantityTest() { + //Given + int expected = 20; + + // When + Sneaker testSneaker = new Sneaker(); + testSneaker.setQuantity(expected); + + // Then + Assertions.assertEquals(expected, testSneaker.getQuantity()); + } + + @Test + public void setPriceTest() { + //Given + float expected = 200.00F; + + // When + Sneaker testSneaker = new Sneaker(); + testSneaker.setPrice(expected); + + // Then + Assertions.assertEquals(expected, testSneaker.getPrice()); + } + + } From 7f0321d1e8ca76fe4c3c50a27c4290c21ec658e1 Mon Sep 17 00:00:00 2001 From: Manny Date: Sun, 4 Jul 2021 20:03:38 -0400 Subject: [PATCH 06/11] added HatTest --- src/main/java/models/Hat.java | 64 +++++++++++++++++- src/main/java/models/Sneaker.java | 10 +-- src/test/java/models/HatTest.java | 96 +++++++++++++++++++++++++++ src/test/java/models/SneakerTest.java | 6 +- 4 files changed, 166 insertions(+), 10 deletions(-) diff --git a/src/main/java/models/Hat.java b/src/main/java/models/Hat.java index 9f19eb5..9c365e9 100644 --- a/src/main/java/models/Hat.java +++ b/src/main/java/models/Hat.java @@ -1,11 +1,71 @@ package models; public class Hat { - private int id; + private int hatId; private String type; //fitted, snapback or strapback private String sport; //baseball, basketball, NFL private String team; - private int size; + private String size; //small/ medium, large private int quantity; private float price; + + + //================ SETTERS ================// + public void setHatId(int hatId) { + this.hatId = hatId; + } + + public void setType(String type) { + this.type = type; + } + + public void setSport(String sport) { + this.sport = sport; + } + + public void setTeam(String team) { + this.team = team; + } + + public void setSize(String size) { + this.size = size; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public void setPrice(float price) { + this.price = price; + } + + //================ GETTERS ================// + public int getHatId() { + return hatId; + } + + public String getType() { + return type; + } + + public String getSport() { + return sport; + } + + public String getTeam() { + return team; + } + + public String getSize() { + return size; + } + + public int getQuantity() { + return quantity; + } + + public float getPrice() { + return price; + } + } diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index 8d57259..d0c2ead 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -1,7 +1,7 @@ package models; public class Sneaker { - private int id; + private int sneakerId; private String name; private String brand; private String sport; @@ -11,8 +11,8 @@ public class Sneaker { //================ SETTERS ================// - public void setId(int id) { - this.id = id; + public void setSneakerId(int sneakerId) { + this.sneakerId = sneakerId; } public void setName(String name) { @@ -41,8 +41,8 @@ public void setPrice(float price) { //================ GETTERS ================// - public int getId() { - return id; + public int getSneakerId() { + return sneakerId; } public String getName() { diff --git a/src/test/java/models/HatTest.java b/src/test/java/models/HatTest.java index b21936f..2dcc69c 100644 --- a/src/test/java/models/HatTest.java +++ b/src/test/java/models/HatTest.java @@ -1,4 +1,100 @@ package models; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + public class HatTest { + + @Test + public void setHatIdTest() { + //Given + int expected = 503; + + // When + Hat testHat = new Hat(); + testHat.setHatId(expected); + + // Then + Assertions.assertEquals(expected, testHat.getHatId()); + } + + @Test + public void setTypeTest() { + //Given + String expected = "Fitted"; + + // When + Hat testHat = new Hat(); + testHat.setType(expected); + + // Then + Assertions.assertEquals(expected, testHat.getType()); + } + + @Test + public void setSportTest() { + //Given + String expected = "Baseball"; + + // When + Hat testHat = new Hat(); + testHat.setSport(expected); + + // Then + Assertions.assertEquals(expected, testHat.getSport()); + } + + @Test + public void setTeamTest() { + //Given + String expected = "Chicago White Sox"; + + // When + Hat testHat = new Hat(); + testHat.setTeam(expected); + + // Then + Assertions.assertEquals(expected, testHat.getTeam()); + } + + @Test + public void setSizeTest() { + //Given + String expected = "Small"; + + // When + Hat testHat = new Hat(); + testHat.setSize(expected); + + // Then + Assertions.assertEquals(expected, testHat.getSize()); + } + + @Test + public void setQuantityTest() { + //Given + int expected = 20; + + // When + Hat testHat = new Hat(); + testHat.setQuantity(expected); + + // Then + Assertions.assertEquals(expected, testHat.getQuantity()); + } + + @Test + public void setPriceTest() { + //Given + float expected = 39.99F; + + // When + Hat testHat = new Hat(); + testHat.setPrice(expected); + + // Then + Assertions.assertEquals(expected, testHat.getPrice()); + } + + } diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index 4cd4d65..af66238 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -6,16 +6,16 @@ public class SneakerTest { @Test - public void setIdTest() { + public void setSneakerIdTest() { //Given int expected = 7001; // When Sneaker testSneaker = new Sneaker(); - testSneaker.setId(expected); + testSneaker.setSneakerId(expected); // Then - Assertions.assertEquals(expected, testSneaker.getId()); + Assertions.assertEquals(expected, testSneaker.getSneakerId()); } @Test From b8971ca65cb2b832dd978cb7b0655f9dee239760 Mon Sep 17 00:00:00 2001 From: Manny Date: Sun, 4 Jul 2021 23:08:17 -0400 Subject: [PATCH 07/11] added constructorTest to SneakerTest --- src/main/java/models/Hat.java | 1 + src/main/java/models/Sneaker.java | 24 ++++++++++++++++++++++++ src/test/java/models/SneakerTest.java | 25 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/src/main/java/models/Hat.java b/src/main/java/models/Hat.java index 9c365e9..fd0c858 100644 --- a/src/main/java/models/Hat.java +++ b/src/main/java/models/Hat.java @@ -68,4 +68,5 @@ public float getPrice() { return price; } + } diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index d0c2ead..e31f0d0 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -9,6 +9,30 @@ public class Sneaker { private int quantity; private float price; + public Sneaker() { + this.sneakerId = Integer.MAX_VALUE; + this.name = ""; + this.brand = ""; + this.sport = ""; + this.size = Double.MAX_VALUE; + this.quantity = Integer.MAX_VALUE; + this.price = Float.MAX_VALUE; + } + + public Sneaker(int sneakerId, String name, String brand, String sport, double size, int quantity, float price) { + this.sneakerId = sneakerId; + this.name = name; + this.brand = brand; + this.sport = sport; + this.size = size; + this.quantity = quantity; + this.price = price; +} + + public static void main(String[] args) { + + } + //================ SETTERS ================// public void setSneakerId(int sneakerId) { diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index af66238..f2d2608 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -96,5 +96,30 @@ public void setPriceTest() { Assertions.assertEquals(expected, testSneaker.getPrice()); } + @Test + public void constructorTest() { + // Given + int expectedId = 6; + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + String expectedSport = "Tennis"; + double expectedSize = 10.5; + int expectedQuantity = 20; + float expectedPrice = 80.00F; + + // When + Sneaker testSneaker = new Sneaker(expectedId, expectedName, expectedBrand, + expectedSport, expectedSize, expectedQuantity, expectedPrice); + + // Then + Assertions.assertEquals(expectedId, testSneaker.getSneakerId()); + Assertions.assertEquals(expectedName, testSneaker.getName()); + Assertions.assertEquals(expectedBrand, testSneaker.getBrand()); + Assertions.assertEquals(expectedSport, testSneaker.getSport()); + Assertions.assertEquals(expectedSize, testSneaker.getSize()); + Assertions.assertEquals(expectedQuantity, testSneaker.getQuantity()); + Assertions.assertEquals(expectedPrice, testSneaker.getPrice()); + + } } From 72009d7d63716f51611b84b66f01e38caf0a0a18 Mon Sep 17 00:00:00 2001 From: Manny Date: Sun, 4 Jul 2021 23:27:19 -0400 Subject: [PATCH 08/11] added constructorTest for hat --- src/main/java/models/Hat.java | 19 +++++++++++++++++++ src/main/java/models/Sneaker.java | 1 - src/test/java/models/HatTest.java | 26 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/main/java/models/Hat.java b/src/main/java/models/Hat.java index fd0c858..8492538 100644 --- a/src/main/java/models/Hat.java +++ b/src/main/java/models/Hat.java @@ -9,6 +9,25 @@ public class Hat { private int quantity; private float price; + public Hat(){ + this.hatId = Integer.MAX_VALUE; + this.type = ""; + this.sport = ""; + this.team = ""; + this.size = ""; + this.quantity = Integer.MAX_VALUE; + this.price = Float.MAX_VALUE; + } + + public Hat (int hatId, String type, String sport, String team, String size, int quantity, float price) { + this.hatId = hatId; + this.type = type; + this.sport = sport; + this.team = team; + this.size = size; + this.quantity = quantity; + this.price = price; + } //================ SETTERS ================// public void setHatId(int hatId) { diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index e31f0d0..e6a0ad8 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -93,7 +93,6 @@ public float getPrice() { return price; } - } diff --git a/src/test/java/models/HatTest.java b/src/test/java/models/HatTest.java index 2dcc69c..282b117 100644 --- a/src/test/java/models/HatTest.java +++ b/src/test/java/models/HatTest.java @@ -96,5 +96,31 @@ public void setPriceTest() { Assertions.assertEquals(expected, testHat.getPrice()); } + @Test + public void constructorTest() { + // Given + int expectedId = 302; + String expectedType = "Fitted"; + String expectedSport = "Baseball"; + String expectedTeam = "New York Yankees"; + String expectedSize = "Small"; + int expectedQuantity = 20; + float expectedPrice = 40.00F; + + // When + Hat testHat = new Hat(expectedId, expectedType, expectedSport, + expectedTeam, expectedSize, expectedQuantity, expectedPrice); + + // Then + Assertions.assertEquals(expectedId, testHat.getHatId()); + Assertions.assertEquals(expectedType, testHat.getType()); + Assertions.assertEquals(expectedSport, testHat.getSport()); + Assertions.assertEquals(expectedTeam, testHat.getTeam()); + Assertions.assertEquals(expectedSize, testHat.getSize()); + Assertions.assertEquals(expectedQuantity, testHat.getQuantity()); + Assertions.assertEquals(expectedPrice, testHat.getPrice()); + + } + } From 66a8af2d5ef89bbc60c8471bec247ab942d7aa6d Mon Sep 17 00:00:00 2001 From: Manny Date: Tue, 6 Jul 2021 23:58:24 -0400 Subject: [PATCH 09/11] Section 2 finished, on to Section 3 --- src/main/java/models/Sneaker.java | 1 + src/main/java/services/HatService.java | 41 +++++++++++++ src/main/java/services/SneakerService.java | 40 +++++++++++++ src/test/java/models/SneakerTest.java | 2 + src/test/java/services/HatServiceTest.java | 57 ++++++++++++++++++ .../java/services/SneakerServiceTest.java | 58 +++++++++++++++++++ 6 files changed, 199 insertions(+) diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index e6a0ad8..e6132ae 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -29,6 +29,7 @@ public Sneaker(int sneakerId, String name, String brand, String sport, double si this.price = price; } + public static void main(String[] args) { } diff --git a/src/main/java/services/HatService.java b/src/main/java/services/HatService.java index 6b2119f..4e75ce0 100644 --- a/src/main/java/services/HatService.java +++ b/src/main/java/services/HatService.java @@ -1,4 +1,45 @@ package services; +import models.Hat; + +import java.util.ArrayList; + public class HatService { + private static int nextId = 1; + + private static ArrayList inventory = new ArrayList<>(); + + public static Hat create (String type, String sport, String team, String size, int quantity, float price) { + Hat createdHat = new Hat (nextId++, type, sport, team, size, quantity, price); + inventory.add(createdHat); + return createdHat; + } + + // read + public Hat findHat(int hatId) { + for (Hat element : inventory) { + if(element.getHatId() == hatId) { + return element; + } + } + return null; + } + + // read all + public Hat[] findAll() { + + return inventory.toArray(new Hat[0]); + } + + // delete + public boolean delete(int hatId) { + for (Hat element : inventory) { + if (element.getHatId() == hatId) { + inventory.remove(element); + return true; + } + } + return false; + } + } diff --git a/src/main/java/services/SneakerService.java b/src/main/java/services/SneakerService.java index a022353..5cf6885 100644 --- a/src/main/java/services/SneakerService.java +++ b/src/main/java/services/SneakerService.java @@ -1,4 +1,44 @@ package services; +import models.Sneaker; +import java.util.ArrayList; + public class SneakerService { + private static int nextId = 1; + + private static ArrayList inventory = new ArrayList<>(); + + public static Sneaker create(String name, String brand, String sport, double size, int quantity, float price) { + Sneaker createdSneaker = new Sneaker(nextId++, name, brand, sport, size, quantity, price); + inventory.add(createdSneaker); + return createdSneaker; + } + + // read + public Sneaker findSneaker(int sneakerId) { + for (Sneaker element : inventory) { + if (element.getSneakerId() == sneakerId) { + return element; + } + } + return null; + } + + // read all + public Sneaker[] findAll() { + + return inventory.toArray(new Sneaker[0]); + } + + // delete + public boolean delete(int sneakerId) { + for (Sneaker element : inventory) { + if (element.getSneakerId() == sneakerId) { + inventory.remove(element); + return true; + } + } + return false; + } + } diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java index f2d2608..8454734 100644 --- a/src/test/java/models/SneakerTest.java +++ b/src/test/java/models/SneakerTest.java @@ -122,4 +122,6 @@ public void constructorTest() { } + + } diff --git a/src/test/java/services/HatServiceTest.java b/src/test/java/services/HatServiceTest.java index 540baf3..8baee76 100644 --- a/src/test/java/services/HatServiceTest.java +++ b/src/test/java/services/HatServiceTest.java @@ -1,4 +1,61 @@ package services; + +import models.Hat; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + public class HatServiceTest { + @Test + public void createTest() { + // Given + String expectedType = "Fitted"; + String expectedSport = "Baseball"; + String expectedTeam = "New York Yankees"; + String expectedSize = "Small"; + int expectedQuantity = 20; + float expectedPrice = 40.00F; + + // When + HatService hatService = new HatService(); + Hat testHat = HatService.create(expectedType, expectedSport, expectedTeam, + expectedSize, expectedQuantity, expectedPrice); + + int actualId = testHat.getHatId(); + String actualType = testHat.getType(); + String actualSport = testHat.getSport(); + String actualTeam = testHat.getTeam(); + String actualSize = testHat.getSize(); + int actualQuantity = testHat.getQuantity(); + float actualPrice = testHat.getPrice(); + + // Then + Assertions.assertEquals(Integer.class.getName(), new Integer(actualId).getClass().getName()); + Assertions.assertEquals(expectedType, actualType); + Assertions.assertEquals(expectedSport, actualSport); + Assertions.assertEquals(expectedTeam, actualTeam); + Assertions.assertEquals(expectedSize, actualSize); + Assertions.assertEquals(expectedQuantity, actualQuantity); + Assertions.assertEquals(expectedPrice, actualPrice); + } + + @Test + public void findHatTest() { + // Given + String expectedType = "Fitted"; + String expectedSport = "Baseball"; + String expectedTeam = "New York Yankees"; + String expectedSize = "Small"; + int expectedQuantity = 20; + float expectedPrice = 40.00F; + + // When + HatService hatService = new HatService(); + Hat testHat = HatService.create(expectedType, expectedSport, expectedTeam, + expectedSize, expectedQuantity, expectedPrice); + + Hat actual = hatService.findHat(testHat.getHatId()); + + Assertions.assertEquals(testHat, actual); + } } diff --git a/src/test/java/services/SneakerServiceTest.java b/src/test/java/services/SneakerServiceTest.java index 3ae2e9a..3ed9353 100644 --- a/src/test/java/services/SneakerServiceTest.java +++ b/src/test/java/services/SneakerServiceTest.java @@ -1,4 +1,62 @@ package services; +import models.Sneaker; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + public class SneakerServiceTest { + + @Test + public void createTest() { + // Given + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + String expectedSport = "Tennis"; + double expectedSize = 10.5; + int expectedQuantity = 20; + float expectedPrice = 80.00F; + + // When + SneakerService sneakerService = new SneakerService(); + Sneaker testSneaker = SneakerService.create(expectedName, expectedBrand, + expectedSport, expectedSize, expectedQuantity, expectedPrice); + + int actualId = testSneaker.getSneakerId(); + String actualName = testSneaker.getName(); + String actualBrand = testSneaker.getBrand(); + String actualSport = testSneaker.getSport(); + double actualSize = testSneaker.getSize(); + int actualQuantity = testSneaker.getQuantity(); + float actualPrice = testSneaker.getPrice(); + + // Then + 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(expectedQuantity, actualQuantity); + Assertions.assertEquals(expectedPrice, actualPrice); + } + + @Test + public void findSneakerTest() { + // Given + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + String expectedSport = "Tennis"; + double expectedSize = 10.5; + int expectedQuantity = 20; + float expectedPrice = 80.00F; + + // When + SneakerService sneakerService = new SneakerService(); + Sneaker testSneaker = SneakerService.create(expectedName, expectedBrand, + expectedSport, expectedSize, expectedQuantity, expectedPrice); + + Sneaker actual = sneakerService.findSneaker(testSneaker.getSneakerId()); + + Assertions.assertEquals(testSneaker, actual); + + } } From f22a12bb46a498f1ee34bf8b7fb557b012497c75 Mon Sep 17 00:00:00 2001 From: Manny Date: Thu, 8 Jul 2021 00:45:05 -0400 Subject: [PATCH 10/11] Saving progress --- src/main/java/io/App.java | 24 ++++ src/main/java/io/Console.java | 224 ++++++++++++++++++++++++++++++ src/main/java/models/Sneaker.java | 14 +- 3 files changed, 255 insertions(+), 7 deletions(-) create mode 100644 src/main/java/io/App.java create mode 100644 src/main/java/io/Console.java diff --git a/src/main/java/io/App.java b/src/main/java/io/App.java new file mode 100644 index 0000000..b982620 --- /dev/null +++ b/src/main/java/io/App.java @@ -0,0 +1,24 @@ +package io; + +import services.SneakerService; + +public class App { + private SneakerService sneakerService = new SneakerService(); + + public static void main(String... args){ + App application = new App(); + application.init(); + } + + private void init() { + // application logic here + // call methods to take user input and interface with services + + + Console.printWelcome(); + Console.mainMenu(); + } + + + +} diff --git a/src/main/java/io/Console.java b/src/main/java/io/Console.java new file mode 100644 index 0000000..d98f44d --- /dev/null +++ b/src/main/java/io/Console.java @@ -0,0 +1,224 @@ +package io; + +import models.Hat; +import models.Sneaker; +import services.HatService; +import services.SneakerService; + +import java.sql.SQLOutput; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + +public class Console { + + public static class Inventory { + private SneakerService sneakerService = new SneakerService(); + private HatService hatService = new HatService(); + + public SneakerService getSneakerService() { + return this.sneakerService; + } + public HatService getHatService() { + return this.hatService; + } + + } + private static Inventory inventory = new Inventory(); + + public static void sampleInventory() { + SneakerService sneakerService = inventory.getSneakerService(); + HatService hatService = inventory.getHatService(); + + sneakerService.create("Air Jordan 1", "Nike", "Basketball", 10.5, 200, 170.00F); + sneakerService.create("Nite Joggers", "Adidas", "Running", 10.5, 50, 120.00F); + sneakerService.create("Air Force 1", "Nike", "Casual", 10.5, 100, 90.00F); + + hatService.create("Fitted", "Baseball", "New York Yankees", "Medium", 20, 39.99F); + hatService.create("Snap-back", "Basketball", "Los Angeles Lakers", "Large", 20, 44.99F); + hatService.create("Strap-back", "Football", "Philadelphia Eagles", "Medium", 20, 34.99F); + } + + public static void print(String input) { + System.out.println(input); + } + public static void printWelcome() { + System.out.println("" + + "**************************************************\n" + + "*** Welcome and Bienvenue ***\n" + + "*** to ***\n" + + "*** ZipCo Inventory Manager ***\n" + + "**************************************************"); + } + + //==============================================================================================// + // =================================== ~*~ MAIN MENU ~*~ ====================================== // + // =============================================================================================// + public static void mainMenu() { + Scanner scanner = new Scanner(System.in); + Integer input; + print(" ~*~ MAIN MENU ~*~ \n" + + "Please enter a number from the menu options"); + print("1 - Show existing products"); + print("2 - Update products"); + print("3 - Delete products"); + print("Press any other numbers to Quit \n > "); + input = scanner.nextInt(); + + switch(input) { + case 1: + // Show Existing products options + productSelector(); + break; + + case 2: + // Show Update products options + updateSelector(); + break; + + case 3: + // Show Delete products options + deleteSelector(); + break; + + default: + print("Quiting Product Inventory Application ... Goodbye"); + } + } + + + + + + //=============================================================================================// + // ================================ SHOW EXISTING PRODUCTS OPTIONS =========================== // + //=============================================================================================// + private static void productSelector() { + Scanner scanner = new Scanner(System.in); + Integer input; + print("Enter the number corresponding to the product"); + print("1 - Sneakers"); + print("2 - Hats"); + print("~*~ OR ~*~"); + print("3 - Main Menu"); + + input = scanner.nextInt(); + + switch(input) { + case 1: + // Show sneakers inventory information + printSneakersList(inventory.getSneakerService().findAll()); + productSelector(); + break; + case 2: + // Show hats inventory information + printHatsList(inventory.getHatService().findAll()); + productSelector(); + break; + case 3: + // Go back to main menu + mainMenu(); + break; + default: + print("Please enter a valid number ... Try again!"); + productSelector(); + } + + } + + //=================================================================================================// + // ================================ INFO GOES INTO PRODUCT SELECTOR ============================ // + //=================================================================================================// + public static void printSneakersList (Sneaker[] list) { + ArrayList sneakerList = new ArrayList<>(Arrays.asList(list)); + + for (Sneaker element : sneakerList) { + print(element.getName() + element.getBrand() + element.getSport() + element.getSize() + element.getQuantity() + element.getPrice()); + } + } + public static void printHatsList (Hat[] list) { + ArrayList hatList = new ArrayList<>(Arrays.asList(list)); + + for (Hat element : hatList) { + print(element.getType() + element.getSport() + element.getTeam() + element.getSize() + element.getQuantity() + element.getPrice()); + } + } + + //=================================================================================================// + // ================================ SHOW UPDATE PRODUCTS OPTIONS ================================= // + //=================================================================================================// + private static void updateSelector() { + Scanner scanner = new Scanner(System.in); + Integer input; + print("Enter the number corresponding to the product"); + print("1 - Sneakers"); + print("2 - Hats"); + print("~*~ OR ~*~"); + print("3 - Main Menu"); + + input = scanner.nextInt(); + + switch (input) { + case 1: + // Allow user to update sneakers + + break; + case 2: + // Allow user to update hats + break; + case 3: + // Go back to main menu + mainMenu(); + break; + default: + print("Please enter a valid number ... Try again!"); + updateSelector(); + } + } + + + + + + + + + //=================================================================================================// + // ================================ SHOW DELETE PRODUCTS OPTIONS ================================= // + //=================================================================================================// + + private static void deleteSelector() { + Scanner scanner = new Scanner(System.in); + Integer input; + print("Enter the number corresponding to the product"); + print("1 - Sneakers"); + print("2 - Hats"); + print("~*~ OR ~*~"); + print("3 - Main Menu"); + + input = scanner.nextInt(); + + switch (input) { + case 1: + // Allow user to delete sneaker + + break; + case 2: + // Allow user to delete hat + break; + case 3: + // Go back to main menu + mainMenu(); + break; + default: + print("Please enter a valid number ... Try again!"); + updateSelector(); + } + } + + + + + + +} diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java index e6132ae..1be5de4 100644 --- a/src/main/java/models/Sneaker.java +++ b/src/main/java/models/Sneaker.java @@ -10,13 +10,13 @@ public class Sneaker { private float price; public Sneaker() { - this.sneakerId = Integer.MAX_VALUE; - this.name = ""; - this.brand = ""; - this.sport = ""; - this.size = Double.MAX_VALUE; - this.quantity = Integer.MAX_VALUE; - this.price = Float.MAX_VALUE; +// this.sneakerId = Integer.MAX_VALUE; +// this.name = ""; +// this.brand = ""; +// this.sport = ""; +// this.size = Double.MAX_VALUE; +// this.quantity = Integer.MAX_VALUE; +// this.price = Float.MAX_VALUE; } public Sneaker(int sneakerId, String name, String brand, String sport, double size, int quantity, float price) { From f73dbd4ee31e0dc5b5b50fea338acb4665002b87 Mon Sep 17 00:00:00 2001 From: MannyMb Date: Wed, 4 Aug 2021 00:01:43 -0400 Subject: [PATCH 11/11] working --- src/main/java/io/Console.java | 18 +++++++----------- src/main/java/services/HatService.java | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/Console.java b/src/main/java/io/Console.java index d98f44d..6c4da07 100644 --- a/src/main/java/io/Console.java +++ b/src/main/java/io/Console.java @@ -88,8 +88,6 @@ public static void mainMenu() { - - //=============================================================================================// // ================================ SHOW EXISTING PRODUCTS OPTIONS =========================== // //=============================================================================================// @@ -162,9 +160,12 @@ private static void updateSelector() { case 1: // Allow user to update sneakers + updateSelector(); break; case 2: // Allow user to update hats + + updateSelector(); break; case 3: // Go back to main menu @@ -179,10 +180,6 @@ private static void updateSelector() { - - - - //=================================================================================================// // ================================ SHOW DELETE PRODUCTS OPTIONS ================================= // //=================================================================================================// @@ -202,9 +199,12 @@ private static void deleteSelector() { case 1: // Allow user to delete sneaker + deleteSelector(); break; case 2: // Allow user to delete hat + + deleteSelector(); break; case 3: // Go back to main menu @@ -212,13 +212,9 @@ private static void deleteSelector() { break; default: print("Please enter a valid number ... Try again!"); - updateSelector(); + deleteSelector(); } } - - - - } diff --git a/src/main/java/services/HatService.java b/src/main/java/services/HatService.java index 4e75ce0..76e7cb6 100644 --- a/src/main/java/services/HatService.java +++ b/src/main/java/services/HatService.java @@ -41,5 +41,5 @@ public boolean delete(int hatId) { } return false; } - +// add method for updating }