Migrate to Mockito.mock(T...) where feasible
This commit is contained in:
@@ -53,28 +53,24 @@ class MockFilterChainTests {
|
||||
|
||||
@Test
|
||||
void constructorNullServlet() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new MockFilterChain(null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new MockFilterChain(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void constructorNullFilter() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new MockFilterChain(mock(Servlet.class), (Filter) null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new MockFilterChain(mock(), (Filter) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doFilterNullRequest() throws Exception {
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
chain.doFilter(null, this.response));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> chain.doFilter(null, this.response));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doFilterNullResponse() throws Exception {
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
chain.doFilter(this.request, null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> chain.doFilter(this.request, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,25 +81,25 @@ class MockFilterChainTests {
|
||||
assertThat(chain.getRequest()).isEqualTo(request);
|
||||
assertThat(chain.getResponse()).isEqualTo(response);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
chain.doFilter(this.request, this.response))
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> chain.doFilter(this.request, this.response))
|
||||
.withMessage("This FilterChain has already been called!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doFilterWithServlet() throws Exception {
|
||||
Servlet servlet = mock(Servlet.class);
|
||||
Servlet servlet = mock();
|
||||
MockFilterChain chain = new MockFilterChain(servlet);
|
||||
chain.doFilter(this.request, this.response);
|
||||
verify(servlet).service(this.request, this.response);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
chain.doFilter(this.request, this.response))
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> chain.doFilter(this.request, this.response))
|
||||
.withMessage("This FilterChain has already been called!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doFilterWithServletAndFilters() throws Exception {
|
||||
Servlet servlet = mock(Servlet.class);
|
||||
Servlet servlet = mock();
|
||||
|
||||
MockFilter filter2 = new MockFilter(servlet);
|
||||
MockFilter filter1 = new MockFilter(null);
|
||||
@@ -116,8 +112,8 @@ class MockFilterChainTests {
|
||||
|
||||
verify(servlet).service(this.request, this.response);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
chain.doFilter(this.request, this.response))
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> chain.doFilter(this.request, this.response))
|
||||
.withMessage("This FilterChain has already been called!");
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing
|
||||
*/
|
||||
class BootstrapUtilsTests {
|
||||
|
||||
private final CacheAwareContextLoaderDelegate delegate = mock(CacheAwareContextLoaderDelegate.class);
|
||||
private final CacheAwareContextLoaderDelegate delegate = mock();
|
||||
|
||||
@Test
|
||||
void resolveTestContextBootstrapperWithEmptyBootstrapWithAnnotation() {
|
||||
|
||||
@@ -407,7 +407,7 @@ class MergedContextConfigurationTests {
|
||||
*/
|
||||
@Test
|
||||
void equalsWithSameContextCustomizers() {
|
||||
Set<ContextCustomizer> customizers = Collections.singleton(mock(ContextCustomizer.class));
|
||||
Set<ContextCustomizer> customizers = Collections.singleton(mock());
|
||||
MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers, loader, null, null);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
@@ -420,8 +420,8 @@ class MergedContextConfigurationTests {
|
||||
*/
|
||||
@Test
|
||||
void equalsWithDifferentContextCustomizers() {
|
||||
Set<ContextCustomizer> customizers1 = Collections.singleton(mock(ContextCustomizer.class));
|
||||
Set<ContextCustomizer> customizers2 = Collections.singleton(mock(ContextCustomizer.class));
|
||||
Set<ContextCustomizer> customizers1 = Collections.singleton(mock());
|
||||
Set<ContextCustomizer> customizers2 = Collections.singleton(mock());
|
||||
|
||||
MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers1, loader, null, null);
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock;
|
||||
class AotMergedContextConfigurationTests {
|
||||
|
||||
private final CacheAwareContextLoaderDelegate delegate =
|
||||
new DefaultCacheAwareContextLoaderDelegate(mock(ContextCache.class));
|
||||
new DefaultCacheAwareContextLoaderDelegate(mock());
|
||||
|
||||
private final ContextLoader contextLoader = new DelegatingSmartContextLoader();
|
||||
|
||||
|
||||
@@ -49,10 +49,10 @@ class LruContextCacheTests {
|
||||
private static final MergedContextConfiguration bazConfig = config(Baz.class);
|
||||
|
||||
|
||||
private final ConfigurableApplicationContext abcContext = mock(ConfigurableApplicationContext.class);
|
||||
private final ConfigurableApplicationContext fooContext = mock(ConfigurableApplicationContext.class);
|
||||
private final ConfigurableApplicationContext barContext = mock(ConfigurableApplicationContext.class);
|
||||
private final ConfigurableApplicationContext bazContext = mock(ConfigurableApplicationContext.class);
|
||||
private final ConfigurableApplicationContext abcContext = mock();
|
||||
private final ConfigurableApplicationContext fooContext = mock();
|
||||
private final ConfigurableApplicationContext barContext = mock();
|
||||
private final ConfigurableApplicationContext bazContext = mock();
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -232,7 +232,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public TestExecutionListener listener() {
|
||||
return mock(TestExecutionListener.class);
|
||||
return mock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,10 +19,8 @@ package org.springframework.test.context.jdbc;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.AnnotationConfigurationException;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.jdbc.SqlConfig.TransactionMode;
|
||||
|
||||
@@ -42,7 +40,7 @@ class SqlScriptsTestExecutionListenerTests {
|
||||
|
||||
private final SqlScriptsTestExecutionListener listener = new SqlScriptsTestExecutionListener();
|
||||
|
||||
private final TestContext testContext = mock(TestContext.class);
|
||||
private final TestContext testContext = mock();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -78,9 +76,9 @@ class SqlScriptsTestExecutionListenerTests {
|
||||
|
||||
@Test
|
||||
void isolatedTxModeDeclaredWithoutTxMgr() throws Exception {
|
||||
ApplicationContext ctx = mock(ApplicationContext.class);
|
||||
given(ctx.getResource(anyString())).willReturn(mock(Resource.class));
|
||||
given(ctx.getAutowireCapableBeanFactory()).willReturn(mock(AutowireCapableBeanFactory.class));
|
||||
ApplicationContext ctx = mock();
|
||||
given(ctx.getResource(anyString())).willReturn(mock());
|
||||
given(ctx.getAutowireCapableBeanFactory()).willReturn(mock());
|
||||
|
||||
Class<?> clazz = IsolatedWithoutTxMgr.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
@@ -92,9 +90,9 @@ class SqlScriptsTestExecutionListenerTests {
|
||||
|
||||
@Test
|
||||
void missingDataSourceAndTxMgr() throws Exception {
|
||||
ApplicationContext ctx = mock(ApplicationContext.class);
|
||||
given(ctx.getResource(anyString())).willReturn(mock(Resource.class));
|
||||
given(ctx.getAutowireCapableBeanFactory()).willReturn(mock(AutowireCapableBeanFactory.class));
|
||||
ApplicationContext ctx = mock();
|
||||
given(ctx.getResource(anyString())).willReturn(mock());
|
||||
given(ctx.getAutowireCapableBeanFactory()).willReturn(mock());
|
||||
|
||||
Class<?> clazz = MissingDataSourceAndTxMgr.class;
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
|
||||
|
||||
@@ -111,10 +111,10 @@ class DisabledIfConditionTests {
|
||||
private ExtensionContext buildExtensionContext(String methodName) {
|
||||
Class<?> testClass = SpringTestCase.class;
|
||||
Method method = ReflectionUtils.findMethod(getClass(), methodName);
|
||||
Store store = mock(Store.class);
|
||||
Store store = mock();
|
||||
given(store.getOrComputeIfAbsent(any(), any(), any())).willReturn(new TestContextManager(testClass));
|
||||
|
||||
ExtensionContext extensionContext = mock(ExtensionContext.class);
|
||||
ExtensionContext extensionContext = mock();
|
||||
given(extensionContext.getTestClass()).willReturn(Optional.of(testClass));
|
||||
given(extensionContext.getElement()).willReturn(Optional.of(method));
|
||||
given(extensionContext.getStore(any())).willReturn(store);
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class SpringFailOnTimeoutTests {
|
||||
|
||||
private final Statement statement = mock(Statement.class);
|
||||
private final Statement statement = mock();
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,8 +23,6 @@ import java.lang.annotation.Target;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
@@ -42,6 +40,7 @@ import org.springframework.test.context.TestContextBootstrapper;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.assertj.core.api.SoftAssertions.assertSoftly;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration.INHERIT;
|
||||
import static org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration.OVERRIDE;
|
||||
|
||||
@@ -63,7 +62,7 @@ abstract class AbstractContextConfigurationUtilsTests {
|
||||
|
||||
|
||||
MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass) {
|
||||
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = Mockito.mock(CacheAwareContextLoaderDelegate.class);
|
||||
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = mock();
|
||||
BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext(testClass, cacheAwareContextLoaderDelegate);
|
||||
TestContextBootstrapper bootstrapper = BootstrapTestUtils.resolveTestContextBootstrapper(bootstrapContext);
|
||||
return bootstrapper.buildMergedContextConfiguration();
|
||||
|
||||
@@ -59,7 +59,7 @@ class DirtiesContextTestExecutionListenerTests {
|
||||
|
||||
private final TestExecutionListener beforeListener = new DirtiesContextBeforeModesTestExecutionListener();
|
||||
private final TestExecutionListener afterListener = new DirtiesContextTestExecutionListener();
|
||||
private final TestContext testContext = mock(TestContext.class);
|
||||
private final TestContext testContext = mock();
|
||||
|
||||
|
||||
@Nested
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -63,7 +62,7 @@ class DynamicPropertiesContextCustomizerTests {
|
||||
DynamicPropertiesContextCustomizer customizer = customizerFor("nullName");
|
||||
ConfigurableApplicationContext context = new StaticApplicationContext();
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> customizer.customizeContext(context, mock(MergedContextConfiguration.class)))
|
||||
.isThrownBy(() -> customizer.customizeContext(context, mock()))
|
||||
.withMessage("'name' must not be null or blank");
|
||||
}
|
||||
|
||||
@@ -72,7 +71,7 @@ class DynamicPropertiesContextCustomizerTests {
|
||||
DynamicPropertiesContextCustomizer customizer = customizerFor("emptyName");
|
||||
ConfigurableApplicationContext context = new StaticApplicationContext();
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> customizer.customizeContext(context, mock(MergedContextConfiguration.class)))
|
||||
.isThrownBy(() -> customizer.customizeContext(context, mock()))
|
||||
.withMessage("'name' must not be null or blank");
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ class DynamicPropertiesContextCustomizerTests {
|
||||
DynamicPropertiesContextCustomizer customizer = customizerFor("nullValueSupplier");
|
||||
ConfigurableApplicationContext context = new StaticApplicationContext();
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> customizer.customizeContext(context, mock(MergedContextConfiguration.class)))
|
||||
.isThrownBy(() -> customizer.customizeContext(context, mock()))
|
||||
.withMessage("'valueSupplier' must not be null");
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ class DynamicPropertiesContextCustomizerTests {
|
||||
void customizeContextAddsPropertySource() throws Exception {
|
||||
ConfigurableApplicationContext context = new StaticApplicationContext();
|
||||
DynamicPropertiesContextCustomizer customizer = customizerFor("valid1", "valid2");
|
||||
customizer.customizeContext(context, mock(MergedContextConfiguration.class));
|
||||
customizer.customizeContext(context, mock());
|
||||
ConfigurableEnvironment environment = context.getEnvironment();
|
||||
assertThat(environment.getRequiredProperty("p1a")).isEqualTo("v1a");
|
||||
assertThat(environment.getRequiredProperty("p1b")).isEqualTo("v1b");
|
||||
|
||||
@@ -191,7 +191,7 @@ class TestPropertySourceUtilsTests {
|
||||
@Test
|
||||
void addPropertiesFilesToEnvironmentWithNullEnvironment() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> addPropertiesFilesToEnvironment((ConfigurableEnvironment) null, mock(ResourceLoader.class), FOO_LOCATIONS))
|
||||
.isThrownBy(() -> addPropertiesFilesToEnvironment((ConfigurableEnvironment) null, mock(), FOO_LOCATIONS))
|
||||
.withMessageContaining("'environment' must not be null");
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ class TestPropertySourceUtilsTests {
|
||||
@Test
|
||||
void addPropertiesFilesToEnvironmentWithEnvironmentAndNullLocations() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> addPropertiesFilesToEnvironment(new MockEnvironment(), mock(ResourceLoader.class), (String[]) null))
|
||||
.isThrownBy(() -> addPropertiesFilesToEnvironment(new MockEnvironment(), mock(), (String[]) null))
|
||||
.withMessageContaining("'locations' must not be null");
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ class TestPropertySourceUtilsTests {
|
||||
|
||||
String pair = "key = value";
|
||||
ByteArrayResource resource = new ByteArrayResource(pair.getBytes(), "from inlined property: " + pair);
|
||||
ResourceLoader resourceLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader resourceLoader = mock();
|
||||
given(resourceLoader.getResource(anyString())).willReturn(resource);
|
||||
|
||||
addPropertiesFilesToEnvironment(environment, resourceLoader, FOO_LOCATIONS);
|
||||
|
||||
@@ -49,7 +49,7 @@ import static org.springframework.transaction.annotation.Propagation.REQUIRED;
|
||||
*/
|
||||
class TransactionalTestExecutionListenerTests {
|
||||
|
||||
private final PlatformTransactionManager tm = mock(PlatformTransactionManager.class);
|
||||
private final PlatformTransactionManager tm = mock();
|
||||
|
||||
private final TransactionalTestExecutionListener listener = new TransactionalTestExecutionListener() {
|
||||
@Override
|
||||
@@ -58,7 +58,7 @@ class TransactionalTestExecutionListenerTests {
|
||||
}
|
||||
};
|
||||
|
||||
private final TestContext testContext = mock(TestContext.class);
|
||||
private final TestContext testContext = mock();
|
||||
|
||||
|
||||
@AfterEach
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
@@ -49,9 +48,9 @@ class ServletTestExecutionListenerTests {
|
||||
|
||||
private static final String SET_UP_OUTSIDE_OF_STEL = "setUpOutsideOfStel";
|
||||
|
||||
private final WebApplicationContext wac = mock(WebApplicationContext.class);
|
||||
private final WebApplicationContext wac = mock();
|
||||
private final MockServletContext mockServletContext = new MockServletContext();
|
||||
private final TestContext testContext = mock(TestContext.class);
|
||||
private final TestContext testContext = mock();
|
||||
private final ServletTestExecutionListener listener = new ServletTestExecutionListener();
|
||||
|
||||
|
||||
@@ -73,7 +72,7 @@ class ServletTestExecutionListenerTests {
|
||||
@Test
|
||||
void standardApplicationContext() throws Exception {
|
||||
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(getClass());
|
||||
given(testContext.getApplicationContext()).willReturn(mock(ApplicationContext.class));
|
||||
given(testContext.getApplicationContext()).willReturn(mock());
|
||||
|
||||
listener.beforeTestClass(testContext);
|
||||
assertSetUpOutsideOfStelAttributeExists();
|
||||
|
||||
@@ -105,7 +105,7 @@ class DefaultResponseCreatorTests {
|
||||
@Test
|
||||
void setBodyFromResource() throws IOException {
|
||||
byte[] resourceContent = {7, 14, 21, 28, 35};
|
||||
Resource resource = mock(Resource.class);
|
||||
Resource resource = mock();
|
||||
given(resource.getInputStream()).willReturn(new ByteArrayInputStream(resourceContent));
|
||||
|
||||
ClientHttpResponse response = createResponse(new DefaultResponseCreator(HttpStatus.OK).body(resource));
|
||||
|
||||
@@ -53,7 +53,7 @@ class ExecutingResponseCreatorTests {
|
||||
@Test
|
||||
void ensureRequestIsMock() {
|
||||
final ExecutingResponseCreator responseCreator = new ExecutingResponseCreator((uri, method) -> null);
|
||||
ClientHttpRequest notAMockRequest = mock(ClientHttpRequest.class);
|
||||
ClientHttpRequest notAMockRequest = mock();
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> responseCreator.createResponse(notAMockRequest))
|
||||
|
||||
@@ -131,7 +131,7 @@ public class CookieAssertionTests {
|
||||
ExchangeResult result = new ExchangeResult(
|
||||
request, response, Mono.empty(), Mono.empty(), Duration.ZERO, null, null);
|
||||
|
||||
return new CookieAssertions(result, mock(WebTestClient.ResponseSpec.class));
|
||||
return new CookieAssertions(result, mock());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ class HeaderAssertionTests {
|
||||
ExchangeResult result = new ExchangeResult(
|
||||
request, response, Mono.empty(), Mono.empty(), Duration.ZERO, null, null);
|
||||
|
||||
return new HeaderAssertions(result, mock(WebTestClient.ResponseSpec.class));
|
||||
return new HeaderAssertions(result, mock());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ class StatusAssertionTests {
|
||||
ExchangeResult result = new ExchangeResult(
|
||||
request, response, Mono.empty(), Mono.empty(), Duration.ZERO, null, null);
|
||||
|
||||
return new StatusAssertions(result, mock(WebTestClient.ResponseSpec.class));
|
||||
return new StatusAssertions(result, mock());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,13 +26,10 @@ import com.gargoylesoftware.htmlunit.WebResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -52,13 +49,11 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.2
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration
|
||||
@WebAppConfiguration
|
||||
@SpringJUnitWebConfig
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class MockMvcConnectionBuilderSupportTests {
|
||||
|
||||
private final WebClient client = mock(WebClient.class);
|
||||
private final WebClient client = mock();
|
||||
|
||||
private MockMvcWebConnectionBuilderSupport builder;
|
||||
|
||||
@@ -68,7 +63,7 @@ public class MockMvcConnectionBuilderSupportTests {
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
given(this.client.getWebConnection()).willReturn(mock(WebConnection.class));
|
||||
given(this.client.getWebConnection()).willReturn(mock());
|
||||
this.builder = new MockMvcWebConnectionBuilderSupport(this.wac) {};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -45,6 +43,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
import static java.nio.charset.StandardCharsets.UTF_16;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PrintingResultHandler}.
|
||||
@@ -128,7 +127,7 @@ class PrintingResultHandlerTests {
|
||||
String palindrome = "ablE was I ere I saw Elba";
|
||||
byte[] bytes = palindrome.getBytes(UTF_16);
|
||||
this.request.setContent(bytes);
|
||||
this.request.setSession(Mockito.mock(HttpSession.class));
|
||||
this.request.setSession(mock());
|
||||
|
||||
this.handler.handle(this.mvcResult);
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* {@link MockMvcWebTestClient} equivalent of the MockMvc
|
||||
@@ -97,7 +98,7 @@ public class AsyncControllerJavaConfigTests {
|
||||
|
||||
@Bean
|
||||
public CallableProcessingInterceptor callableInterceptor() {
|
||||
return Mockito.mock(CallableProcessingInterceptor.class);
|
||||
return mock();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.test.web.servlet.samples.client.context;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -42,6 +41,7 @@ import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* {@link MockMvcWebTestClient} equivalent of the MockMvc
|
||||
@@ -88,7 +88,7 @@ class JavaConfigTests {
|
||||
|
||||
@Bean
|
||||
PersonDao personDao() {
|
||||
return Mockito.mock(PersonDao.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ public class FrameworkExtensionTests {
|
||||
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder,
|
||||
WebApplicationContext context) {
|
||||
return request -> {
|
||||
request.setUserPrincipal(mock(Principal.class));
|
||||
request.setUserPrincipal(mock());
|
||||
return request;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
@@ -111,7 +112,7 @@ public class AsyncControllerJavaConfigTests {
|
||||
|
||||
@Bean
|
||||
public CallableProcessingInterceptor callableInterceptor() {
|
||||
return Mockito.mock(CallableProcessingInterceptor.class);
|
||||
return mock();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -20,7 +20,6 @@ import jakarta.servlet.ServletContext;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -46,6 +45,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
@@ -160,7 +160,7 @@ public class JavaConfigTests {
|
||||
|
||||
@Bean
|
||||
public PersonDao personDao() {
|
||||
return Mockito.mock(PersonDao.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ public class FrameworkExtensionTests {
|
||||
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder,
|
||||
WebApplicationContext context) {
|
||||
return request -> {
|
||||
request.setUserPrincipal(mock(Principal.class));
|
||||
request.setUserPrincipal(mock());
|
||||
return request;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user