bugfix for RunWith(SpringBootRunner.class) missing

This commit is contained in:
aisensiy 2017-10-27 13:30:26 +08:00
parent 31f96d1f2c
commit dda5babcb7
2 changed files with 7 additions and 2 deletions

View File

@ -6,13 +6,16 @@ import io.spring.core.user.User;
import io.spring.core.user.UserRepository; import io.spring.core.user.UserRepository;
import io.spring.infrastructure.mybatis.readservice.UserReadService; import io.spring.infrastructure.mybatis.readservice.UserReadService;
import org.junit.Before; import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Optional; import java.util.Optional;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(SpringRunner.class)
abstract class TestWithCurrentUser { abstract class TestWithCurrentUser {
@MockBean @MockBean
protected UserRepository userRepository; protected UserRepository userRepository;

View File

@ -12,10 +12,12 @@ import io.spring.infrastructure.mybatis.readservice.UserReadService;
import io.spring.infrastructure.service.NaiveEncryptService; import io.spring.infrastructure.service.NaiveEncryptService;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import java.util.HashMap; import java.util.HashMap;
@ -29,6 +31,7 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(SpringRunner.class)
@WebMvcTest(UsersApi.class) @WebMvcTest(UsersApi.class)
@Import({WebSecurityConfig.class, UserQueryService.class, NaiveEncryptService.class, JacksonCustomizations.class}) @Import({WebSecurityConfig.class, UserQueryService.class, NaiveEncryptService.class, JacksonCustomizations.class})
public class UsersApiTest { public class UsersApiTest {
@ -48,7 +51,6 @@ public class UsersApiTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
RestAssuredMockMvc.mockMvc(mvc); RestAssuredMockMvc.mockMvc(mvc);
defaultAvatar = "https://static.productionready.io/images/smiley-cyrus.jpg"; defaultAvatar = "https://static.productionready.io/images/smiley-cyrus.jpg";
} }
@ -238,4 +240,4 @@ public class UsersApiTest {
.statusCode(422) .statusCode(422)
.body("errors.password[0]", equalTo("invalid email or password")); .body("errors.password[0]", equalTo("invalid email or password"));
} }
} }