공부/토비의 스프링 3.1
assertThat(set.translate(null, null, sqlEx), is(DuplicateKeyException.class));
이사쿠
2019. 3. 23. 01:04
토비의 스프링 3.1 - 4장 예외 실습 중 한 구문(p314)이 자꾸 빨간줄이 떴다.
assertThat(set.translate(null, null, sqlEx), is(DuplicateKeyException.class));
내용은 "Wrong 1st argument type." T type의 아규먼트가 들어와야 하는데 DataAccessException type의 아규먼트가 들어왔다는 것이다.
다른 junit 라이브러리를 import 하기도 했지만 달라진 건 없었다. 검색해보니 junit 버전에 따라 assertThat이 요구하는 아규먼트가 다른 것 같은데(본인은 junit 4.12 사용중) 위와 같을 땐 is 대신 instanceOf를 사용하면 된다고 한다.
assertThat(set.translate(null, null, sqlEx), instanceOf(DuplicateKeyException.class));
출처: https://hwanud.wordpress.com/2019/01/13/토비의-스프링-테스트-코드-junit5-로-적용하기/