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.xmlwith IntelliJ. - Continue by opening the
test.java.rocks.zipcodewilmingtonpackage and completing each of theTODOs.
- Create tests for
void setName(String name)- ensure that when
.setNameis invoked on an instance ofCat, thenamefield is being set to the respective value.
- ensure that when
- Create tests for
setBirthDate(Date birthDate)- ensure that when
.setBirthDateis invoked on an instance ofCat, thebirthDatefield is being set to the respective value.
- ensure that when
- Create tests for
String speak()- ensure that when
.speakis invoked on an instance ofCat, the value"meow!"is returned.
- ensure that when
- Create tests for
void eat(Food food)- ensure that when
.eatis invoked on an instance ofCat, thenumberOfMealsEatenis increased by 1.
- ensure that when
- Create tests for
Integer getId()- ensure that when
.getIdis invoked on an instance ofCat, the respectiveidvalue is returned.
- ensure that when
- Create test to check Animal inheritance; google search
java instanceof keyword- ensure that a
Catis aninstanceofan Animal
- ensure that a
- Create test to check Mammal inheritance; google search
java instanceof keyword- ensure that a
Catis aninstanceofa Mammal
- ensure that a
- Create tests for
void setName(String name)- ensure that when
.setNameis invoked on an instance ofDog, thenamefield is being set to the respective value.
- ensure that when
- Create tests for
setBirthDate(Date birthDate)- ensure that when
.setBirthDateis invoked on an instance ofDog, thebirthDatefield is being set to the respective value.
- ensure that when
- Create tests for
String speak()- ensure that when
.speakis invoked on an instance ofDog, the value"bark!"is returned.
- ensure that when
- Create tests for
void eat(Food food)- ensure that when
.eatis invoked on an instance ofDog, thenumberOfMealsEatenis increased by 1.
- ensure that when
- Create tests for
Integer getId()- ensure that when
.getIdis invoked on an instance ofDog, the respectiveidvalue is returned.
- ensure that when
- Create test to check Animal inheritance; google search
java instanceof keyword- ensure that a
Dogis aninstanceofan Animal
- ensure that a
- Create test to check Mammal inheritance; google search
java instanceof keyword- ensure that a
Dogis aninstanceofan Mammal
- ensure that a
- Create Test for
Animal createDog(String name, Date birthDate)- ensure that when
.createDogis invoked onAnimalFactoryTestaDogis created with the respectivenameandbirthDatevalue.
- ensure that when
- Create Test for
Animal createCat(String name, Date birthDate)- ensure that when
.createCatis invoked onAnimalFactoryTestaDogis created with the respectivenameandbirthDatevalue.
- ensure that when
- Create tests for
void add(Cat cat)- ensure that when
.addis invoked on theCatHouse, a respectiveCatobject can be retrieved from the house.
- ensure that when
- Create tests for
void remove(Cat cat)- ensure that when
.removeis invoked on theCatHouse, a respectiveCatobject can no longer be retrieved from the house.
- ensure that when
- Create tests for
void remove(Integer id)- ensure that when
.removeis invoked on theCatHouse, aCatobject with the respectiveidcan no longer be retrieved from the house.
- ensure that when
- Create tests for
Cat getCatById(Integer id)- ensure that when
.getCatByIdis invoked on theCatHouse, aCatwith the respectiveidis returned.
- ensure that when
- Create tests for
Integer getNumberOfCats()- ensure that when
.getNumberOfCats()is invoked on theCatHouse, the respective number ofCatobjects is returned.
- ensure that when
- Create tests for
void add(Dog dog)- ensure that when
.addis invoked on theDogHouse, a respectiveDogobject can be retrieved from the house.
- ensure that when
- Create tests for
void remove(Integer id)- ensure that when
.removeis invoked on theDogHouse, a respectiveDogobject can no longer be retrieved from the house.
- ensure that when
- Create tests for
void remove(Dog dog)- ensure that when
.removeis invoked on theDogHouse, aDogobject with the respectiveidcan no longer be retrieved from the house.
- ensure that when
- Create tests for
Dog getDogById(Integer id)- ensure that when
.getCatByIdis invoked on theDogHouse, aDogwith the respectiveidis returned.
- ensure that when
- Create tests for
Integer getNumberOfDogs()- ensure that when
.getNumberOfDogs()is invoked on theDogHouse, the respective number ofDogobjects 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.