瀏覽代碼

Talking Pets

Zavon Malone 6 年之前
父節點
當前提交
a1e93d933f

+ 8
- 0
pom.xml 查看文件

@@ -19,6 +19,14 @@
19 19
             </plugin>
20 20
         </plugins>
21 21
     </build>
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>junit</groupId>
25
+            <artifactId>junit</artifactId>
26
+            <version>RELEASE</version>
27
+            <scope>test</scope>
28
+        </dependency>
29
+    </dependencies>
22 30
 
23 31
 
24 32
 </project>

+ 34
- 0
src/test/java/io/zipcoder/polymorphism/DogTest.java 查看文件

@@ -0,0 +1,34 @@
1
+package io.zipcoder.polymorphism;
2
+import org.junit.Assert;
3
+import org.junit.Test;
4
+
5
+public class DogTest {
6
+    @Test
7
+    public void testImplementation(){
8
+        Dog dog = new Dog();
9
+
10
+        Assert.assertTrue(dog instanceof Pet);;
11
+    }
12
+
13
+    @Test
14
+    public void testSpeak(){
15
+        Dog dog = new Dog();
16
+        String expected = "Bark";
17
+
18
+        String actual= dog.speak();
19
+
20
+        Assert.assertEquals(expected, actual);
21
+    }
22
+
23
+    @Test
24
+    public void testSetName(){
25
+        Dog dog = new Dog();
26
+        String expected = "Jim";
27
+
28
+        dog.setNameOfPet(expected);
29
+        String actual = dog.getNameOfPet();
30
+
31
+        Assert.assertEquals(expected, actual);
32
+
33
+    }
34
+}

+ 0
- 7
src/test/java/io/zipcoder/polymorphism/MainApplicationTest.java 查看文件

@@ -1,7 +0,0 @@
1
-package io.zipcoder.polymorphism;
2
-
3
-/**
4
- * Created by leon on 11/6/17.
5
- */
6
-public class MainApplicationTest {
7
-}

+ 32
- 0
src/test/java/io/zipcoder/polymorphism/TestCat.java 查看文件

@@ -0,0 +1,32 @@
1
+package io.zipcoder.polymorphism;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class TestCat {
7
+    @Test
8
+    public void testImplementation(){
9
+        Cat cat= new Cat();
10
+
11
+        Assert.assertTrue(cat instanceof Pet);
12
+    }
13
+
14
+    @Test
15
+    public void testSpeak(){
16
+        Cat cat= new Cat();
17
+        String expected = "Meow";
18
+
19
+        String actual= cat.speak();
20
+
21
+        Assert.assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void testSetName(){
26
+        Cat cat= new Cat();
27
+        String expected = "Jim";
28
+
29
+        cat.setNameOfPet(expected);
30
+
31
+    }
32
+}

+ 35
- 0
src/test/java/io/zipcoder/polymorphism/TestLion.java 查看文件

@@ -0,0 +1,35 @@
1
+package io.zipcoder.polymorphism;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class TestLion {
7
+    @Test
8
+    public void testImplementation(){
9
+        Lion lion = new Lion();
10
+
11
+        Assert.assertTrue(lion instanceof Pet);;
12
+    }
13
+
14
+    @Test
15
+    public void testSpeak(){
16
+        Lion lion = new Lion();
17
+        String expected = "RAWRRRRR";
18
+
19
+        String actual= lion.speak();
20
+
21
+        Assert.assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void testSetName(){
26
+        Lion lion = new Lion();
27
+        String expected = "Jim";
28
+
29
+        lion.setNameOfPet(expected);
30
+        String actual = lion.getNameOfPet();
31
+
32
+        Assert.assertEquals(expected, actual);
33
+
34
+    }
35
+}