Browse Source

Update Product test and read me to give better instruction

Nhu Nguyen 6 years ago
parent
commit
a890dd9615
2 changed files with 12 additions and 30 deletions
  1. 5
    23
      README.md
  2. 7
    7
      src/test/java/org/zipcoder/store/ProductTest.java

+ 5
- 23
README.md View File

5
 
5
 
6
 ## Part 1 - Product
6
 ## Part 1 - Product
7
 In the `test` folder, there is a `ProductTest` with most of the tested commented out.
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
     - ex: `Hat (Color: Yellow, Size: LG)`
13
     - ex: `Hat (Color: Yellow, Size: LG)`
32
 
14
 
33
 ## Part 2 - Cart
15
 ## Part 2 - Cart

+ 7
- 7
src/test/java/org/zipcoder/store/ProductTest.java View File

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