BugNote
actual and formal argument lists differ in length 에러
제뉴어리맨
2022. 9. 19. 14:53
상황
테스트에서 Post에 대한 Dto를 전송하여 Controller에 대한 슬라이스 테스트 진행 하려 함.
- 실행 코드
@WebMvcTest({MajorController.class, MajorMapper.class})
@AutoConfigureMockMvc
public class MajorControllerTest {
@Autowired
private MockMvc mockMvc;
private MediaType mediaType = MediaType.APPLICATION_JSON;
@Autowired
private Gson gson;
@Test
public void postMajorTest() throws Exception {
MajorDto.Post post = MajorDto.Post.builder().majorCode("CPS").majorName("Computer Science").build();
String content = gson.toJson(post);
ResultActions actions = mockMvc.perform(post("/v1/major")
.accept(mediaType)
.contentType(mediaType)
.content(content)
);
ResultActions result = actions.andExpect(status().isCreated());
}
}
테스트가 실행조차 안되며 컴파일 에러 발생.
- 에러 메세지
> Task :compileJava FAILED
C:\StartDream\CodeStates\WorkSpace\Spring\side-project\from-controller_to-exception_practice\src\main\java\com\practice\example\major\mapper\MajorMapper.java:11: warning: Unmapped target properties: "majorId, studentList, professorList, subjectList".
Major majorPostDtoToMajor(MajorDto.Post dto);
^
C:\StartDream\CodeStates\WorkSpace\Spring\side-project\from-controller_to-exception_practice\src\main\java\com\practice\example\major\dto\MajorDto.java:14: error: constructor Post in class Post cannot be applied to given types;
@Builder
^
required: no arguments
found: String,String
reason: actual and formal argument lists differ in length
Note: C:\StartDream\CodeStates\WorkSpace\Spring\side-project\from-controller_to-exception_practice\src\main\java\com\practice\example\major\controller\MajorController.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
1 warning
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
1 actionable task: 1 executed
에러 내용
뭔가 맵핑 부분에서 에러가 나는것 처럼 보였다.
에러 라인이 모두 맵핑과 관련된 라인이였기 때문이다.
원인
@Builder를 쓰는 Dto에
@AllArgsConstructor 가 없어서.
해결 방법
원인이 되는것으로 추정 되는, @Builder를 쓰는 Dto에 @AllArgsConstructor 추가
결과
해결