#36 ProductManager zmalone

開啟中
zmalone 請求將 1 次程式碼提交從 zmalone/CR-MesoLabs-Inheritance-ProductManager:master 合併至 master

+ 1
- 0
.idea/.name 查看文件

@@ -0,0 +1 @@
1
+productmanager

+ 2
- 4
.idea/compiler.xml 查看文件

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

+ 2
- 115
.idea/misc.xml 查看文件

@@ -1,128 +1,15 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3
-  <component name="ClientPropertiesManager">
4
-    <properties class="javax.swing.AbstractButton">
5
-      <property name="hideActionText" class="java.lang.Boolean" />
6
-    </properties>
7
-    <properties class="javax.swing.JComponent">
8
-      <property name="html.disable" class="java.lang.Boolean" />
9
-    </properties>
10
-    <properties class="javax.swing.JEditorPane">
11
-      <property name="JEditorPane.w3cLengthUnits" class="java.lang.Boolean" />
12
-      <property name="JEditorPane.honorDisplayProperties" class="java.lang.Boolean" />
13
-      <property name="charset" class="java.lang.String" />
14
-    </properties>
15
-    <properties class="javax.swing.JList">
16
-      <property name="List.isFileList" class="java.lang.Boolean" />
17
-    </properties>
18
-    <properties class="javax.swing.JPasswordField">
19
-      <property name="JPasswordField.cutCopyAllowed" class="java.lang.Boolean" />
20
-    </properties>
21
-    <properties class="javax.swing.JSlider">
22
-      <property name="Slider.paintThumbArrowShape" class="java.lang.Boolean" />
23
-      <property name="JSlider.isFilled" class="java.lang.Boolean" />
24
-    </properties>
25
-    <properties class="javax.swing.JTable">
26
-      <property name="Table.isFileList" class="java.lang.Boolean" />
27
-      <property name="JTable.autoStartsEdit" class="java.lang.Boolean" />
28
-      <property name="terminateEditOnFocusLost" class="java.lang.Boolean" />
29
-    </properties>
30
-    <properties class="javax.swing.JToolBar">
31
-      <property name="JToolBar.isRollover" class="java.lang.Boolean" />
32
-    </properties>
33
-    <properties class="javax.swing.JTree">
34
-      <property name="JTree.lineStyle" class="java.lang.String" />
35
-    </properties>
36
-    <properties class="javax.swing.text.JTextComponent">
37
-      <property name="caretAspectRatio" class="java.lang.Double" />
38
-      <property name="caretWidth" class="java.lang.Integer" />
39
-    </properties>
40
-  </component>
3
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
41 4
   <component name="MavenProjectsManager">
42 5
     <option name="originalFiles">
43 6
       <list>
44 7
         <option value="$PROJECT_DIR$/pom.xml" />
8
+        <option value="$PROJECT_DIR$/MaloneZavon/pom.xml" />
45 9
       </list>
46 10
     </option>
47 11
   </component>
48
-  <component name="ProjectInspectionProfilesVisibleTreeState">
49
-    <entry key="Project Default">
50
-      <profile-state>
51
-        <expanded-state>
52
-          <State>
53
-            <id />
54
-          </State>
55
-        </expanded-state>
56
-        <selected-state>
57
-          <State>
58
-            <id>Android</id>
59
-          </State>
60
-        </selected-state>
61
-      </profile-state>
62
-    </entry>
63
-  </component>
64 12
   <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
65 13
     <output url="file://$PROJECT_DIR$/out" />
66 14
   </component>
67
-  <component name="masterDetails">
68
-    <states>
69
-      <state key="GlobalLibrariesConfigurable.UI">
70
-        <settings>
71
-          <splitter-proportions>
72
-            <option name="proportions">
73
-              <list>
74
-                <option value="0.2" />
75
-              </list>
76
-            </option>
77
-          </splitter-proportions>
78
-        </settings>
79
-      </state>
80
-      <state key="JdkListConfigurable.UI">
81
-        <settings>
82
-          <last-edited>1.8</last-edited>
83
-          <splitter-proportions>
84
-            <option name="proportions">
85
-              <list>
86
-                <option value="0.2" />
87
-              </list>
88
-            </option>
89
-          </splitter-proportions>
90
-        </settings>
91
-      </state>
92
-      <state key="ProjectJDKs.UI">
93
-        <settings>
94
-          <last-edited>1.8</last-edited>
95
-          <splitter-proportions>
96
-            <option name="proportions">
97
-              <list>
98
-                <option value="0.2" />
99
-              </list>
100
-            </option>
101
-          </splitter-proportions>
102
-        </settings>
103
-      </state>
104
-      <state key="ProjectLibrariesConfigurable.UI">
105
-        <settings>
106
-          <splitter-proportions>
107
-            <option name="proportions">
108
-              <list>
109
-                <option value="0.2" />
110
-              </list>
111
-            </option>
112
-          </splitter-proportions>
113
-        </settings>
114
-      </state>
115
-      <state key="ScopeChooserConfigurable.UI">
116
-        <settings>
117
-          <splitter-proportions>
118
-            <option name="proportions">
119
-              <list>
120
-                <option value="0.2" />
121
-              </list>
122
-            </option>
123
-          </splitter-proportions>
124
-        </settings>
125
-      </state>
126
-    </states>
127
-  </component>
128 15
 </project>

+ 0
- 8
.idea/modules.xml 查看文件

@@ -1,8 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<project version="4">
3
-  <component name="ProjectModuleManager">
4
-    <modules>
5
-      <module fileurl="file://$PROJECT_DIR$/bankaccountlab.iml" filepath="$PROJECT_DIR$/bankaccountlab.iml" />
6
-    </modules>
7
-  </component>
8
-</project>

+ 0
- 124
.idea/uiDesigner.xml 查看文件

@@ -1,124 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<project version="4">
3
-  <component name="Palette2">
4
-    <group name="Swing">
5
-      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
6
-        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
7
-      </item>
8
-      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
9
-        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
10
-      </item>
11
-      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
12
-        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
13
-      </item>
14
-      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
15
-        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
16
-      </item>
17
-      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
18
-        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
19
-        <initial-values>
20
-          <property name="text" value="Button" />
21
-        </initial-values>
22
-      </item>
23
-      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
24
-        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
25
-        <initial-values>
26
-          <property name="text" value="RadioButton" />
27
-        </initial-values>
28
-      </item>
29
-      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
30
-        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
31
-        <initial-values>
32
-          <property name="text" value="CheckBox" />
33
-        </initial-values>
34
-      </item>
35
-      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
36
-        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
37
-        <initial-values>
38
-          <property name="text" value="Label" />
39
-        </initial-values>
40
-      </item>
41
-      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
42
-        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
43
-          <preferred-size width="150" height="-1" />
44
-        </default-constraints>
45
-      </item>
46
-      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
47
-        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
48
-          <preferred-size width="150" height="-1" />
49
-        </default-constraints>
50
-      </item>
51
-      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
52
-        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
53
-          <preferred-size width="150" height="-1" />
54
-        </default-constraints>
55
-      </item>
56
-      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
57
-        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
58
-          <preferred-size width="150" height="50" />
59
-        </default-constraints>
60
-      </item>
61
-      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
62
-        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
63
-          <preferred-size width="150" height="50" />
64
-        </default-constraints>
65
-      </item>
66
-      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
67
-        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
68
-          <preferred-size width="150" height="50" />
69
-        </default-constraints>
70
-      </item>
71
-      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
72
-        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
73
-      </item>
74
-      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
75
-        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
76
-          <preferred-size width="150" height="50" />
77
-        </default-constraints>
78
-      </item>
79
-      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
80
-        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
81
-          <preferred-size width="150" height="50" />
82
-        </default-constraints>
83
-      </item>
84
-      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
85
-        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
86
-          <preferred-size width="150" height="50" />
87
-        </default-constraints>
88
-      </item>
89
-      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
90
-        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
91
-          <preferred-size width="200" height="200" />
92
-        </default-constraints>
93
-      </item>
94
-      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
95
-        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
96
-          <preferred-size width="200" height="200" />
97
-        </default-constraints>
98
-      </item>
99
-      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
100
-        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
101
-      </item>
102
-      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
103
-        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
104
-      </item>
105
-      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
106
-        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
107
-      </item>
108
-      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
109
-        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
110
-      </item>
111
-      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
112
-        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
113
-          <preferred-size width="-1" height="20" />
114
-        </default-constraints>
115
-      </item>
116
-      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
117
-        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
118
-      </item>
119
-      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
120
-        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
121
-      </item>
122
-    </group>
123
-  </component>
124
-</project>

+ 513
- 439
.idea/workspace.xml
文件差異過大導致無法顯示
查看文件


+ 12
- 0
MaloneZavon/pom.xml 查看文件

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>Malone.Zavon</groupId>
8
+    <artifactId>Malone.Zavon</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+
11
+
12
+</project>

+ 11
- 0
pom.xml 查看文件

@@ -7,6 +7,17 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>productmanager</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <!-- https://mvnrepository.com/artifact/junit/junit -->
12
+        <dependency>
13
+            <groupId>junit</groupId>
14
+            <artifactId>junit</artifactId>
15
+            <version>4.12</version>
16
+            <scope>test</scope>
17
+        </dependency>
18
+    </dependencies>
19
+
20
+
10 21
 
11 22
 
12 23
 </project>

+ 63
- 0
src/main/java/com/zipcodewilmington/productmanager/Inventory.java 查看文件

@@ -0,0 +1,63 @@
1
+package com.zipcodewilmington.productmanager;
2
+
3
+
4
+import java.util.ArrayList;
5
+import java.util.Iterator;
6
+import java.util.List;
7
+
8
+public class Inventory {
9
+    public List<Product> productList;
10
+
11
+    public Inventory(List<Product>  productList) {
12
+        this.productList = productList;
13
+    }
14
+
15
+    public Inventory(){
16
+        this.productList = new ArrayList<Product>();
17
+    }
18
+
19
+    public List<Product> getProductList(){
20
+        return productList;
21
+    }
22
+
23
+    public void add(Product product){
24
+
25
+        productList.add(product);
26
+    }
27
+
28
+    public void remove(Product product) {
29
+
30
+        productList.remove(product);
31
+    }
32
+
33
+
34
+    public Double getTotalValue() {
35
+        Double sum = 0.0;
36
+        for(Product product: productList){
37
+            sum+= product.getPrice() * product.getQuantity();
38
+        }
39
+        return sum;
40
+    }
41
+
42
+
43
+    public Boolean contains(Product product) {
44
+    return productList.contains(product);
45
+    }
46
+
47
+    public int size() {
48
+        return productList.size();
49
+    }
50
+
51
+    public void removeById(Integer id){
52
+        Iterator<Product> productIterator= productList.iterator();
53
+        while(productIterator.hasNext()){
54
+            Product product = productIterator.next();
55
+            if(product.getId()==(id)){
56
+                productIterator.remove();
57
+                break;
58
+            }
59
+        }
60
+    }
61
+
62
+
63
+}

+ 70
- 0
src/main/java/com/zipcodewilmington/productmanager/MainApplication.java 查看文件

@@ -1,7 +1,77 @@
1 1
 package com.zipcodewilmington.productmanager;
2 2
 
3
+
4
+import java.util.List;
5
+import java.util.Scanner;
6
+
3 7
 /**
4 8
  * Created by leon on 1/10/18.
5 9
  */
6 10
 public class MainApplication {
11
+
12
+    public static void main(String[] args){
13
+        Inventory inventory= new Inventory();
14
+        Scanner scanner = new Scanner(System.in);
15
+
16
+
17
+        while(true) {
18
+            System.out.println(getWelcomeMessage());
19
+
20
+            String userInput = scanner.nextLine();
21
+            if (userInput.equals("view")) {
22
+                String view = inventory.toString();
23
+            } else if (userInput.equals("add")) {
24
+                addProduct(inventory, scanner);
25
+            } else if (userInput.equals("remove")) {
26
+                System.out.println("what is the id?");
27
+                Integer id = Integer.parseInt(scanner.nextLine());
28
+                inventory.removeById(id);
29
+            }
30
+
31
+            if(userInput.equals("quit")){
32
+                break;
33
+            }
34
+
35
+            System.out.println(inventory.getProductList());
36
+            printInventory(inventory);
37
+        }
38
+
39
+    }
40
+
41
+    private static String getWelcomeMessage() {
42
+        return new StringBuilder()
43
+        .append("Welcome to my ineventory\n")
44
+        .append("From here, you can")
45
+        .append("[ view ]")
46
+        .append("[ add ]")
47
+        .append("[ remove ]")
48
+        .append("products.")
49
+        .toString();
50
+    }
51
+
52
+    private static void printInventory(Inventory inventory) {
53
+        List<Product> productList= inventory.getProductList();
54
+        for(int x = 0; x < productList.size(); x++){
55
+            Product product= productList.get(x);
56
+            product.getPrice();
57
+            product.getQuantity();
58
+            product.getId();
59
+            System.out.println(product.getPrice() + " : " + product.getId() + " : " + product.getQuantity());
60
+        }
61
+    }
62
+
63
+    private static void addProduct(Inventory inventory, Scanner scanner) {
64
+        System.out.println("What is the price?");
65
+        Double price = Double.parseDouble(scanner.nextLine());
66
+
67
+        System.out.println("What is the id?");
68
+        Integer id = Integer.parseInt(scanner.nextLine());
69
+
70
+        System.out.println("What is the quantity?");
71
+        Integer quantity = Integer.parseInt(scanner.nextLine());
72
+
73
+        inventory.add(new Product(price, id, quantity));
74
+    }
7 75
 }
76
+
77
+

+ 35
- 0
src/main/java/com/zipcodewilmington/productmanager/Product.java 查看文件

@@ -4,4 +4,39 @@ package com.zipcodewilmington.productmanager;
4 4
  * Created by leon on 1/10/18.
5 5
  */
6 6
 public class Product {
7
+    private Double price;
8
+    private Integer id;
9
+    private Integer quantity;
10
+
11
+    public Product(Double price, Integer id, Integer quantity) {
12
+        this.price = price;
13
+        this.id = id;
14
+        this.quantity= quantity;
15
+    }
16
+
17
+    public double getPrice() {
18
+        return price;
19
+    }
20
+
21
+    public int getId() {
22
+        return id;
23
+    }
24
+
25
+    public int getQuantity() {
26
+        return quantity;
27
+    }
28
+
29
+    public void setPrice(Double price) {
30
+        this.price= price;
31
+    }
32
+
33
+    public void setId(Integer id) {
34
+        this.id= id;
35
+    }
36
+
37
+    public void setQuantity(Integer quantity) {
38
+        this.quantity= quantity;
39
+    }
40
+
41
+
7 42
 }

+ 138
- 0
src/test/java/com/zipcodewilmington/productmanager/InventoryTest.java 查看文件

@@ -0,0 +1,138 @@
1
+package com.zipcodewilmington.productmanager;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import java.util.ArrayList;
6
+import java.util.List;
7
+
8
+public class InventoryTest {
9
+    @Test
10
+    public void constructorTest(){
11
+        //given
12
+        List<Product> productList = new ArrayList<Product>();
13
+
14
+        //When
15
+        Inventory inventory= new Inventory(productList);
16
+
17
+        //then
18
+        Assert.assertEquals(productList, inventory.getProductList());
19
+    }
20
+
21
+    @Test
22
+    public void addTest(){
23
+        //Given
24
+        Inventory inventory= new Inventory();
25
+        Product product = new Product(50.7,1,2);
26
+        //When
27
+        inventory.add(product);
28
+        //Then
29
+        Assert.assertTrue(inventory.contains(product));
30
+    }
31
+
32
+    @Test
33
+    public void removeTest(){
34
+        //Given
35
+        Inventory inventory= new Inventory();
36
+        Product product = new Product(50.7, 1, 2);
37
+        inventory.add(product);
38
+        //When
39
+        inventory.remove(product);
40
+        //Then
41
+        Assert.assertFalse(inventory.contains(product));
42
+    }
43
+
44
+    @Test
45
+    public void sizeTest(){
46
+        //given
47
+        Inventory inventory= new Inventory();
48
+        Product product= new Product(50.7,1,2);
49
+        inventory.add(product);
50
+        int expected = 1;
51
+        //when
52
+        int actual = inventory.size();
53
+        //then
54
+        Assert.assertEquals(expected, actual);
55
+
56
+    }
57
+
58
+    @Test
59
+    public void containsTest(){
60
+        //given
61
+        Inventory inventory= new Inventory();
62
+        Product product= new Product(50.7,1,2);
63
+        inventory.add(product);
64
+        boolean expected = true;
65
+        //when
66
+        boolean actual = inventory.contains(product);
67
+        //then
68
+        Assert.assertEquals(expected, actual);
69
+
70
+    }
71
+
72
+    @Test
73
+    public void toStringTest(){
74
+
75
+    }
76
+
77
+    @Test
78
+    public void mergeInventories(){
79
+        Inventory inventory = new Inventory();
80
+    }
81
+
82
+    @Test
83
+    public void getTotalValue(){
84
+        Inventory inventory = new Inventory();
85
+        Double price = 10.0;
86
+        int quantity = 5;
87
+
88
+        Double expected = price*quantity;
89
+
90
+        Product product = new Product(price, 1, quantity);
91
+
92
+        inventory.add(product);
93
+
94
+
95
+        Double actual= inventory.getTotalValue();
96
+
97
+        Assert.assertEquals(expected,actual);
98
+    }
99
+
100
+    @Test
101
+    public void getTotalValue2(){
102
+        Inventory inventory = new Inventory();
103
+        Double price = 5.0;
104
+        Double price2 = 15.0;
105
+        int quantity = 12;
106
+        int quantity1 = 5;
107
+
108
+        Double expected = (price*quantity)+(price2*quantity1);
109
+
110
+        Product product = new Product(price, 1, quantity);
111
+        Product product1= new Product(price2, 2, quantity1);
112
+        inventory.add(product);
113
+        inventory.add(product1);
114
+
115
+        Double actual= inventory.getTotalValue();
116
+
117
+        Assert.assertEquals(expected,actual);
118
+    }
119
+
120
+    @Test
121
+    public void nullaryConstuctorTest(){
122
+        Inventory inventory= new Inventory();
123
+
124
+        List<Product> productList = inventory.getProductList();
125
+        Assert.assertNotNull(productList);
126
+        Assert.assertTrue(productList.isEmpty());
127
+    }
128
+    public void removeById(){
129
+        Inventory inventory= new Inventory();
130
+        int id =2;
131
+        Product product = new Product(50.7,1,2);
132
+        inventory.add(product);
133
+
134
+        inventory.removeById(id);
135
+
136
+        Assert.assertFalse(inventory.contains(product));
137
+    }
138
+}

+ 49
- 1
src/test/java/com/zipcodewilmington/productmanager/ProductTest.java 查看文件

@@ -1,7 +1,55 @@
1 1
 package com.zipcodewilmington.productmanager;
2
-
2
+import org.junit.Assert;
3
+import org.junit.Test;
3 4
 /**
4 5
  * Created by leon on 1/10/18.
5 6
  */
6 7
 public class ProductTest {
8
+@Test
9
+    public void testConstructor(){
10
+    //given
11
+    double price=50.7;
12
+    int id=1;
13
+    int quantity=4;
14
+
15
+    //when
16
+    Product product = new Product(price,id, quantity);
17
+
18
+    //them
19
+    Assert.assertEquals(price, product.getPrice(),0.001);
20
+    Assert.assertEquals(id, product.getId());
21
+    Assert.assertEquals(quantity, product.getQuantity());
22
+}
23
+
24
+@Test
25
+    public void testsetPrice(){
26
+    Product p = new Product(50.7, 1, 2);
27
+    double expected =50.7;
28
+
29
+    p.setPrice(expected);
30
+
31
+    Assert.assertEquals(expected, p.getPrice(),0.001);
32
+    }
33
+
34
+    @Test
35
+    public void testsetId(){
36
+        Product p = new Product(50.7,1,2);
37
+        int expected =1;
38
+
39
+        p.setId(expected);
40
+
41
+        Assert.assertEquals(expected, p.getId());
42
+    }
43
+
44
+    @Test
45
+    public void testsetQuantity(){
46
+        Product p = new Product(50.7,1,5);
47
+       int expected =5;
48
+
49
+        p.setQuantity(expected);
50
+
51
+        Assert.assertEquals(expected, p.getQuantity());
52
+
53
+
54
+    }
7 55
 }