Kaynağa Gözat

added ReadMe & testing

Leon 6 yıl önce
ebeveyn
işleme
f3415e3b0f

+ 11
- 0
README.md Dosyayı Görüntüle

@@ -0,0 +1,11 @@
1
+# Iterating an array of `Person` objects
2
+* **Objective:**
3
+    * To concatenate the details of `Person` objects by iterating an array  
4
+
5
+* **Purpose:**
6
+    * To demonstrate practical understanding of `while`, `for`, and `for each` loops.
7
+
8
+* **Getting started:**
9
+    * The `PersonHandler` class has 3 [method stubs](https://en.wikipedia.org/wiki/Method_stub) to be completed.
10
+        * The methods contain line-by-line comments to guide you through the process.
11
+    * Ensure all tests cases pass successfully.

+ 7
- 0
pom.xml Dosyayı Görüntüle

@@ -7,6 +7,13 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>loop_labs</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>4.12</version>
15
+        </dependency>
16
+    </dependencies>
10 17
     <properties>
11 18
         <maven.compiler.source>1.8</maven.compiler.source>
12 19
         <maven.compiler.target>1.8</maven.compiler.target>

+ 2
- 2
src/main/java/com/zipcodewilmington/Person.java Dosyayı Görüntüle

@@ -23,8 +23,8 @@ public class Person {
23 23
     @Override
24 24
     public String toString() {
25 25
         return new StringBuilder()
26
-                .append("My first name is " + firstName)
27
-                .append("My last name is " + lastName)
26
+                .append("\nMy first name is " + firstName)
27
+                .append("\nMy last name is " + lastName)
28 28
                 .toString();
29 29
     }
30 30
 }

+ 5
- 0
src/main/java/com/zipcodewilmington/PersonHandler.java Dosyayı Görüntüle

@@ -57,4 +57,9 @@ public class PersonHandler {
57 57
 
58 58
         return result;
59 59
     }
60
+
61
+
62
+    public Person[] getPersonArray() {
63
+        return personArray;
64
+    }
60 65
 }

+ 54
- 0
src/test/java/com/zipcodewilmington/PersonHandlerTest.java Dosyayı Görüntüle

@@ -1,7 +1,61 @@
1 1
 package com.zipcodewilmington;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
3 7
 /**
4 8
  * Created by leon on 1/24/18.
5 9
  */
6 10
 public class PersonHandlerTest {
11
+    PersonHandler personHandler;
12
+    private String expected;
13
+
14
+    @Before
15
+    public void setup() {
16
+        // : Given
17
+        Person person1 = new Person("Leon", "Hunter");
18
+        Person person2 = new Person("Tariq", "Hook");
19
+        Person person3 = new Person("Dolio", "Durant");
20
+        Person[] personArray = {person1, person2, person3};
21
+
22
+        this.personHandler = new PersonHandler(personArray);
23
+        this.expected = "\nMy first name is Leon\n" +
24
+                "My last name is Hunter\n" +
25
+                "My first name is Tariq\n" +
26
+                "My last name is Hook\n" +
27
+                "My first name is Dolio\n" +
28
+                "My last name is Durant";
29
+    }
30
+
31
+    @Test
32
+    public void testWhileLoop() {
33
+        // : When
34
+        String actual = personHandler.whileLoop();
35
+
36
+        // : Then
37
+        Assert.assertEquals(expected, actual);
38
+    }
39
+
40
+
41
+    @Test
42
+    public void testForLoop() {
43
+        // : When
44
+        String actual = personHandler.forLoop();
45
+
46
+        // : Then
47
+        Assert.assertEquals(expected, actual);
48
+    }
49
+
50
+
51
+    @Test
52
+    public void testForEachLoop() {
53
+        // : When
54
+        String actual = personHandler.forEachLoop();
55
+
56
+        // : Then
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+
60
+
7 61
 }