작성
·
407
0
11분 40초 쯤에서
then(javaMailSender).should().send(any(SimpleMailMessage.class));
이 부분에서 then이 임포트가 되지 않습니다..
org.mockito.core 를 따로 쳐서 임포트 해보려 했지만
뜨지 않습니다.
전체코드입니다.
package com.wook.demo.account;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import org.mockito.configuration.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito.Then;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.web.servlet.MockMvc;
@SpringBootTest
@AutoConfigureMockMvc
public class AccountControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private AccountRepository accountRepository;
@MockBean
private JavaMailSender javaMailSender;
@DisplayName("회원 가입 화면 보이는지 테스트")
@Test
void signpForm() throws Exception {
mockMvc.perform(get("/sign-up"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("account/sign-up"))
.andExpect(model().attributeExists("signUpForm"));
}
@DisplayName("회원 가입 처리 - 입력값 오류")
@Test
void signUpSubmit_with_wrong_input() throws Exception {
mockMvc.perform(post("/sign-up")
.param("nickname", "shinwook")
.param("email", "email...")
.param("password", "12345")
.with(csrf()))
.andExpect(status().isOk())
.andExpect(view().name("account/sign-up"));
}
@DisplayName("회원 가입 처리 - 입력값 정상")
@Test
void signUpSubmit_with_correct_input() throws Exception {
mockMvc.perform(post("/sign-up")
.param("nickname", "shinwook")
.param("email", "email@naver.com")
.param("password", "12345678")
.with(csrf()))
.andExpect(status().is3xxRedirection())
.andExpect(view().name("redirect:/"));
assertTrue(accountRepository.existsByEmail("email@naver.com"));
then(javaMailSender).should().send(any(SimpleMailMessage.class));
}
}
답변 1
0
import org.mockito.BDDMockito.Then;
이 부분을 이렇게 바꿔보세요.
import static org.mockito.BDDMockito.*;