Skip to content
Snippets Groups Projects
Commit 7cfd371c authored by Petr Seidl's avatar Petr Seidl
Browse files

Update added tests for gpa filters

parent f7a7b5a4
No related branches found
No related tags found
No related merge requests found
Pipeline #108161 passed
......@@ -12,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
 
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
 
......@@ -72,6 +73,16 @@ class StudentServiceImplTest {
 
}
 
@Test
void findByGpa() {
List<Student> students = Collections.singletonList(
new Student(1, "Ted", "Parker", 4.2)
);
BDDMockito.given(studentRepository.findByGpa(4.2)).willReturn(students);
Assertions.assertEquals(students,studentService.findByGpa(4.2));
Mockito.verify(studentRepository,Mockito.atLeastOnce()).findByGpa(4.2);
}
@Test
void findByGpaLessThan() {
List<Student> lessGpaStudents = Arrays.asList(
......
......@@ -89,6 +89,19 @@ class StudentControllerTest {
Mockito.verify(studentService,Mockito.atLeastOnce()).findAll();
}
 
@Test
void findByGpa() throws Exception {
List<Student> result = Collections.singletonList(
new Student(1,"Ted","Parker",4.3)
);
BDDMockito.given(studentService.findByGpa(4.3)).willReturn(result);
mvc.perform(MockMvcRequestBuilders.get("/api/v1/student/gpa/4.3")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.*.id",CoreMatchers.equalTo(Collections.singletonList(1))));
Mockito.verify(studentService, Mockito.atLeastOnce()).findByGpa(4.3);
}
@Test
void findByGpaGreaterThan() throws Exception {
List<Student> result = Collections.singletonList(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment