浏览代码

doggo test

Seth 6 年前
父节点
当前提交
27539af58f

+ 8
- 0
pom.xml 查看文件

@@ -7,6 +7,14 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>polymorphism</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10 18
     <dependency>
11 19
         <groupId>junit</groupId>
12 20
         <artifactId>junit</artifactId>

+ 16
- 0
src/main/java/io/zipcoder/polymorphism/Dog.java 查看文件

@@ -0,0 +1,16 @@
1
+package io.zipcoder.polymorphism;
2
+
3
+public class Dog extends Pets{
4
+
5
+    public Dog() {
6
+
7
+    }
8
+
9
+    @Override
10
+    public String speak() {
11
+        return "Bark";
12
+    }
13
+}
14
+
15
+
16
+

+ 13
- 1
src/main/java/io/zipcoder/polymorphism/Pets.java 查看文件

@@ -1,4 +1,16 @@
1 1
 package io.zipcoder.polymorphism;
2 2
 
3
-public class Pets {
3
+public abstract class Pets {
4
+    private String name;
5
+    private String kind;
6
+
7
+    public Pets() {}
8
+
9
+    public Pets(String name, String kind) {
10
+        this.name = name;
11
+        this.kind = kind;
12
+    }
13
+
14
+    public String speak() {return "blorp";}
15
+
4 16
 }

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

@@ -0,0 +1,25 @@
1
+package io.zipcoder.polymorphism;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class DogTest {
7
+
8
+    @Test
9
+    public void speakTest() {
10
+        //Given
11
+        String actual = "Bark";
12
+
13
+        //When
14
+        Dog sparky = new Dog();
15
+        String expected = sparky.speak();
16
+
17
+        //Then
18
+        Assert.assertEquals(actual, expected);
19
+
20
+    }
21
+
22
+
23
+
24
+
25
+}