/
BookTest.java
112 lines (96 loc) · 3.12 KB
/
BookTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.technologyconversations.books;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
public class BookTest extends CommonTest {
@Test
public void idShouldHaveSetterAndGetter() {
int expected = 123;
book.setId(expected);
assertThat(book.getId(), is(equalTo(expected)));
}
@Test
public void imageShouldHaveSetterAndGetter() {
String expected = "new_path/image.png";
book.setImage(expected);
assertThat(book.getImage(), is(equalTo(expected)));
}
@Test
public void titleShouldHaveSetterAndGetter() {
String expected = "new title";
book.setTitle(expected);
assertThat(book.getTitle(), is(equalTo(expected)));
}
@Test
public void authorShouldHaveSetterAndGetter() {
String expected = "new author";
book.setAuthor(expected);
assertThat(book.getAuthor(), is(equalTo(expected)));
}
@Test
public void priceShouldHaveSetterAndGetter() {
double expected = 123.45;
book.setPrice(expected);
assertThat(book.getPrice(), is(equalTo(expected)));
}
@Test
public void linkShouldHaveSetterAndGetter() {
String expected = "new link";
book.setLink(expected);
assertThat(book.getLink(), is(equalTo(expected)));
}
@Test
public void equalsShouldFailIfIdIsNotTheSame() {
Book actual = new Book(123);
actual.setImage(image);
actual.setTitle(title);
actual.setAuthor(author);
actual.setPrice(price);
assertThat(actual, is(not(equalTo(book))));
}
@Test
public void equalsShouldReturnFalseIfImageIsNotTheSame() {
Book actual = new Book(id);
actual.setImage("new image");
actual.setTitle(title);
actual.setAuthor(author);
actual.setPrice(price);
assertThat(actual, is(not(equalTo(book))));
}
@Test
public void equalsShouldReturnFalseIfTitleIsNotTheSame() {
Book actual = new Book(id);
actual.setImage(image);
actual.setTitle("new title");
actual.setAuthor(author);
actual.setPrice(price);
assertThat(actual, is(not(equalTo(book))));
}
@Test
public void equalsShouldReturnFalseIfAuthorIsNotTheSame() {
Book actual = new Book(id);
actual.setImage(image);
actual.setTitle(title);
actual.setAuthor("new author");
actual.setPrice(price);
assertThat(actual, is(not(equalTo(book))));
}
@Test
public void equalsShouldReturnFalseIfPriceIsNotTheSame() {
Book actual = new Book(id);
actual.setImage(image);
actual.setTitle(title);
actual.setAuthor(author);
actual.setPrice(123.45);
assertThat(actual, is(not(equalTo(book))));
}
@Test
public void equalShouldReturnTrueIfIdImageTitleAuthorAndPriceAreTheSame() {
Book actual = new Book(id);
actual.setImage(image);
actual.setTitle(title);
actual.setAuthor(author);
actual.setPrice(price);
assertThat(actual, is(equalTo(book)));
}
}