본문 바로가기

Back-End (web)50

[Intellij][warning] Following modules override project settings Kotlin Compiler 에서 위와 같은 warning이 표시. .idea > modules > xxx.iml 파일에서 useProjectSettings="False" -> "true" 로 변경. 2019. 6. 12.
[SPRING] Controller redirect @GetMapping("main") public String main() { if(특정조건){ "redirect:fail"; // '/fail' path로 리다이렉트 } return "main"; } 특정조건인 경우 특정 path로 redirect 하게 해준다. @GetMapping("main") public String main() { if(특정조건) { return "fail"; // fail.jsp 반환 } return "main"; } 특정조건인 경우 특정 페이지를 내려준다. (이 경우는 리다이렉트가 아님) 2019. 5. 30.
Spock 테스트 정리 Spock으로 테스트코드를 짜보자 (Spock)[http://kwonnam.pe.kr/wiki/java/spock] spock test 예시 when - then @SpringBootTest class apiServiceSpecTest extends Specification { @Autowired ApiService apiService int productNo = 100 int size = 100 def "getProductNames 테스트"() { when: List result = apiService.getProductNames(productNo, size) then: result[0] == "name1" } } expect expect = when + then def "getProductNames .. 2019. 5. 23.
[spring] webClient error 처리 기존코드 WebClient.create().get() .uri("http://~~~") .retrieve() .bodyToMono(CustomResponse::class.java) .onErrorMap { e -> log.error(e.message) e // return e } .map { // return } CustomResponse 타입의 body를 가져와서 처리한다. 에러가 발생하는 경우(4xx, 5xx) onErrorMap이 에러를 캐치해서 log.error로 해당에러를 찍는다. WebClient.create().get() .uri("http://~~~~") .exchange() .flatMap { response -> // get header val header = response.heade.. 2019. 5. 8.
[Error] Mockito cannot mock/spy because: final class org.mockito.exceptions.base.MockitoException: Cannot mock/spy class com.example.study.AuthServiceTest$UserRepository Mockito cannot mock/spy because : - final class 위와 같은 에러 발생. Mockito cannot mock/spy because : - final class // build.gradle dependencies { // ... testImplementation 'org.mockito:mockito-inline:2.13.0' // add } build.gradle에 mockito-inline을 추가. 참고 : How to mock a final class with .. 2019. 4. 15.
[Kotlin] If 문 Type mismatch null이 가능한 변수인 경우 if문 안에 조건문이 true, false, null 3가지가 올 수 있기 때문에 위와 같이 status 만 적으면 Type mismatch 에러가 난다. 이를 해결하려면 위와 같이 조건문에 true라고 명시적으로 적어주면 된다. 2019. 3. 25.