-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVeterinaryPracticeConsoleViewTest.kt
More file actions
197 lines (163 loc) · 6.43 KB
/
VeterinaryPracticeConsoleViewTest.kt
File metadata and controls
197 lines (163 loc) · 6.43 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package view
import com.google.common.truth.Truth.assertThat
import database.entity.CustomerEntity
import database.entity.PetEntity
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.RelaxedMockK
import io.mockk.verify
import org.junit.Before
import org.junit.Test
import presenter.Presenter
import java.io.ByteArrayOutputStream
import java.io.PrintStream
class VeterinaryPracticeConsoleViewTest {
@RelaxedMockK
lateinit var mockPresenter: Presenter
private val outputStreamCaptor = ByteArrayOutputStream()
private lateinit var subject: VeterinaryPracticeConsoleView
@Before
fun setUp() {
MockKAnnotations.init(this)
System.setOut(PrintStream(outputStreamCaptor))
subject = VeterinaryPracticeConsoleView(mockPresenter).apply {
startProgram("src/main/resources/vet_patient_file_happy_path_1.txt")
}
}
@Test
fun `startProgram() - verify presenter setupWithView() and start() functions are called`() {
//given
val fileName = "some_file_name.txt"
//when
subject.startProgram(fileName)
//then
verify { mockPresenter.setupWithView(subject) }
verify { mockPresenter.start(fileName) }
}
@Test
fun `searchProgram() - verify presenter search function is called`() {
//given
val searchQuery = "query"
//when
subject.searchProgram(searchQuery)
//then
verify { mockPresenter.search(searchQuery) }
}
@Test
fun `showCustomers() - given customer information then customer details are printed`() {
//when
subject.showQueryResult(customers = listOf(singleCustomerEntity), pets = emptyList())
//then
assertThat(
outputStreamCaptor.toString().trim()
).isEqualTo(
"Customer: ${singleCustomerEntity.customer}\n" +
"Identifier: ${singleCustomerEntity.identifier}\n" +
"Pets: ${singleCustomerEntity.pets}"
)
}
@Test
fun `showCustomers() - given list of customer information then customer details are printed`() {
//when
subject.showQueryResult(customers = customerEntities, pets = emptyList())
//then
assertThat(
outputStreamCaptor.toString().trim()
).isEqualTo(
"Customer: ${customerEntities[0].customer}\n" +
"Identifier: ${customerEntities[0].identifier}\n" +
"Pets: ${customerEntities[0].pets}\n" +
"\n" +
"Customer: ${customerEntities[1].customer}\n" +
"Identifier: ${customerEntities[1].identifier}\n" +
"Pets: ${customerEntities[1].pets}"
)
}
@Test
fun `showPets() - given pet information then the pet details are printed`() {
//when
subject.showQueryResult(customers = emptyList(), pets = listOf(singlePetEntity))
//then
assertThat(
outputStreamCaptor.toString().trim()
).isEqualTo(
"Pet: ${singlePetEntity.pet}\n" +
"Type: ${singlePetEntity.type}\n" +
"Identifier: ${singlePetEntity.identifier}\n" +
"Owner: ${singlePetEntity.owner}\n" +
"Owner ID: ${singlePetEntity.ownerId}"
)
}
@Test
fun `showPets() - given list of pet information then pet details are printed`() {
//when
subject.showQueryResult(customers = emptyList(), pets = petEntities)
//then
assertThat(
outputStreamCaptor.toString().trim()
).isEqualTo(
"Pet: ${petEntities[0].pet}\n" +
"Type: ${petEntities[0].type}\n" +
"Identifier: ${petEntities[0].identifier}\n" +
"Owner: ${petEntities[0].owner}\n" +
"Owner ID: ${petEntities[0].ownerId}\n" +
"\n" +
"Pet: ${petEntities[1].pet}\n" +
"Type: ${petEntities[1].type}\n" +
"Identifier: ${petEntities[1].identifier}\n" +
"Owner: ${petEntities[1].owner}\n" +
"Owner ID: ${petEntities[1].ownerId}"
)
}
@Test
fun `showCustomersAndPets() - given customer and pet information then customer and pet details are printed`() {
//when
subject.showQueryResult(listOf(singleCustomerEntity), listOf(singlePetEntity))
//then
assertThat(
outputStreamCaptor.toString().trim()
).isEqualTo(
"Customer: ${customerEntities[0].customer}\n" +
"Identifier: ${customerEntities[0].identifier}\n" +
"Pets: ${customerEntities[0].pets}\n" +
"\n" +
"Pet: ${singlePetEntity.pet}\n" +
"Type: ${singlePetEntity.type}\n" +
"Identifier: ${singlePetEntity.identifier}\n" +
"Owner: ${singlePetEntity.owner}\n" +
"Owner ID: ${singlePetEntity.ownerId}"
)
}
@Test
fun `showInvalidErrorMessage() - called with line as reference then message printed that includes line number`() {
//when
subject.showInvalidErrorMessage(1)
//then
assertThat(outputStreamCaptor.toString().trim()).isEqualTo("Error on line 1: Invalid syntax")
}
@Test
fun `showErrorOnLineWithMessage() - called with line number and error message passed as reference then message printed that includes line number and message`() {
//when
subject.showErrorOnLineWithMessage(1, "error message")
//then
assertThat(outputStreamCaptor.toString().trim()).isEqualTo("Error on line 1: error message")
}
@Test
fun `showError - called with error message passed a reference then message is printed`() {
//when
subject.showError("error message")
//then
assertThat(outputStreamCaptor.toString().trim()).isEqualTo("error message")
}
private companion object {
val singleCustomerEntity = CustomerEntity("Albert", "1", "Johnny")
val customerEntities = listOf(
singleCustomerEntity,
CustomerEntity("Hugo", "2", "Malt")
)
val singlePetEntity = PetEntity("Johnny", "Fish", "1", "Albert", "1")
val petEntities = listOf(
singlePetEntity,
PetEntity("Malt", "Dog", "2", "Hugo", "2")
)
}
}