this is a pretty big lab. important to get it done.
remember, make your last commit message "finished" after you have figured it all out
- Objective:
- To create tests that ensure expected behavior of each class:
- Cat
- Dog
- AnimalFactory
- CatHouse
- DogHouse
- To create tests that ensure expected behavior of each class:
- Purpose:
- To establish familiarity with Test-Driven-Development (TDD) practices.
- Getting context:
- Click here to gain more familiarity with TDD-structured programming.
- You probably already have IntelliJ installed, right?
- Begin by opening the project via its
pom.xml
with IntelliJ. - Continue by opening the
test.java.rocks.zipcodewilmington
package and completing each of theTODO
s.
- Create tests for
void setName(String name)
- ensure that when
.setName
is invoked on an instance ofCat
, thename
field is being set to the respective value.
- ensure that when
- Create tests for
setBirthDate(Date birthDate)
- ensure that when
.setBirthDate
is invoked on an instance ofCat
, thebirthDate
field is being set to the respective value.
- ensure that when
- Create tests for
String speak()
- ensure that when
.speak
is invoked on an instance ofCat
, the value"meow!"
is returned.
- ensure that when
- Create tests for
void eat(Food food)
- ensure that when
.eat
is invoked on an instance ofCat
, thenumberOfMealsEaten
is increased by 1.
- ensure that when
- Create tests for
Integer getId()
- ensure that when
.getId
is invoked on an instance ofCat
, the respectiveid
value is returned.
- ensure that when
- Create test to check Animal inheritance; google search
java instanceof keyword
- ensure that a
Cat
is aninstanceof
an Animal
- ensure that a
- Create test to check Mammal inheritance; google search
java instanceof keyword
- ensure that a
Cat
is aninstanceof
a Mammal
- ensure that a
- Create tests for
void setName(String name)
- ensure that when
.setName
is invoked on an instance ofDog
, thename
field is being set to the respective value.
- ensure that when
- Create tests for
setBirthDate(Date birthDate)
- ensure that when
.setBirthDate
is invoked on an instance ofDog
, thebirthDate
field is being set to the respective value.
- ensure that when
- Create tests for
String speak()
- ensure that when
.speak
is invoked on an instance ofDog
, the value"bark!"
is returned.
- ensure that when
- Create tests for
void eat(Food food)
- ensure that when
.eat
is invoked on an instance ofDog
, thenumberOfMealsEaten
is increased by 1.
- ensure that when
- Create tests for
Integer getId()
- ensure that when
.getId
is invoked on an instance ofDog
, the respectiveid
value is returned.
- ensure that when
- Create test to check Animal inheritance; google search
java instanceof keyword
- ensure that a
Dog
is aninstanceof
an Animal
- ensure that a
- Create test to check Mammal inheritance; google search
java instanceof keyword
- ensure that a
Dog
is aninstanceof
an Mammal
- ensure that a
- Create Test for
Animal createDog(String name, Date birthDate)
- ensure that when
.createDog
is invoked onAnimalFactoryTest
aDog
is created with the respectivename
andbirthDate
value.
- ensure that when
- Create Test for
Animal createCat(String name, Date birthDate)
- ensure that when
.createCat
is invoked onAnimalFactoryTest
aDog
is created with the respectivename
andbirthDate
value.
- ensure that when
- Create tests for
void add(Cat cat)
- ensure that when
.add
is invoked on theCatHouse
, a respectiveCat
object can be retrieved from the house.
- ensure that when
- Create tests for
void remove(Cat cat)
- ensure that when
.remove
is invoked on theCatHouse
, a respectiveCat
object can no longer be retrieved from the house.
- ensure that when
- Create tests for
void remove(Integer id)
- ensure that when
.remove
is invoked on theCatHouse
, aCat
object with the respectiveid
can no longer be retrieved from the house.
- ensure that when
- Create tests for
Cat getCatById(Integer id)
- ensure that when
.getCatById
is invoked on theCatHouse
, aCat
with the respectiveid
is returned.
- ensure that when
- Create tests for
Integer getNumberOfCats()
- ensure that when
.getNumberOfCats()
is invoked on theCatHouse
, the respective number ofCat
objects is returned.
- ensure that when
- Create tests for
void add(Dog dog)
- ensure that when
.add
is invoked on theDogHouse
, a respectiveDog
object can be retrieved from the house.
- ensure that when
- Create tests for
void remove(Integer id)
- ensure that when
.remove
is invoked on theDogHouse
, a respectiveDog
object can no longer be retrieved from the house.
- ensure that when
- Create tests for
void remove(Dog dog)
- ensure that when
.remove
is invoked on theDogHouse
, aDog
object with the respectiveid
can no longer be retrieved from the house.
- ensure that when
- Create tests for
Dog getDogById(Integer id)
- ensure that when
.getCatById
is invoked on theDogHouse
, aDog
with the respectiveid
is returned.
- ensure that when
- Create tests for
Integer getNumberOfDogs()
- ensure that when
.getNumberOfDogs()
is invoked on theDogHouse
, the respective number ofDog
objects is returned.
- ensure that when
Why is this lab important?
Java inheritance makes things easier for a programmer by allowing them to reuse code and create more flexible and modular programs. Inheritance allows a subclass to inherit properties and methods from a superclass, which can save time and effort when writing code.
By using inheritance, programmers can create a hierarchy of classes that share common properties and behaviors. This can make the code easier to understand and maintain, as changes made to the superclass will automatically be inherited by the subclasses. In addition, inheritance can help to reduce code duplication, as common properties and behaviors can be defined in the superclass and reused by the subclasses.
Inheritance also allows for polymorphism, which is the ability of objects to take on multiple forms. This means that a subclass can be treated as an instance of its superclass, which can make the code more flexible and adaptable to changing requirements. For example, a program that uses inheritance can easily add new subclasses without having to modify the existing code.