Sfoglia il codice sorgente

moved to git.zipcode.rocks

L. Dolio Durant 8 anni fa
commit
69abead009

+ 115
- 0
.gitignore Vedi File

@@ -0,0 +1,115 @@
1
+# Created by .ignore support plugin (hsz.mobi)
2
+### Java template
3
+# Compiled class file
4
+*.class
5
+
6
+# Log file
7
+*.log
8
+
9
+# BlueJ files
10
+*.ctxt
11
+
12
+# Mobile Tools for Java (J2ME)
13
+.mtj.tmp/
14
+
15
+# Package Files #
16
+*.jar
17
+*.war
18
+*.ear
19
+*.zip
20
+*.tar.gz
21
+*.rar
22
+
23
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24
+hs_err_pid*
25
+### Eclipse template
26
+
27
+.metadata
28
+bin/
29
+tmp/
30
+*.tmp
31
+*.bak
32
+*.swp
33
+*~.nib
34
+local.properties
35
+.settings/
36
+.loadpath
37
+.recommenders
38
+
39
+# Eclipse Core
40
+.project
41
+
42
+# External tool builders
43
+.externalToolBuilders/
44
+
45
+# Locally stored "Eclipse launch configurations"
46
+*.launch
47
+
48
+# PyDev specific (Python IDE for Eclipse)
49
+*.pydevproject
50
+
51
+# CDT-specific (C/C++ Development Tooling)
52
+.cproject
53
+
54
+# JDT-specific (Eclipse Java Development Tools)
55
+.classpath
56
+
57
+# Java annotation processor (APT)
58
+.factorypath
59
+
60
+# PDT-specific (PHP Development Tools)
61
+.buildpath
62
+
63
+# sbteclipse plugin
64
+.target
65
+
66
+# Tern plugin
67
+.tern-project
68
+
69
+# TeXlipse plugin
70
+.texlipse
71
+
72
+# STS (Spring Tool Suite)
73
+.springBeans
74
+
75
+# Code Recommenders
76
+.recommenders/
77
+
78
+# Scala IDE specific (Scala & Java development for Eclipse)
79
+.cache-main
80
+.scala_dependencies
81
+.worksheet
82
+### macOS template
83
+*.DS_Store
84
+.AppleDouble
85
+.LSOverride
86
+
87
+# Icon must end with two \r
88
+Icon
89
+
90
+
91
+# Thumbnails
92
+._*
93
+
94
+# Files that might appear in the root of a volume
95
+.DocumentRevisions-V100
96
+.fseventsd
97
+.Spotlight-V100
98
+.TemporaryItems
99
+.Trashes
100
+.VolumeIcon.icns
101
+.com.apple.timemachine.donotpresent
102
+
103
+# Directories potentially created on remote AFP share
104
+.AppleDB
105
+.AppleDesktop
106
+Network Trash Folder
107
+Temporary Items
108
+.apdisk
109
+
110
+#Intellij files
111
+.idea
112
+*.iml
113
+
114
+#maven build target
115
+target/

+ 9
- 0
.travis.yml Vedi File

@@ -0,0 +1,9 @@
1
+sudo: false
2
+language: java
3
+
4
+deploy:
5
+  provider: script
6
+  script: "mvn test"
7
+  skip_cleanup: true
8
+  on:
9
+tags: true

+ 62
- 0
README-TDDPatterns.md Vedi File

@@ -0,0 +1,62 @@
1
+# Test Driven Development (TDD)
2
+## What is a unit test?
3
+* A `unit test` is a practice by which `small units of code` are tested.
4
+* The purpose of a unit test is to determine if a feature being tested is fit for use in other parts of an application.
5
+* It is considered best practice to test every method in an application with at least 2 sets of arguments.
6
+* Tests are typically expressed as a combination of three clauses:
7
+	* `Given` some context
8
+	* `When` some action is carried out
9
+	* `Then` consequences should be observable
10
+
11
+### Example
12
+
13
+```java
14
+// Given
15
+String name = "Leon";
16
+Integer age = 25;
17
+Person leon = new Person(name, age);
18
+
19
+// When
20
+String getNameResult = leon.getName();
21
+Integer getAgeResult = leon.getAge();
22
+
23
+// Then
24
+Assert.assertEquals(name, getNameResult);
25
+Assert.assertEquals(age, getAgeResult);
26
+```
27
+
28
+
29
+## What are the three clauses of a test?
30
+### Given (some context)
31
+* `Given` is the section of a unit test method that
32
+	* initializes, instantiates, or sets the value of data to pass to test method.
33
+
34
+* **Example**
35
+
36
+```java
37
+// Given
38
+String name = "Leon";
39
+Integer age = 25;
40
+Person leon = new Person(name, age);
41
+```
42
+
43
+### When (some action is carried out)
44
+* `When` is the section of a unit test method that
45
+	* invokes the method under test with the arranged parameters
46
+
47
+```java
48
+// When
49
+String getNameResult = leon.getName();
50
+Integer getAgeResult = leon.getAge(); 
51
+```
52
+
53
+
54
+### Then (consequences should be observable)
55
+* `Then` is the section of a unit test method that
56
+	* verifies that the method to be tested behaves as expected
57
+
58
+```java
59
+// Then
60
+Assert.assertEquals(name, getNameResult);
61
+Assert.assertEquals(age, getAgeResult);
62
+```

+ 79
- 0
README.md Vedi File

@@ -0,0 +1,79 @@
1
+# TDD-AnimalFactory
2
+* **Objective:**
3
+    * To create tests that ensure expected behavior of each class:
4
+        * Cat
5
+        * Dog
6
+        * AnimalFactory
7
+        * CatHouse
8
+        * DogHouse
9
+* **Purpose:**
10
+    * To establish familiarity with Test-Driven-Development (TDD) practices.
11
+* **Getting context:**
12
+	* Click [here](./README-TDDPatterns.md) to gain more familiarity with TDD-structured programming.
13
+
14
+## Getting Started
15
+* Begin by opening the `test.java.rocks.zipcodewilmington` package and completing each of the `TODO`s.
16
+
17
+### CatTest
18
+* Create tests for `void setName(String name)`
19
+    * ensure that when `.setName` is invoked on an instance of `Cat`, the `name` field is being set to the respective value.
20
+* Create tests for `String speak()`
21
+    * ensure that when `.speak` is invoked on an instance of `Cat`, the value `"meow!"` is returned.
22
+* Create tests for `setBirthDate(Date birthDate)`
23
+    * ensure that when `.setBirthDate` is invoked on an instance of `Cat`, the `name` field is being set to the respective value.
24
+* Create tests for `void eat(Food food)`
25
+    * ensure that when `.eat` is invoked on an instance of `Cat`, the `numberOfMealsEaten` is increased by 1.
26
+* Create tests for `Integer getId()`
27
+    * ensure that when `.getId` is invoked on an instance of `Cat`, the respective `id` value is returned.
28
+* Create test to check Animal inheritance; google search `java instanceof keyword`
29
+    * ensure that a `Cat` is an `instanceof` an Animal 
30
+* Create test to check Mammal inheritance; google search `java instanceof keyword`
31
+    * ensure that a `Cat` is an `instanceof` a Mammal
32
+
33
+### DogTest
34
+* Create tests for `void setName(String name)`
35
+    * ensure that when `.setName` is invoked on an instance of `Dog`, the `name` field is being set to the respective value.
36
+* Create tests for `String speak()`
37
+    * ensure that when `.speak` is invoked on an instance of `Dog`, the value `"bark!"` is returned.
38
+* Create tests for `setBirthDate(Date birthDate)`
39
+    * ensure that when `.setBirthDate` is invoked on an instance of `Dog`, the `name` field is being set to the respective value.
40
+* Create tests for `void eat(Food food)`
41
+    * ensure that when `.eat` is invoked on an instance of `Dog`, the `numberOfMealsEaten` is increased by 1.
42
+* Create tests for `Integer getId()`
43
+    * ensure that when `.getId` is invoked on an instance of `Dog`, the respective `id` value is returned.
44
+* Create test to check Animal inheritance; google search `java instanceof keyword`
45
+    * ensure that a `Dog` is an `instanceof` an Animal 
46
+* Create test to check Mammal inheritance; google search `java instanceof keyword`
47
+    * ensure that a `Dog` is an `instanceof` an Mammal
48
+ 
49
+
50
+### AnimalFactoryTest
51
+* Create Test for `Animal createDog(String name, Date birthDate)`
52
+    * ensure that when `.createDog` is invoked on `AnimalFactoryTest` a `Dog` is created with the respective `name` and `birthDate` value.
53
+* Create Test for `Animal createCat(String name, Date birthDate)`
54
+    * ensure that when `.createCat` is invoked on `AnimalFactoryTest` a `Dog` is created with the respective `name` and `birthDate` value.
55
+
56
+### CatHouseTest
57
+* Create tests for `void add(Cat cat)`
58
+    * ensure that when `.add` is invoked on the `CatHouse`, a respective `Cat` object can be retrieved from the house.  
59
+* Create tests for `void remove(Cat cat)`
60
+    * ensure that when `.remove` is invoked on the `CatHouse`, a respective `Cat` object can no longer be retrieved from the house.
61
+* Create tests for `void remove(Integer id)`
62
+    * ensure that when `.remove` is invoked on the `CatHouse`, a `Cat` object with the respective `id` can no longer be retrieved from the house.
63
+* Create tests for `Cat getCatById(Integer id)`
64
+    * ensure that when `.getCatById` is invoked on the `CatHouse`, a `Cat` with the respective `id` is returned.
65
+* Create tests for `Integer getNumberOfCats()`
66
+    * ensure that when `.getNumberOfCats()` is invoked on the `CatHouse`, the respective number of `Cat` objects is returned.
67
+ 
68
+### DogHouseTest
69
+* Create tests for `void add(Dog dog)`
70
+    * ensure that when `.add` is invoked on the `DogHouse`, a respective `Dog` object can be retrieved from the house.  
71
+* Create tests for `void remove(Integer id)`
72
+    * ensure that when `.remove` is invoked on the `DogHouse`, a respective `Dog` object can no longer be retrieved from the house.
73
+* Create tests for `void remove(Dog dog)`
74
+    * ensure that when `.remove` is invoked on the `DogHouse`, a `Dog` object with the respective `id` can no longer be retrieved from the house.
75
+* Create tests for `Dog getDogById(Integer id)`
76
+    * ensure that when `.getCatById` is invoked on the `DogHouse`, a `Dog` with the respective `id` is returned.
77
+* Create tests for `Integer getNumberOfDogs()`
78
+    * ensure that when `.getNumberOfDogs()` is invoked on the `DogHouse`, the respective number of `Dog` objects is returned.
79
+

+ 34
- 0
pom.xml Vedi File

@@ -0,0 +1,34 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>rocks.zipcodewilmington</groupId>
8
+    <artifactId>tdd-animals</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+
11
+
12
+    <build>
13
+        <plugins>
14
+            <plugin>
15
+                <groupId>org.apache.maven.plugins</groupId>
16
+                <artifactId>maven-compiler-plugin</artifactId>
17
+                <version>3.7.0</version>
18
+                <configuration>
19
+                    <source>1.8</source>
20
+                    <target>1.8</target>
21
+                </configuration>
22
+            </plugin>
23
+        </plugins>
24
+    </build>
25
+
26
+    <dependencies>
27
+        <dependency>
28
+            <groupId>junit</groupId>
29
+            <artifactId>junit</artifactId>
30
+            <version>4.12</version>
31
+        </dependency>
32
+    </dependencies>
33
+
34
+</project>

+ 7
- 0
src/main/java/rocks/zipcodewilmington/Food.java Vedi File

@@ -0,0 +1,7 @@
1
+package rocks.zipcodewilmington;
2
+
3
+/**
4
+ * @author leon on 4/19/18.
5
+ */
6
+public class Food {
7
+}

+ 7
- 0
src/main/java/rocks/zipcodewilmington/MainApplication.java Vedi File

@@ -0,0 +1,7 @@
1
+package rocks.zipcodewilmington;
2
+
3
+/**
4
+ * @author leon on 4/19/18.
5
+ */
6
+public class MainApplication {
7
+}

+ 14
- 0
src/main/java/rocks/zipcodewilmington/animals/Animal.java Vedi File

@@ -0,0 +1,14 @@
1
+package rocks.zipcodewilmington.animals;
2
+
3
+import rocks.zipcodewilmington.Food;
4
+
5
+/**
6
+ * @author leon on 4/19/18.
7
+ */
8
+public interface Animal {
9
+    String speak();
10
+    Integer getNumberOfMealsEaten();
11
+    Integer getId();
12
+    void eat(Food food);
13
+
14
+}

+ 16
- 0
src/main/java/rocks/zipcodewilmington/animals/Cat.java Vedi File

@@ -0,0 +1,16 @@
1
+package rocks.zipcodewilmington.animals;
2
+
3
+import java.util.Date;
4
+
5
+/**
6
+ * @author leon on 4/19/18.
7
+ */
8
+public class Cat extends Mammal {
9
+    public Cat(String name, Date birthDate, Integer id) {
10
+        super(name, birthDate, id);
11
+    }
12
+
13
+    public String speak() {
14
+        return "meow!";
15
+    }
16
+}

+ 16
- 0
src/main/java/rocks/zipcodewilmington/animals/Dog.java Vedi File

@@ -0,0 +1,16 @@
1
+package rocks.zipcodewilmington.animals;
2
+
3
+import java.util.Date;
4
+
5
+/**
6
+ * @author leon on 4/19/18.
7
+ */
8
+public class Dog extends Mammal {
9
+    public Dog(String name, Date birthDate, Integer id) {
10
+        super(name, birthDate, id);
11
+    }
12
+
13
+    public String speak() {
14
+        return "bark!";
15
+    }
16
+}

+ 53
- 0
src/main/java/rocks/zipcodewilmington/animals/Mammal.java Vedi File

@@ -0,0 +1,53 @@
1
+package rocks.zipcodewilmington.animals;
2
+
3
+import rocks.zipcodewilmington.Food;
4
+
5
+import java.util.ArrayList;
6
+import java.util.Date;
7
+
8
+/**
9
+ * @author leon on 4/19/18.
10
+ */
11
+public abstract class Mammal implements Animal {
12
+    private final Integer id;
13
+    private ArrayList<Food> eatenMeals;
14
+    private String name;
15
+    private Date birthDate;
16
+
17
+    public Mammal(String name, Date birthDate, Integer id) {
18
+        this.name = name;
19
+        this.birthDate = birthDate;
20
+        this.eatenMeals = new ArrayList<>();
21
+        this.id = id;
22
+    }
23
+
24
+    public String getName() {
25
+        return name;
26
+    }
27
+
28
+    public void setName(String name) {
29
+        this.name = name;
30
+    }
31
+
32
+    public Date getBirthDate() {
33
+        return birthDate;
34
+    }
35
+
36
+    public void setBirthDate(Date birthDate) {
37
+        this.birthDate = birthDate;
38
+    }
39
+
40
+
41
+    public Integer getNumberOfMealsEaten() {
42
+        return eatenMeals.size();
43
+    }
44
+
45
+    public void eat(Food food) {
46
+        eatenMeals.add(food);
47
+    }
48
+
49
+    @Override
50
+    public Integer getId() {
51
+        return id;
52
+    }
53
+}

+ 25
- 0
src/main/java/rocks/zipcodewilmington/animals/animal_creation/AnimalFactory.java Vedi File

@@ -0,0 +1,25 @@
1
+package rocks.zipcodewilmington.animals.animal_creation;
2
+
3
+import rocks.zipcodewilmington.animals.Animal;
4
+import rocks.zipcodewilmington.animals.Cat;
5
+import rocks.zipcodewilmington.animals.Dog;
6
+import rocks.zipcodewilmington.animals.animal_storage.CatHouse;
7
+import rocks.zipcodewilmington.animals.animal_storage.DogHouse;
8
+
9
+import java.util.Date;
10
+
11
+/**
12
+ * @author leon on 4/19/18.
13
+ * This class is responsible for creating animals and automatically assigning them an id
14
+ */
15
+public class AnimalFactory {
16
+    public static Dog createDog(String name, Date birthDate) {
17
+        Integer newId = DogHouse.getNumberOfDogs();
18
+        return new Dog(name, birthDate, newId);
19
+    }
20
+
21
+    public static Cat createCat(String name, Date birthDate) {
22
+        Integer newId = CatHouse.getNumberOfCats();
23
+        return new Cat(name, birthDate, newId);
24
+    }
25
+}

+ 42
- 0
src/main/java/rocks/zipcodewilmington/animals/animal_storage/AnimalWarehouse.java Vedi File

@@ -0,0 +1,42 @@
1
+package rocks.zipcodewilmington.animals.animal_storage;
2
+
3
+import rocks.zipcodewilmington.animals.Animal;
4
+
5
+import java.util.ArrayList;
6
+
7
+/**
8
+ * @author leon on 4/19/18.
9
+ * this class is an abstraction of how Animals are stored and retrieved
10
+ */
11
+class AnimalWarehouse<AnimalType extends Animal> {
12
+    private volatile ArrayList<AnimalType> list = new ArrayList<>();
13
+
14
+    public void add(AnimalType animal) {
15
+        list.add(animal);
16
+    }
17
+
18
+    public AnimalType getAnimalById(int id) {
19
+        for(AnimalType animal : list) {
20
+            if(animal.getId() == id) {
21
+                return animal;
22
+            }
23
+        }
24
+        return null;
25
+    }
26
+
27
+    public void removeAnimal(Animal animal) {
28
+        list.remove(animal);
29
+    }
30
+
31
+    public void removeAnimalById(int id) {
32
+        removeAnimal(getAnimalById(id));
33
+    }
34
+
35
+    public Integer getNumberOfAnimals() {
36
+        return list.size();
37
+    }
38
+
39
+    public void clear() {
40
+        list.clear();
41
+    }
42
+}

+ 35
- 0
src/main/java/rocks/zipcodewilmington/animals/animal_storage/CatHouse.java Vedi File

@@ -0,0 +1,35 @@
1
+package rocks.zipcodewilmington.animals.animal_storage;
2
+
3
+
4
+import rocks.zipcodewilmington.animals.Cat;
5
+
6
+/**
7
+ * @author leon on 4/19/18.
8
+ */
9
+public class CatHouse {
10
+    private static AnimalWarehouse<Cat> catHouse = new AnimalWarehouse<>();
11
+
12
+    public static void add(Cat cat) {
13
+        catHouse.add(cat);
14
+    }
15
+
16
+    public static void remove(Integer id) {
17
+        catHouse.removeAnimalById(id);
18
+    }
19
+
20
+    public static void remove(Cat cat) {
21
+        catHouse.removeAnimal(cat);
22
+    }
23
+
24
+    public static Cat getCatById(Integer id) {
25
+        return catHouse.getAnimalById(id);
26
+    }
27
+
28
+    public static Integer getNumberOfCats() {
29
+        return catHouse.getNumberOfAnimals();
30
+    }
31
+
32
+    public static void clear() {
33
+        catHouse.clear();
34
+    }
35
+}

+ 34
- 0
src/main/java/rocks/zipcodewilmington/animals/animal_storage/DogHouse.java Vedi File

@@ -0,0 +1,34 @@
1
+package rocks.zipcodewilmington.animals.animal_storage;
2
+
3
+import rocks.zipcodewilmington.animals.Dog;
4
+
5
+/**
6
+ * @author leon on 4/19/18.
7
+ */
8
+public class DogHouse {
9
+    private static AnimalWarehouse<Dog> dogHouse = new AnimalWarehouse<>();
10
+
11
+    public static void add(Dog dog) {
12
+        dogHouse.add(dog);
13
+    }
14
+
15
+    public static void remove(Integer id) {
16
+        dogHouse.removeAnimalById(id);
17
+    }
18
+
19
+    public static void remove(Dog dog) {
20
+        dogHouse.removeAnimal(dog);
21
+    }
22
+
23
+    public static Dog getDogById(Integer id) {
24
+        return dogHouse.getAnimalById(id);
25
+    }
26
+
27
+    public static Integer getNumberOfDogs() {
28
+        return dogHouse.getNumberOfAnimals();
29
+    }
30
+
31
+    public static void clear() {
32
+        dogHouse.clear();
33
+    }
34
+}

+ 9
- 0
src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java Vedi File

@@ -0,0 +1,9 @@
1
+package rocks.zipcodewilmington;
2
+
3
+/**
4
+ * @author leon on 4/19/18.
5
+ */
6
+public class AnimalFactoryTest {
7
+    //TODO - Create Test for `Animal createDog(String name, Date birthDate)`
8
+    //TODO - Create Test for `Animal createCat(String name, Date birthDate)`
9
+}

+ 12
- 0
src/test/java/rocks/zipcodewilmington/CatHouseTest.java Vedi File

@@ -0,0 +1,12 @@
1
+package rocks.zipcodewilmington;
2
+
3
+/**
4
+ * @author leon on 4/19/18.
5
+ */
6
+public class CatHouseTest {
7
+    // TODO - Create tests for `void add(Cat cat)`
8
+    // TODO - Create tests for `void remove(Integer id)`
9
+    // TODO - Create tests for `void remove(Cat cat)`
10
+    // TODO - Create tests for `Cat getCatById(Integer id)`
11
+    // TODO - Create tests for `Integer getNumberOfCats()`
12
+}

+ 43
- 0
src/test/java/rocks/zipcodewilmington/CatTest.java Vedi File

@@ -0,0 +1,43 @@
1
+package rocks.zipcodewilmington;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcodewilmington.animals.Cat;
6
+
7
+import java.util.Date;
8
+
9
+/**
10
+ * @author leon on 4/19/18.
11
+ */
12
+public class CatTest {
13
+    // TODO - Create tests for `void setName(String name)`
14
+    // TODO - Create tests for `speak`
15
+    // TODO - Create tests for `setBirthDate(Date birthDate)`
16
+    // TODO - Create tests for `void eat(Food food)`
17
+    // TODO - Create tests for `Integer getId()`
18
+    // TODO - Create test to check Animal inheritance; google search `java instanceof keyword`
19
+    // TODO - Create test to check Mammal inheritance; google search `java instanceof keyword`
20
+
21
+
22
+    @Test
23
+    public void constructorTest() {
24
+        // Given (cat data)
25
+        String givenName = "Zula";
26
+        Date givenBirthDate = new Date();
27
+        Integer givenId = 0;
28
+
29
+        // When (a cat is constructed)
30
+        Cat cat = new Cat(givenName, givenBirthDate, givenId);
31
+
32
+        // When (we retrieve data from the cat)
33
+        String retrievedName = cat.getName();
34
+        Date retrievedBirthDate = cat.getBirthDate();
35
+        Integer retrievedId = cat.getId();
36
+
37
+        // Then (we expect the given data, to match the retrieved data)
38
+        Assert.assertEquals(givenName, retrievedName);
39
+        Assert.assertEquals(givenBirthDate, retrievedBirthDate);
40
+        Assert.assertEquals(givenId, retrievedId);
41
+    }
42
+
43
+}

+ 34
- 0
src/test/java/rocks/zipcodewilmington/DogHouseTest.java Vedi File

@@ -0,0 +1,34 @@
1
+package rocks.zipcodewilmington;
2
+
3
+import org.junit.Test;
4
+import rocks.zipcodewilmington.animals.Dog;
5
+import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory;
6
+import rocks.zipcodewilmington.animals.animal_storage.DogHouse;
7
+
8
+import java.util.Date;
9
+
10
+/**
11
+ * @author leon on 4/19/18.
12
+ */
13
+public class DogHouseTest {
14
+    // TODO - Create tests for `void add(Dog dog)`
15
+    // TODO - Create tests for `void remove(Integer id)`
16
+    // TODO - Create tests for `void remove(Dog dog)`
17
+    // TODO - Create tests for `Dog getDogById(Integer id)`
18
+    // TODO - Create tests for `Integer getNumberOfDogs()`
19
+
20
+    @Test
21
+    public void testGetNumberOfDogs() {
22
+        // Given (some
23
+        String name = "Milo";
24
+        Date birthDate = new Date();
25
+        Dog animal = AnimalFactory.createDog(name, birthDate);
26
+        DogHouse.clear();
27
+
28
+        // When
29
+        DogHouse.add(animal);
30
+
31
+        // Then
32
+        DogHouse.getNumberOfDogs();
33
+    }
34
+}

+ 31
- 0
src/test/java/rocks/zipcodewilmington/DogTest.java Vedi File

@@ -0,0 +1,31 @@
1
+package rocks.zipcodewilmington;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcodewilmington.animals.Dog;
6
+
7
+/**
8
+ * @author leon on 4/19/18.
9
+ */
10
+public class DogTest {
11
+    // TODO - Create tests for `new Dog(String name, Date birthDate, Integer id)`
12
+    // TODO - Create tests for `speak`
13
+    // TODO - Create tests for `setBirthDate(Date birthDate)`
14
+    // TODO - Create tests for `void eat(Food food)`
15
+    // TODO - Create tests for `Integer getId()`
16
+    // TODO - Create test to check Animal inheritance; google search `java instanceof keyword`
17
+    // TODO - Create test to check Mammal inheritance; google search `java instanceof keyword`
18
+    @Test
19
+    public void setNameTest() {
20
+        // Given (a name exists and a dog exists)
21
+        Dog dog = new Dog(null, null, null);
22
+        String givenName = "Milo";
23
+
24
+        // When (a dog's name is set to the given name)
25
+        dog.setName(givenName);
26
+
27
+        // Then (we expect to get the given name from the dog)
28
+        String dogName = dog.getName();
29
+        Assert.assertEquals(dogName, givenName);
30
+    }
31
+}