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

Update added filter for gpa

parent c38ac43e
No related branches found
No related tags found
No related merge requests found
......@@ -48,6 +48,16 @@ public class StudentController {
return studentService.findAllByLastName(lastName).stream().map(this::toDTO).collect(Collectors.toList());
}
 
@GetMapping("/gpa/less")
public List<StudentDTO> findByGpaLessThan(@RequestParam double gpa) {
return studentService.findByGpaLessThan(gpa).stream().map(this::toDTO).collect(Collectors.toList());
}
@GetMapping("/gpa/greater")
public List<StudentDTO> findByGpaGreaterThan(@RequestParam double gpa) {
return studentService.findByGpaGreaterThan(gpa).stream().map(this::toDTO).collect(Collectors.toList());
}
@PutMapping("/{id}")
public void update(@PathVariable int id, @RequestBody StudentCreateDTO student) {
try {
......
......@@ -79,9 +79,9 @@ class StudentServiceImplTest {
new Student(3,"Test","Student",1.5),
new Student(4,"Test","Student",2.6)
);
BDDMockito.given(studentRepository.findByGpaGreaterThan(3)).willReturn(lessGpaStudents);
Assertions.assertEquals(lessGpaStudents,studentService.findByGpaGreaterThan(3));
Mockito.verify(studentRepository,Mockito.atLeastOnce()).findByGpaGreaterThan(3);
BDDMockito.given(studentRepository.findByGpaLessThan(3)).willReturn(lessGpaStudents);
Assertions.assertEquals(lessGpaStudents,studentService.findByGpaLessThan(3));
Mockito.verify(studentRepository,Mockito.atLeastOnce()).findByGpaLessThan(3);
}
 
@Test
......
......@@ -89,6 +89,33 @@ class StudentControllerTest {
Mockito.verify(studentService,Mockito.atLeastOnce()).findAll();
}
 
@Test
void findByGpaGreaterThan() throws Exception {
List<Student> result = Collections.singletonList(
new Student(4, "Test", "Student", 2.6)
);
BDDMockito.given(studentService.findByGpaGreaterThan(1.5)).willReturn(result);
mvc.perform(MockMvcRequestBuilders.get("/api/v1/student/gpa/greater?gpa=1.5")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.*.id",CoreMatchers.equalTo(Collections.singletonList(4))));
Mockito.verify(studentService,Mockito.atLeastOnce()).findByGpaGreaterThan(1.5);
}
@Test
void findByGpaLessThan() throws Exception {
List<Student> result = Collections.singletonList(
new Student(2, "Test", "Student", 1.0)
);
BDDMockito.given(studentService.findByGpaLessThan(1.5)).willReturn(result);
mvc.perform(MockMvcRequestBuilders.get("/api/v1/student/gpa/less?gpa=1.5")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.*.id",CoreMatchers.equalTo(Collections.singletonList(2))));
Mockito.verify(studentService,Mockito.atLeastOnce()).findByGpaLessThan(1.5);
}
@Test
void update() throws Exception {
StudentCreateDTO newStudent = new StudentCreateDTO("Ted","SK",1.3);
......
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