Added tests for controller.getObservations.
This commit is contained in:
parent
fbf963b99e
commit
a0ae8803be
@ -99,4 +99,73 @@ class ControllerTest {
|
|||||||
val result = controller.addObservation(newData)
|
val result = controller.addObservation(newData)
|
||||||
assertEquals(1L, result)
|
assertEquals(1L, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGetObservations_SiteAndTutorNull() {
|
||||||
|
val request = ObservationsRequest(null, null, "", LocalDate.now(), LocalDate.now())
|
||||||
|
val result = controller.getObservations(request)
|
||||||
|
assertTrue(result.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGetObservations_WithSite_TutorNull_NoWhom() {
|
||||||
|
val request = ObservationsRequest(1, null, "", LocalDate.now(), LocalDate.now())
|
||||||
|
val site = Site(1, "Area 51")
|
||||||
|
val observation = Observation(site = site, date = LocalDate.now(),
|
||||||
|
type = TrainingType.INITIAL, observed = "1", whom = "G1", monitoring = 5.0,
|
||||||
|
control = 4.0, conservatism = 3.0, teamwork = 2.0, knowledge = 1.0, entries = listOf(), tutors = setOf())
|
||||||
|
doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
|
doReturn(listOf(observation))
|
||||||
|
.`when`(observationRepository).findBySiteAndDateBetween(site, LocalDate.now(), LocalDate.now())
|
||||||
|
val result = controller.getObservations(request)
|
||||||
|
assertEquals(1, result.size)
|
||||||
|
assertEquals(observation, result[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGetObservations_WithSite_TutorNull_WithWhom() {
|
||||||
|
val request = ObservationsRequest(1, null, "Group A", LocalDate.now(), LocalDate.now())
|
||||||
|
val site = Site(1, "Area 51")
|
||||||
|
val observation = Observation(site = site, date = LocalDate.now(),
|
||||||
|
type = TrainingType.INITIAL, observed = "1", whom = "Group A", monitoring = 5.0,
|
||||||
|
control = 4.0, conservatism = 3.0, teamwork = 2.0, knowledge = 1.0, entries = listOf(), tutors = setOf())
|
||||||
|
doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
|
doReturn(listOf(observation))
|
||||||
|
.`when`(observationRepository).findBySiteAndWhomAndDateBetween(site, "Group A", LocalDate.now(), LocalDate.now())
|
||||||
|
val result = controller.getObservations(request)
|
||||||
|
assertEquals(1, result.size)
|
||||||
|
assertEquals(observation, result[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGetObservations_WithSite_WithTutor_NoWhom() {
|
||||||
|
val request = ObservationsRequest(null, 1, "", LocalDate.now(), LocalDate.now())
|
||||||
|
val site = Site(1, "Area 51")
|
||||||
|
val tutor = Tutor(1, "Mr Unknown", site)
|
||||||
|
val observation = Observation(site = site, date = LocalDate.now(),
|
||||||
|
type = TrainingType.INITIAL, observed = "1", whom = "G1", monitoring = 5.0,
|
||||||
|
control = 4.0, conservatism = 3.0, teamwork = 2.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor))
|
||||||
|
doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1)
|
||||||
|
doReturn(listOf(observation))
|
||||||
|
.`when`(observationRepository).findByTutorsAndDateBetween(tutor, LocalDate.now(), LocalDate.now())
|
||||||
|
val result = controller.getObservations(request)
|
||||||
|
assertEquals(1, result.size)
|
||||||
|
assertEquals(observation, result[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGetObservations_WithSite_WithTutor_WithWhom() {
|
||||||
|
val request = ObservationsRequest(null, 1, "Group A", LocalDate.now(), LocalDate.now())
|
||||||
|
val site = Site(1, "Area 51")
|
||||||
|
val tutor = Tutor(1, "Mr Unknown", site)
|
||||||
|
val observation = Observation(site = site, date = LocalDate.now(),
|
||||||
|
type = TrainingType.INITIAL, observed = "1", whom = "Group A", monitoring = 5.0,
|
||||||
|
control = 4.0, conservatism = 3.0, teamwork = 2.0, knowledge = 1.0, entries = listOf(), tutors = setOf(tutor))
|
||||||
|
doReturn(Optional.of(tutor)).`when`(tutorRepository).findById(1)
|
||||||
|
doReturn(listOf(observation))
|
||||||
|
.`when`(observationRepository).findByTutorsAndWhomAndDateBetween(tutor, "Group A", LocalDate.now(), LocalDate.now())
|
||||||
|
val result = controller.getObservations(request)
|
||||||
|
assertEquals(1, result.size)
|
||||||
|
assertEquals(observation, result[0])
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user