浏览代码

Update Product test and read me to give better instruction

Nhu Nguyen 6 年前
父节点
当前提交
a890dd9615
共有 2 个文件被更改,包括 12 次插入30 次删除
  1. 5
    23
      README.md
  2. 7
    7
      src/test/java/org/zipcoder/store/ProductTest.java

+ 5
- 23
README.md 查看文件

@@ -5,29 +5,11 @@
5 5
 
6 6
 ## Part 1 - Product
7 7
 In the `test` folder, there is a `ProductTest` with most of the tested commented out.
8
-  1. Notice the word `Product` is red. That's because we need to create a new Class named `Product`. The file should be in `src/main/java/org.zipcoder.store`.
9
-    - To make the test pass, create a new empty constructor with no parameter
10
-  2. Uncomment the second test, line 14 - 26.
11
-    - Create a new constructor that takes a String for the product name
12
-  3. Continue to uncomment the test and make it pass
13
-  4. For the `get` and `set` test, you need to create a field and methods to get and set the field. 
14
-    - Ex:
15
-
16
-    ```java
17
-    public class Book {
18
-      private String title;
19
-
20
-      public void setTitle(String title){
21
-        this.title = title;
22
-      }
23
-
24
-      public String getTitle() {
25
-        return this.title;
26
-      }
27
-    }
28
-    ```
29
-  5. Continue to uncomment the test and add code to make the test pass
30
-  6. For the product description, it should be in this format `title (Color: color, Size: size)`
8
+  1. The first test `testConstruction_WithNoParams` checks to see if the `Product` class has an empty constructor. To test it, I created a new object with no parameter.
9
+  2. The second test `testGetSetName` checks to see if you can set and get the name of the product. In order to make this pass, I added a `String` field called `name` (line 5). Then I added a getter method `getName` (line 18-20) and a setter method `setName(String name)` (line 23-25).
10
+  3. The third test `testConstruction_WithName` checks if the `Product` class has a constructor that takes a String. Notice we can have more than one constructor. When I create a new Product with a string `new Product("T-shirt")`, I set that string to the field `name` so when I called `getName`, I get the string that I passed into the constructor.
11
+  4. Continue to uncomment the test and write the code to make it pass
12
+  5. For the product description, it should be in this format `title (Color: color, Size: size)`
31 13
     - ex: `Hat (Color: Yellow, Size: LG)`
32 14
 
33 15
 ## Part 2 - Cart

+ 7
- 7
src/test/java/org/zipcoder/store/ProductTest.java 查看文件

@@ -12,12 +12,13 @@ public class ProductTest {
12 12
     }
13 13
 
14 14
     @Test
15
-    public void testConstruction_WithName(){
15
+    public void testGetSetName(){
16 16
         //Given
17
-        String expectedName = "T-Shirt";
17
+        String expectedName = "Pants";
18
+        Product product = new Product();
18 19
 
19 20
         //When
20
-        Product product = new Product(expectedName);
21
+        product.setName(expectedName);
21 22
 
22 23
         //Then
23 24
         String actualName = product.getName();
@@ -25,13 +26,12 @@ public class ProductTest {
25 26
     }
26 27
 
27 28
     @Test
28
-    public void testGetSetName(){
29
+    public void testConstruction_WithName(){
29 30
         //Given
30
-        String expectedName = "Pants";
31
-        Product product = new Product();
31
+        String expectedName = "T-Shirt";
32 32
 
33 33
         //When
34
-        product.setName(expectedName);
34
+        Product product = new Product(expectedName);
35 35
 
36 36
         //Then
37 37
         String actualName = product.getName();