-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibraryTest.java
More file actions
executable file
·93 lines (75 loc) · 2.1 KB
/
LibraryTest.java
File metadata and controls
executable file
·93 lines (75 loc) · 2.1 KB
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
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
class FakeDisplay implements Display
{
String lastShownLine;
public void showLine(String line) {
lastShownLine = line;
}
}
class FakeListener implements LibraryEventListener
{
Book lastBook;
Money lastSubtotal;
public void bookAdded(Book book) {
lastBook = book;
}
public void totaled(Money total) {
lastSubtotal = total;
}
}
public class LibraryTest {
FakeDisplay display;
Monitor listener;
Library library;
@Before
public void setUp() {
display = new FakeDisplay();
listener = new Monitor(display);
library = new Library(listener);
}
@Test
public void canAddTestDrivenDevelopmentByExample() {
FakeListener listener = new FakeListener();
library = new Library(listener);
library.checkoutBook("0321146530");
assertEquals(3835, listener.lastBook.getPrice().getCents());
assertEquals("Test Driven Development By Example", listener.lastBook.getName());
}
@Test
public void canAddRefactoring() {
library.checkoutBook("0201485672");
assertEquals("Refactoring $47.84", display.lastShownLine);
}
@Test
public void canAddGoosBook() {
library.checkoutBook("0321503627");
assertEquals("Growing the Object Oriented Design, Guided by Test $47.98", display.lastShownLine);
}
@Test
public void canSubtotalACheckout() {
library.checkoutBook("0321146530");
library.checkoutBook("0201485672");
library.totalPrice();
assertEquals("Subtotal $86.19", display.lastShownLine);
}
@Ignore @Test(expected = NotExistingIsbnException.class)
public void not_existing_isbn() {
library.checkoutBook("notExistingIsbn");
fail();
}
@Test
public void total_on_not_existing_isbn() {
library.checkoutBook("notExistingIsbn");
library.totalPrice();
assertEquals("Subtotal $0.00", display.lastShownLine);
}
@Test
public void total_count_on_not_existing_isbn() {
library.checkoutBook("notExistingIsbn");
assertEquals(0, library.totalCount());
}
}