Browse Source

first commit

Leon 6 years ago
parent
commit
32ca3d1182
26 changed files with 1518 additions and 349 deletions
  1. 2
    0
      .idea/compiler.xml
  2. 13
    0
      .idea/libraries/Maven__junit_junit_4_12.xml
  3. 13
    0
      .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
  4. 1
    0
      .idea/modules.xml
  5. 732
    342
      .idea/workspace.xml
  6. 20
    0
      pom.xml
  7. 0
    7
      src/main/java/com/zipcodewilmington/productmanager/Product.java
  8. 58
    0
      src/main/java/com/zipcodewilmington/productmanager/inventory/Inventory.java
  9. 92
    0
      src/main/java/com/zipcodewilmington/productmanager/inventory/InventoryManager.java
  10. 10
    0
      src/main/java/com/zipcodewilmington/productmanager/inventory/products/Butter.java
  11. 10
    0
      src/main/java/com/zipcodewilmington/productmanager/inventory/products/Eggs.java
  12. 10
    0
      src/main/java/com/zipcodewilmington/productmanager/inventory/products/Milk.java
  13. 52
    0
      src/main/java/com/zipcodewilmington/productmanager/inventory/products/Product.java
  14. 44
    0
      src/main/java/com/zipcodewilmington/productmanager/utils/Console.java
  15. 13
    0
      src/main/java/com/zipcodewilmington/productmanager/utils/MockConsole.java
  16. 56
    0
      src/test/java/com/zipcodewilmington/productmanager/ConsoleTest.java
  17. 98
    0
      src/test/java/com/zipcodewilmington/productmanager/ProductTest.java
  18. 24
    0
      src/test/java/com/zipcodewilmington/productmanager/inventory/AddTest.java
  19. 54
    0
      src/test/java/com/zipcodewilmington/productmanager/inventory/ConstructorTest.java
  20. 25
    0
      src/test/java/com/zipcodewilmington/productmanager/inventory/FindByIdTest.java
  21. 29
    0
      src/test/java/com/zipcodewilmington/productmanager/inventory/GetQuantity.java
  22. 30
    0
      src/test/java/com/zipcodewilmington/productmanager/inventory/GetTotalValueTest.java
  23. 25
    0
      src/test/java/com/zipcodewilmington/productmanager/inventory/RemoveTest.java
  24. 30
    0
      src/test/java/com/zipcodewilmington/productmanager/inventorymanager/AddTest.java
  25. 47
    0
      src/test/java/com/zipcodewilmington/productmanager/inventorymanager/ConstructorTest.java
  26. 30
    0
      src/test/java/com/zipcodewilmington/productmanager/inventorymanager/RemoveTest.java

+ 2
- 0
.idea/compiler.xml View File

@@ -7,10 +7,12 @@
7 7
         <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8 8
         <outputRelativeToContentRoot value="true" />
9 9
         <module name="bankaccountlab" />
10
+        <module name="productmanager" />
10 11
       </profile>
11 12
     </annotationProcessing>
12 13
     <bytecodeTargetLevel target="1.8">
13 14
       <module name="bankaccountlab" target="1.5" />
15
+      <module name="productmanager" target="8" />
14 16
     </bytecodeTargetLevel>
15 17
   </component>
16 18
 </project>

+ 13
- 0
.idea/libraries/Maven__junit_junit_4_12.xml View File

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: junit:junit:4.12">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 13
- 0
.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml View File

@@ -0,0 +1,13 @@
1
+<component name="libraryTable">
2
+  <library name="Maven: org.hamcrest:hamcrest-core:1.3">
3
+    <CLASSES>
4
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
5
+    </CLASSES>
6
+    <JAVADOC>
7
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
8
+    </JAVADOC>
9
+    <SOURCES>
10
+      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
11
+    </SOURCES>
12
+  </library>
13
+</component>

+ 1
- 0
.idea/modules.xml View File

@@ -3,6 +3,7 @@
3 3
   <component name="ProjectModuleManager">
4 4
     <modules>
5 5
       <module fileurl="file://$PROJECT_DIR$/bankaccountlab.iml" filepath="$PROJECT_DIR$/bankaccountlab.iml" />
6
+      <module fileurl="file://$PROJECT_DIR$/productmanager.iml" filepath="$PROJECT_DIR$/productmanager.iml" />
6 7
     </modules>
7 8
   </component>
8 9
 </project>

+ 732
- 342
.idea/workspace.xml
File diff suppressed because it is too large
View File


+ 20
- 0
pom.xml View File

@@ -7,6 +7,26 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>productmanager</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>junit</groupId>
25
+            <artifactId>junit</artifactId>
26
+            <version>4.12</version>
27
+            <scope>test</scope>
28
+        </dependency>
29
+    </dependencies>
10 30
 
11 31
 
12 32
 </project>

+ 0
- 7
src/main/java/com/zipcodewilmington/productmanager/Product.java View File

@@ -1,7 +0,0 @@
1
-package com.zipcodewilmington.productmanager;
2
-
3
-/**
4
- * Created by leon on 1/10/18.
5
- */
6
-public class Product {
7
-}

+ 58
- 0
src/main/java/com/zipcodewilmington/productmanager/inventory/Inventory.java View File

@@ -0,0 +1,58 @@
1
+package com.zipcodewilmington.productmanager.inventory;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.products.Product;
4
+
5
+import java.util.List;
6
+
7
+/**
8
+ * @author leon on 15/11/2018.
9
+ */
10
+public class Inventory {
11
+    private List<Product> productList;
12
+
13
+    public Inventory(List<Product> productList) {
14
+
15
+    }
16
+
17
+    public Inventory() {
18
+
19
+    }
20
+
21
+    public void add(Product product) {
22
+
23
+    }
24
+
25
+    public List<Product> getProductList() {
26
+        return null;
27
+    }
28
+
29
+    public Boolean contains(Product product) {
30
+        return null;
31
+    }
32
+
33
+    public Product findById(Long id) {
34
+        return null;
35
+    }
36
+
37
+    public Integer getTotalQuantity() {
38
+        return null;
39
+    }
40
+
41
+    public Double getTotalValue() {
42
+        return null;
43
+    }
44
+
45
+    public void remove(Product product) {
46
+    }
47
+
48
+    public void removeById(Long id) {
49
+
50
+    }
51
+
52
+    @Override
53
+    public String toString() {
54
+        return "Inventory{" +
55
+                "productList=" + productList +
56
+                '}';
57
+    }
58
+}

+ 92
- 0
src/main/java/com/zipcodewilmington/productmanager/inventory/InventoryManager.java View File

@@ -0,0 +1,92 @@
1
+package com.zipcodewilmington.productmanager.inventory;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.products.Product;
4
+import com.zipcodewilmington.productmanager.utils.Console;
5
+
6
+/**
7
+ * @author leon on 15/11/2018.
8
+ */
9
+public class InventoryManager {
10
+    private Inventory inventory;
11
+    private Console console;
12
+
13
+    public InventoryManager() {
14
+        this(new Inventory(), new Console());
15
+    }
16
+
17
+    public InventoryManager(Inventory inventory, Console console) {
18
+        this.inventory = inventory;
19
+        this.console = console;
20
+    }
21
+
22
+    public void welcome() {
23
+        String userInput = console.getStringInput(new StringBuilder()
24
+                .append("Welcome to the inventory manager!")
25
+                .append("\nFrom here you can select any of the following options:")
26
+                .append("\n\t[ add ] a product to the inventory")
27
+                .append("\n\t[ remove ] a product from the inventory")
28
+                .append("\n\t[ view inventory ] the inventory")
29
+                .append("\n\t[ view product ] in the inventory")
30
+                .toString());
31
+
32
+        switch (userInput.toLowerCase()) {
33
+            case "add":
34
+                add();
35
+                break;
36
+
37
+            case "remove":
38
+                remove();
39
+                break;
40
+
41
+            case "view inventory":
42
+                viewInventory();
43
+                break;
44
+
45
+            case "view product":
46
+                viewProduct();
47
+                break;
48
+        }
49
+    }
50
+
51
+    public void add() {
52
+        console.println("Adding an item to the inventory");
53
+        Long id = console.getLongInput("What is the id of the item?");
54
+        Double price = console.getDoubleInput("What is the price of the item?");
55
+        Integer quantity = console.getIntegerInput("What is the quantity of the item?");
56
+        inventory.add(new Product(id, price, quantity));
57
+    }
58
+
59
+
60
+    public void remove() {
61
+        Long id = console.getLongInput("What is the id of the item?");
62
+        inventory.removeById(id);
63
+        console.println("Item removed.");
64
+    }
65
+
66
+    public void viewProduct() {
67
+        Long id = console.getLongInput("What is the id of the item?");
68
+        console.println("Item found.");
69
+        console.println("Displaying details.");
70
+        console.println(inventory.findById(id).toString());
71
+    }
72
+
73
+    public void viewInventory() {
74
+        console.println(inventory.toString());
75
+    }
76
+
77
+    public Inventory getInventory() {
78
+        return inventory;
79
+    }
80
+
81
+    public void setInventory(Inventory inventory) {
82
+        this.inventory = inventory;
83
+    }
84
+
85
+    public Console getConsole() {
86
+        return console;
87
+    }
88
+
89
+    public void setConsole(Console console) {
90
+        this.console = console;
91
+    }
92
+}

+ 10
- 0
src/main/java/com/zipcodewilmington/productmanager/inventory/products/Butter.java View File

@@ -0,0 +1,10 @@
1
+package com.zipcodewilmington.productmanager.inventory.products;
2
+
3
+/**
4
+ * @author leon on 15/11/2018.
5
+ */
6
+public class Butter extends Product {
7
+    public Butter(Long id, Integer quantity) {
8
+        super(id, 1.5, quantity);
9
+    }
10
+}

+ 10
- 0
src/main/java/com/zipcodewilmington/productmanager/inventory/products/Eggs.java View File

@@ -0,0 +1,10 @@
1
+package com.zipcodewilmington.productmanager.inventory.products;
2
+
3
+/**
4
+ * @author leon on 15/11/2018.
5
+ */
6
+public class Eggs extends Product {
7
+    public Eggs(Long id, Integer quantity) {
8
+        super(id, 2.25, quantity);
9
+    }
10
+}

+ 10
- 0
src/main/java/com/zipcodewilmington/productmanager/inventory/products/Milk.java View File

@@ -0,0 +1,10 @@
1
+package com.zipcodewilmington.productmanager.inventory.products;
2
+
3
+/**
4
+ * @author leon on 15/11/2018.
5
+ */
6
+public class Milk extends Product {
7
+    public Milk(Long id, Integer quantity) {
8
+        super(id, 2.5, quantity);
9
+    }
10
+}

+ 52
- 0
src/main/java/com/zipcodewilmington/productmanager/inventory/products/Product.java View File

@@ -0,0 +1,52 @@
1
+package com.zipcodewilmington.productmanager.inventory.products;
2
+
3
+/**
4
+ * Created by leon on 1/10/18.
5
+ */
6
+public class Product {
7
+    private Long id;
8
+    private Double price;
9
+    private Integer quantity;
10
+
11
+    public Product() {
12
+    }
13
+
14
+    public Product(Long id, Double price, Integer quantity) {
15
+        this.id = id;
16
+        this.price = price;
17
+        this.quantity = quantity;
18
+    }
19
+
20
+    public Long getId() {
21
+        return id;
22
+    }
23
+
24
+    public void setId(Long id) {
25
+        this.id = id;
26
+    }
27
+
28
+    public Double getPrice() {
29
+        return price;
30
+    }
31
+
32
+    public void setPrice(Double price) {
33
+        this.price = price;
34
+    }
35
+
36
+    public Integer getQuantity() {
37
+        return quantity;
38
+    }
39
+
40
+    public void setQuantity(Integer quantity) {
41
+        this.quantity = quantity;
42
+    }
43
+
44
+    @Override
45
+    public String toString() {
46
+        return "Product{" +
47
+                "id=" + id +
48
+                ", price=" + price +
49
+                ", quantity=" + quantity +
50
+                '}';
51
+    }
52
+}

+ 44
- 0
src/main/java/com/zipcodewilmington/productmanager/utils/Console.java View File

@@ -0,0 +1,44 @@
1
+package com.zipcodewilmington.productmanager.utils;
2
+
3
+import java.io.InputStream;
4
+import java.io.PrintStream;
5
+import java.util.Scanner;
6
+
7
+/**
8
+ * @author leon on 15/11/2018.
9
+ */
10
+public class Console {
11
+    private final Scanner scanner;
12
+    private final PrintStream printStream;
13
+
14
+    public Console() {
15
+        this(System.in, System.out);
16
+    }
17
+
18
+    public Console(InputStream inputStream, PrintStream printStream) {
19
+        this.scanner = new Scanner(inputStream);
20
+        this.printStream = printStream;
21
+    }
22
+
23
+    public void println(String prompt) {
24
+        printStream.println(prompt);
25
+    }
26
+
27
+    public String getStringInput(String prompt) {
28
+        println(prompt);
29
+        String userInput = scanner.nextLine();
30
+        return userInput;
31
+    }
32
+
33
+    public Double getDoubleInput(String prompt) {
34
+        return Double.parseDouble(getStringInput(prompt));
35
+    }
36
+
37
+    public Long getLongInput(String prompt) {
38
+        return getDoubleInput(prompt).longValue();
39
+    }
40
+
41
+    public Integer getIntegerInput(String prompt) {
42
+        return getLongInput(prompt).intValue();
43
+    }
44
+}

+ 13
- 0
src/main/java/com/zipcodewilmington/productmanager/utils/MockConsole.java View File

@@ -0,0 +1,13 @@
1
+package com.zipcodewilmington.productmanager.utils;
2
+
3
+import java.io.ByteArrayInputStream;
4
+import java.io.PrintStream;
5
+
6
+/**
7
+ * @author leon on 15/11/2018.
8
+ */
9
+public class MockConsole extends Console {
10
+    public MockConsole(String input, PrintStream printStream) {
11
+        super(new ByteArrayInputStream(input.getBytes()), printStream);
12
+    }
13
+}

+ 56
- 0
src/test/java/com/zipcodewilmington/productmanager/ConsoleTest.java View File

@@ -0,0 +1,56 @@
1
+package com.zipcodewilmington.productmanager;
2
+
3
+import com.zipcodewilmington.productmanager.utils.Console;
4
+import com.zipcodewilmington.productmanager.utils.MockConsole;
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * @author leon on 15/11/2018.
10
+ */
11
+public class ConsoleTest {
12
+    @Test
13
+    public void testGetStringInput() {
14
+        // given
15
+        String prompt = "Let's test .getStringInput()";
16
+        String expected = "This is my user input";
17
+        Console console = new MockConsole(expected, System.out);
18
+
19
+        // when
20
+        String actual = console.getStringInput(prompt);
21
+
22
+        // then
23
+        Assert.assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void testGetDoubleInput() {
28
+        // given
29
+        String prompt = "Let's test .getDoubleInput()";
30
+        String userInput = "25.986";
31
+        Double expected = Double.parseDouble(userInput);
32
+        Console console = new MockConsole(userInput, System.out);
33
+
34
+        // when
35
+        Double actual = console.getDoubleInput(prompt);
36
+
37
+        // then
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+
42
+    @Test
43
+    public void testGetIntegerInput() {
44
+        // given
45
+        String prompt = "Let's test .getIntegerInput()";
46
+        String userInput = "25";
47
+        Integer expected = Integer.parseInt(userInput);
48
+        Console console = new MockConsole(userInput, System.out);
49
+
50
+        // when
51
+        Double actual = console.getDoubleInput(prompt);
52
+
53
+        // then
54
+        Assert.assertEquals(expected, actual);
55
+    }
56
+}

+ 98
- 0
src/test/java/com/zipcodewilmington/productmanager/ProductTest.java View File

@@ -1,7 +1,105 @@
1 1
 package com.zipcodewilmington.productmanager;
2 2
 
3
+import com.zipcodewilmington.productmanager.inventory.products.Product;
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
3 7
 /**
4 8
  * Created by leon on 1/10/18.
5 9
  */
6 10
 public class ProductTest {
11
+    @Test
12
+    public void testConstruction() {
13
+        // given
14
+        Long expectedId = 0L;
15
+        Double expectedPrice = 2.5;
16
+        Integer expectedQuantity = 5;
17
+
18
+        // when
19
+        Product product = new Product(expectedId, expectedPrice, expectedQuantity);
20
+
21
+        // then
22
+        Assert.assertEquals(expectedId, product.getId());
23
+        Assert.assertEquals(expectedPrice, product.getPrice());
24
+        Assert.assertEquals(expectedQuantity, product.getQuantity());
25
+    }
26
+
27
+    @Test
28
+    public void testNullaryConstruction() {
29
+        // given
30
+        // when
31
+        Product product = new Product();
32
+
33
+        // Then
34
+        Assert.assertNull(product.getId());
35
+        Assert.assertNull(product.getPrice());
36
+        Assert.assertNull(product.getQuantity());
37
+    }
38
+
39
+    @Test
40
+    public void testSetId() {
41
+        // Given
42
+        Long expected = 0L;
43
+        Product product = new Product();
44
+
45
+        // when
46
+        product.setId(expected);
47
+
48
+        // then
49
+        Assert.assertEquals(expected, product.getId());
50
+    }
51
+
52
+    @Test
53
+    public void testSetPrice() {
54
+        // Given
55
+        Double expected = 10.5;
56
+        Product product = new Product();
57
+
58
+        // when
59
+        product.setPrice(expected);
60
+
61
+        // then
62
+        Assert.assertEquals(expected, product.getPrice());
63
+    }
64
+
65
+    @Test
66
+    public void testSetQuantity() {
67
+        // given
68
+        Integer expected = 15;
69
+        Product product = new Product();
70
+
71
+        // when
72
+        product.setQuantity(expected);
73
+
74
+        // then
75
+        Assert.assertEquals(expected, product.getQuantity());
76
+    }
77
+
78
+    @Test
79
+    public void testToString1() {
80
+        // given
81
+        Long expectedId = 0L;
82
+        Double expectedPrice = 2.5;
83
+        Integer expectedQuantity = 5;
84
+
85
+        // when
86
+        Product product = new Product(expectedId, expectedPrice, expectedQuantity);
87
+
88
+        // then
89
+        Assert.assertEquals(product.toString(), "Product{id=0, price=2.5, quantity=5}");
90
+    }
91
+
92
+    @Test
93
+    public void testToString2() {
94
+        // given
95
+        Long expectedId = 0L;
96
+        Double expectedPrice = 7.5;
97
+        Integer expectedQuantity = 5;
98
+
99
+        // when
100
+        Product product = new Product(expectedId, expectedPrice, expectedQuantity);
101
+
102
+        // then
103
+        Assert.assertEquals(product.toString(), "Product{id=0, price=7.5, quantity=5}");
104
+    }
7 105
 }

+ 24
- 0
src/test/java/com/zipcodewilmington/productmanager/inventory/AddTest.java View File

@@ -0,0 +1,24 @@
1
+package com.zipcodewilmington.productmanager.inventory;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.products.Product;
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * @author leon on 15/11/2018.
10
+ */
11
+public class AddTest {
12
+    @Test
13
+    public void addProductTest(){
14
+        // given
15
+        Inventory inventory = new Inventory();
16
+        Product product = new Product();
17
+
18
+        // when
19
+        inventory.add(product);
20
+
21
+        // then
22
+        Assert.assertTrue(inventory.contains(product));
23
+    }
24
+}

+ 54
- 0
src/test/java/com/zipcodewilmington/productmanager/inventory/ConstructorTest.java View File

@@ -0,0 +1,54 @@
1
+package com.zipcodewilmington.productmanager.inventory;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.products.Product;
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
8
+import java.util.ArrayList;
9
+import java.util.LinkedList;
10
+import java.util.List;
11
+
12
+/**
13
+ * @author leon on 15/11/2018.
14
+ */
15
+public class ConstructorTest {
16
+    @Test
17
+    public void testConstructionWithArrayList() {
18
+        // given
19
+        List<Product> expected = new ArrayList<Product>();
20
+        Inventory inventory = new Inventory(expected);
21
+
22
+        // when
23
+        List<Product> actual= inventory.getProductList();
24
+
25
+        // then
26
+        Assert.assertEquals(expected, actual);
27
+    }
28
+
29
+    @Test
30
+    public void testConstructionWithLinkedList() {
31
+        // given
32
+        List<Product> expected = new LinkedList<Product>();
33
+        Inventory inventory = new Inventory(expected);
34
+
35
+        // when
36
+        List<Product> actual= inventory.getProductList();
37
+
38
+        // then
39
+        Assert.assertEquals(expected, actual);
40
+    }
41
+
42
+
43
+    @Test
44
+    public void testNullaryConstruction() {
45
+        // given
46
+        Inventory inventory = new Inventory();
47
+
48
+        // when
49
+        List<Product> actual= inventory.getProductList();
50
+
51
+        // then
52
+        Assert.assertNotNull(actual);
53
+    }
54
+}

+ 25
- 0
src/test/java/com/zipcodewilmington/productmanager/inventory/FindByIdTest.java View File

@@ -0,0 +1,25 @@
1
+package com.zipcodewilmington.productmanager.inventory;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.products.Product;
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * @author leon on 15/11/2018.
10
+ */
11
+public class FindByIdTest {
12
+    @Test
13
+    public void findByIdTest() {
14
+        //given
15
+        Inventory inventory = new Inventory();
16
+        Product expected = new Product();
17
+        inventory.add(expected);
18
+
19
+        // when
20
+        Product acutal = inventory.findById(expected.getId());
21
+
22
+        // then
23
+        Assert.assertEquals(expected, acutal);
24
+    }
25
+}

+ 29
- 0
src/test/java/com/zipcodewilmington/productmanager/inventory/GetQuantity.java View File

@@ -0,0 +1,29 @@
1
+package com.zipcodewilmington.productmanager.inventory;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.products.Product;
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * @author leon on 15/11/2018.
10
+ */
11
+public class GetQuantity {
12
+    @Test
13
+    public void getTotalQuantity() {
14
+        // given
15
+        Inventory inventory = new Inventory();
16
+        Product product = new Product();
17
+        product.setQuantity(15);
18
+        Integer expected = 0;
19
+        for(Product p : inventory.getProductList()) {
20
+            expected += p.getQuantity();
21
+        }
22
+
23
+        // when
24
+        Integer actual = inventory.getTotalQuantity();
25
+
26
+        // then
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+}

+ 30
- 0
src/test/java/com/zipcodewilmington/productmanager/inventory/GetTotalValueTest.java View File

@@ -0,0 +1,30 @@
1
+package com.zipcodewilmington.productmanager.inventory;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.products.Product;
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * @author leon on 15/11/2018.
10
+ */
11
+public class GetTotalValueTest {
12
+    @Test
13
+    public void getTotalValue() {
14
+        // given
15
+        Inventory inventory = new Inventory();
16
+        Product product = new Product();
17
+        product.setPrice(10.0);
18
+        product.setQuantity(15);
19
+        Double expected = 0.0;
20
+        for(Product p : inventory.getProductList()) {
21
+            expected += p.getPrice() * p.getQuantity();
22
+        }
23
+
24
+        // when
25
+        Double actual = inventory.getTotalValue();
26
+
27
+        // then
28
+        Assert.assertEquals(expected, actual);
29
+    }
30
+}

+ 25
- 0
src/test/java/com/zipcodewilmington/productmanager/inventory/RemoveTest.java View File

@@ -0,0 +1,25 @@
1
+package com.zipcodewilmington.productmanager.inventory;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.products.Product;
5
+import org.junit.Assert;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * @author leon on 15/11/2018.
10
+ */
11
+public class RemoveTest {
12
+    @Test
13
+    public void removeTest() {
14
+        // given
15
+        Inventory inventory = new Inventory();
16
+        Product product = new Product();
17
+        inventory.add(product);
18
+
19
+        // when
20
+        inventory.remove(product);
21
+
22
+        // then
23
+        Assert.assertFalse(inventory.contains(product));
24
+    }
25
+}

+ 30
- 0
src/test/java/com/zipcodewilmington/productmanager/inventorymanager/AddTest.java View File

@@ -0,0 +1,30 @@
1
+package com.zipcodewilmington.productmanager.inventorymanager;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.InventoryManager;
5
+import com.zipcodewilmington.productmanager.utils.Console;
6
+import com.zipcodewilmington.productmanager.utils.MockConsole;
7
+import org.junit.Assert;
8
+import org.junit.Test;
9
+
10
+/**
11
+ * @author leon on 15/11/2018.
12
+ */
13
+public class AddTest {
14
+    @Test
15
+    public void addTest() {
16
+        // given
17
+        Long id = 1L;
18
+        Double price = 2.5;
19
+        Integer quantity = 10;
20
+        String userInput = id + "\n" + price + "\n" + quantity + "\n";
21
+        Console console = new MockConsole(userInput, System.out);
22
+        InventoryManager inventoryManager = new InventoryManager(new Inventory(), console);
23
+
24
+        // when
25
+        inventoryManager.add();
26
+
27
+        // then
28
+        Assert.assertNotNull(inventoryManager.getInventory().findById(id));
29
+    }
30
+}

+ 47
- 0
src/test/java/com/zipcodewilmington/productmanager/inventorymanager/ConstructorTest.java View File

@@ -0,0 +1,47 @@
1
+package com.zipcodewilmington.productmanager.inventorymanager;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.InventoryManager;
5
+import com.zipcodewilmington.productmanager.utils.Console;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+/**
10
+ * @author leon on 15/11/2018.
11
+ */
12
+public class ConstructorTest {
13
+    @Test
14
+    public void constructionWithInventoryTest() {
15
+        // given
16
+        Inventory inventory = new Inventory();
17
+
18
+        // when
19
+        InventoryManager inventoryManager = new InventoryManager(inventory, null);
20
+
21
+        // then
22
+        Assert.assertEquals(inventory, inventoryManager.getInventory());
23
+    }
24
+
25
+    @Test
26
+    public void constructionWithConsoleTest() {
27
+        // given
28
+        Console console = new Console();
29
+
30
+        // when
31
+        InventoryManager inventoryManager = new InventoryManager(null, console);
32
+
33
+        // then
34
+        Assert.assertEquals(console, inventoryManager.getConsole());
35
+    }
36
+
37
+    @Test
38
+    public void nullaryConstructionTest() {
39
+        // given
40
+        // when
41
+        InventoryManager inventoryManager = new InventoryManager();
42
+
43
+        // then
44
+        Assert.assertNotNull(inventoryManager.getInventory());
45
+        Assert.assertNotNull(inventoryManager.getConsole());
46
+    }
47
+}

+ 30
- 0
src/test/java/com/zipcodewilmington/productmanager/inventorymanager/RemoveTest.java View File

@@ -0,0 +1,30 @@
1
+package com.zipcodewilmington.productmanager.inventorymanager;
2
+
3
+import com.zipcodewilmington.productmanager.inventory.Inventory;
4
+import com.zipcodewilmington.productmanager.inventory.InventoryManager;
5
+import com.zipcodewilmington.productmanager.inventory.products.Product;
6
+import com.zipcodewilmington.productmanager.utils.Console;
7
+import com.zipcodewilmington.productmanager.utils.MockConsole;
8
+import org.junit.Assert;
9
+import org.junit.Test;
10
+
11
+/**
12
+ * @author leon on 15/11/2018.
13
+ */
14
+public class RemoveTest {
15
+    @Test
16
+    public void addTest() {
17
+        // given
18
+        Long productId = 0L;
19
+        Inventory inventory = new Inventory();
20
+        inventory.add(new Product(productId, null, null));
21
+        Console console = new MockConsole(productId.toString(), System.out);
22
+        InventoryManager inventoryManager = new InventoryManager(new Inventory(), console);
23
+
24
+        // when
25
+        inventoryManager.remove();
26
+
27
+        // then
28
+        Assert.assertNull(inventoryManager.getInventory().findById(productId));
29
+    }
30
+}