Add a package de.laliluna.tutorial.junitexample
where you place the example classes and a package
test.laliluna.tutorial.junitexample where you place your test classes.
The class Book
Create a new class Book in the package
de.laliluna.tutorial.junitexample.
Add two properties title of type String
and price of type double.
Add a constructor to set the two properties.
Provide a getter- and setter-method for each of them.
Add a method trunk for a method equals(Object
object) which checks if the object is an instance of the class Book and the
values of the object are equal. The method return a boolean value.
Note: Do not write the logic of the equals(..)
method, we do it after finish creating the test method.
The following source code shows the class Book.
public class Book {
private String title;
private double price;
/**
* Constructor
*
* @param title
* @param price
*/
public Book(String title,
double price) {
this.title = title;
this.price = price;
}
/**
* Check if an object is an instance of book
* and the values of title and price are equal
* then return true, otherwise return false
*/
public boolean equals(Object object) {
return false;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}