@PostMapping
public ResponseEntity createEvent(@RequestBody @Valid EventDto eventDto, Errors errors){
if (errors.hasErrors()){ // 바인딩할때 검증과 관련된 오류가 발생하면 동작
return ResponseEntity.badRequest().build();
}
.
.
.
@Test
@DisplayName("빈값을 입력했을때 에러가 발생하는 테스트")
void createEvent_Bad_Request_Empty_Input() throws Exception{
EventDto eventDto = EventDto.builder().build();
this.mockMvc.perform(post("/api/events")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(eventDto))
)
.andExpect(status().isBadRequest());
}
해당 컨트롤러에 대한 테스트를 실행하면 계속 is marked non-null but is null errors이라는 예외가 발생
import com.sun.istack.NotNull; // 누구세요..?
@Data
@NoArgsConstructor @AllArgsConstructor
@Builder
public class EventDto {
@NotNull
private String name;
import javax.validation.constraints.NotNull; 을 import해야했지만 잘못 import하여 발생한 어이없는 오류.. 다음부터 실수하지 않기 위해 기록합니다..