Browse Source

Migrate to Mockito.mock(T...) where feasible

pull/29868/head
Sam Brannen 2 years ago
parent
commit
c4c786596f
  1. 2
      integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java
  2. 10
      spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java
  3. 15
      spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java
  4. 10
      spring-aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java
  5. 8
      spring-aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java
  6. 8
      spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java
  7. 2
      spring-aop/src/test/java/org/springframework/aop/scope/DefaultScopedObjectTests.java
  8. 28
      spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java
  9. 8
      spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
  10. 6
      spring-beans/src/test/java/org/springframework/beans/factory/annotation/ParameterResolutionTests.java
  11. 4
      spring-beans/src/test/java/org/springframework/beans/factory/aot/AotServicesTests.java
  12. 2
      spring-beans/src/test/java/org/springframework/beans/factory/aot/AutowiredMethodArgumentsResolverTests.java
  13. 6
      spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactoryTests.java
  14. 6
      spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanInstanceSupplierTests.java
  15. 2
      spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java
  16. 2
      spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java
  17. 2
      spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java
  18. 2
      spring-beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java
  19. 4
      spring-beans/src/test/java/org/springframework/beans/factory/support/RootBeanDefinitionTests.java
  20. 11
      spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanConfigurerSupportTests.java
  21. 4
      spring-beans/src/test/java/org/springframework/beans/factory/xml/ResourceEntityResolverTests.java
  22. 2
      spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheManagerTests.java
  23. 5
      spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java
  24. 2
      spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java
  25. 4
      spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapterTests.java
  26. 6
      spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java
  27. 2
      spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java
  28. 2
      spring-context-support/src/testFixtures/java/org/springframework/contextsupport/testfixture/cache/TestableCacheResolver.java
  29. 3
      spring-context/src/test/java/org/springframework/aop/aspectj/AfterAdviceBindingTests.java
  30. 3
      spring-context/src/test/java/org/springframework/aop/aspectj/AfterReturningAdviceBindingTests.java
  31. 3
      spring-context/src/test/java/org/springframework/aop/aspectj/AfterThrowingAdviceBindingTests.java
  32. 6
      spring-context/src/test/java/org/springframework/aop/aspectj/AroundAdviceBindingTests.java
  33. 3
      spring-context/src/test/java/org/springframework/aop/aspectj/BeforeAdviceBindingTests.java
  34. 10
      spring-context/src/test/java/org/springframework/aop/config/MethodLocatingFactoryBeanTests.java
  35. 4
      spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java
  36. 2
      spring-context/src/test/java/org/springframework/cache/interceptor/LoggingCacheErrorHandlerTests.java
  37. 8
      spring-context/src/test/java/org/springframework/context/annotation/DeferredImportSelectorTests.java
  38. 6
      spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java
  39. 3
      spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessorTests.java
  40. 10
      spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java
  41. 2
      spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java
  42. 2
      spring-context/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java
  43. 4
      spring-context/src/test/java/org/springframework/context/event/GenericApplicationListenerAdapterTests.java
  44. 6
      spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java
  45. 2
      spring-context/src/test/java/org/springframework/jndi/JndiObjectFactoryBeanTests.java
  46. 14
      spring-context/src/test/java/org/springframework/jndi/JndiTemplateTests.java
  47. 4
      spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
  48. 14
      spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java
  49. 2
      spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolExecutorFactoryBeanTests.java
  50. 8
      spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskRegistrarTests.java
  51. 2
      spring-context/src/test/java/org/springframework/scripting/bsh/BshScriptFactoryTests.java
  52. 6
      spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java
  53. 4
      spring-context/src/test/java/org/springframework/scripting/support/RefreshableScriptTargetSourceTests.java
  54. 6
      spring-context/src/test/java/org/springframework/scripting/support/ResourceScriptSourceTests.java
  55. 3
      spring-context/src/test/java/org/springframework/scripting/support/ScriptFactoryPostProcessorTests.java
  56. 2
      spring-core/src/test/java/org/springframework/aot/generate/GeneratedClassesTests.java
  57. 2
      spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java
  58. 2
      spring-core/src/test/java/org/springframework/aot/hint/ResourceHintsTests.java
  59. 2
      spring-core/src/test/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrarTests.java
  60. 2
      spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java
  61. 2
      spring-core/src/test/java/org/springframework/core/annotation/AttributeMethodsTests.java
  62. 4
      spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsCollectionTests.java
  63. 2
      spring-core/src/test/java/org/springframework/core/io/PathResourceTests.java
  64. 10
      spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java
  65. 14
      spring-core/src/test/java/org/springframework/core/io/support/ResourceRegionTests.java
  66. 6
      spring-core/src/test/java/org/springframework/core/io/support/SpringFactoriesLoaderTests.java
  67. 4
      spring-core/src/test/java/org/springframework/core/log/CompositeLogTests.java
  68. 4
      spring-core/src/test/java/org/springframework/util/StreamUtilsTests.java
  69. 14
      spring-core/src/test/java/org/springframework/util/UnmodifiableMultiValueMapTests.java
  70. 22
      spring-core/src/test/java/org/springframework/util/concurrent/FutureAdapterTests.java
  71. 22
      spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java
  72. 4
      spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java
  73. 4
      spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java
  74. 2
      spring-core/src/test/java/org/springframework/util/xml/StaxEventXMLReaderTests.java
  75. 2
      spring-core/src/test/java/org/springframework/util/xml/StaxStreamXMLReaderTests.java
  76. 14
      spring-jdbc/src/test/java/org/springframework/jdbc/core/AbstractRowMapperTests.java
  77. 21
      spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java
  78. 30
      spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java
  79. 8
      spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java
  80. 12
      spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java
  81. 31
      spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java
  82. 20
      spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplateTests.java
  83. 18
      spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java
  84. 9
      spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java
  85. 16
      spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java
  86. 16
      spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java
  87. 19
      spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java
  88. 8
      spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReaderTests.java
  89. 2
      spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java
  90. 14
      spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java
  91. 36
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java
  92. 53
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java
  93. 4
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceUtilsTests.java
  94. 8
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DelegatingDataSourceTests.java
  95. 2
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DriverManagerDataSourceTests.java
  96. 12
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapterTests.java
  97. 2
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/AbstractDatabasePopulatorTests.java
  98. 6
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/CompositeDatabasePopulatorTests.java
  99. 6
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorUnitTests.java
  100. 4
      spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookupTests.java
  101. Some files were not shown because too many files have changed in this diff Show More

2
integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

@ -151,7 +151,7 @@ class ScheduledAndTransactionalAnnotationIntegrationTests { @@ -151,7 +151,7 @@ class ScheduledAndTransactionalAnnotationIntegrationTests {
@Bean
PersistenceExceptionTranslator peTranslator() {
return mock(PersistenceExceptionTranslator.class);
return mock();
}
@Bean

10
spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java

@ -50,7 +50,7 @@ public class ThrowsAdviceInterceptorTests { @@ -50,7 +50,7 @@ public class ThrowsAdviceInterceptorTests {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
Object ret = new Object();
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.proceed()).willReturn(ret);
assertThat(ti.invoke(mi)).isEqualTo(ret);
assertThat(th.getCalls()).isEqualTo(0);
@ -62,7 +62,7 @@ public class ThrowsAdviceInterceptorTests { @@ -62,7 +62,7 @@ public class ThrowsAdviceInterceptorTests {
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
assertThat(ti.getHandlerMethodCount()).isEqualTo(2);
Exception ex = new Exception();
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.proceed()).willThrow(ex);
assertThatException().isThrownBy(() -> ti.invoke(mi)).isSameAs(ex);
assertThat(th.getCalls()).isEqualTo(0);
@ -73,7 +73,7 @@ public class ThrowsAdviceInterceptorTests { @@ -73,7 +73,7 @@ public class ThrowsAdviceInterceptorTests {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
FileNotFoundException ex = new FileNotFoundException();
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode"));
given(mi.getThis()).willReturn(new Object());
given(mi.proceed()).willThrow(ex);
@ -90,7 +90,7 @@ public class ThrowsAdviceInterceptorTests { @@ -90,7 +90,7 @@ public class ThrowsAdviceInterceptorTests {
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
// Extends RemoteException
ConnectException ex = new ConnectException("");
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.proceed()).willThrow(ex);
assertThatExceptionOfType(ConnectException.class).isThrownBy(() ->
ti.invoke(mi))
@ -115,7 +115,7 @@ public class ThrowsAdviceInterceptorTests { @@ -115,7 +115,7 @@ public class ThrowsAdviceInterceptorTests {
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
// Extends RemoteException
ConnectException ex = new ConnectException("");
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.proceed()).willThrow(ex);
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
ti.invoke(mi))

15
spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java

@ -94,12 +94,11 @@ public class CustomizableTraceInterceptorTests { @@ -94,12 +94,11 @@ public class CustomizableTraceInterceptorTests {
@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
MethodInvocation methodInvocation = mock();
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
given(methodInvocation.getThis()).willReturn(this);
Log log = mock(Log.class);
Log log = mock();
given(log.isTraceEnabled()).willReturn(true);
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
@ -110,15 +109,14 @@ public class CustomizableTraceInterceptorTests { @@ -110,15 +109,14 @@ public class CustomizableTraceInterceptorTests {
@Test
public void testExceptionPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
MethodInvocation methodInvocation = mock();
IllegalArgumentException exception = new IllegalArgumentException();
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
given(methodInvocation.getThis()).willReturn(this);
given(methodInvocation.proceed()).willThrow(exception);
Log log = mock(Log.class);
Log log = mock();
given(log.isTraceEnabled()).willReturn(true);
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
@ -131,15 +129,14 @@ public class CustomizableTraceInterceptorTests { @@ -131,15 +129,14 @@ public class CustomizableTraceInterceptorTests {
@Test
public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
MethodInvocation methodInvocation = mock();
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
given(methodInvocation.getThis()).willReturn(this);
given(methodInvocation.getArguments()).willReturn(new Object[]{"$ One \\$", 2L});
given(methodInvocation.proceed()).willReturn("Hello!");
Log log = mock(Log.class);
Log log = mock();
given(log.isTraceEnabled()).willReturn(true);
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);

10
spring-aop/src/test/java/org/springframework/aop/interceptor/DebugInterceptorTests.java

@ -39,10 +39,9 @@ public class DebugInterceptorTests { @@ -39,10 +39,9 @@ public class DebugInterceptorTests {
@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock();
MethodInvocation methodInvocation = mock(MethodInvocation.class);
Log log = mock(Log.class);
Log log = mock();
given(log.isTraceEnabled()).willReturn(true);
DebugInterceptor interceptor = new StubDebugInterceptor(log);
@ -54,13 +53,12 @@ public class DebugInterceptorTests { @@ -54,13 +53,12 @@ public class DebugInterceptorTests {
@Test
public void testExceptionPathStillLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
MethodInvocation methodInvocation = mock();
IllegalArgumentException exception = new IllegalArgumentException();
given(methodInvocation.proceed()).willThrow(exception);
Log log = mock(Log.class);
Log log = mock();
given(log.isTraceEnabled()).willReturn(true);
DebugInterceptor interceptor = new StubDebugInterceptor(log);

8
spring-aop/src/test/java/org/springframework/aop/interceptor/PerformanceMonitorInterceptorTests.java

@ -50,10 +50,10 @@ public class PerformanceMonitorInterceptorTests { @@ -50,10 +50,10 @@ public class PerformanceMonitorInterceptorTests {
@Test
public void testSunnyDayPathLogsPerformanceMetricsCorrectly() throws Throwable {
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
Log log = mock(Log.class);
Log log = mock();
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
interceptor.invokeUnderTrace(mi, log);
@ -63,11 +63,11 @@ public class PerformanceMonitorInterceptorTests { @@ -63,11 +63,11 @@ public class PerformanceMonitorInterceptorTests {
@Test
public void testExceptionPathStillLogsPerformanceMetricsCorrectly() throws Throwable {
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
given(mi.proceed()).willThrow(new IllegalArgumentException());
Log log = mock(Log.class);
Log log = mock();
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
assertThatIllegalArgumentException().isThrownBy(() ->

8
spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java

@ -38,11 +38,11 @@ public class SimpleTraceInterceptorTests { @@ -38,11 +38,11 @@ public class SimpleTraceInterceptorTests {
@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
given(mi.getThis()).willReturn(this);
Log log = mock(Log.class);
Log log = mock();
SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
interceptor.invokeUnderTrace(mi, log);
@ -52,13 +52,13 @@ public class SimpleTraceInterceptorTests { @@ -52,13 +52,13 @@ public class SimpleTraceInterceptorTests {
@Test
public void testExceptionPathStillLogsCorrectly() throws Throwable {
MethodInvocation mi = mock(MethodInvocation.class);
MethodInvocation mi = mock();
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
given(mi.getThis()).willReturn(this);
IllegalArgumentException exception = new IllegalArgumentException();
given(mi.proceed()).willThrow(exception);
Log log = mock(Log.class);
Log log = mock();
final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
assertThatIllegalArgumentException().isThrownBy(() ->

2
spring-aop/src/test/java/org/springframework/aop/scope/DefaultScopedObjectTests.java

@ -59,7 +59,7 @@ public class DefaultScopedObjectTests { @@ -59,7 +59,7 @@ public class DefaultScopedObjectTests {
}
private static void testBadTargetBeanName(final String badTargetBeanName) {
ConfigurableBeanFactory factory = mock(ConfigurableBeanFactory.class);
ConfigurableBeanFactory factory = mock();
new DefaultScopedObject(factory, badTargetBeanName);
}

28
spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java

@ -44,22 +44,22 @@ import static org.mockito.Mockito.mock; @@ -44,22 +44,22 @@ import static org.mockito.Mockito.mock;
* @author Chris Beams
* @since 13.05.2003
*/
public class DelegatingIntroductionInterceptorTests {
class DelegatingIntroductionInterceptorTests {
@Test
public void testNullTarget() throws Exception {
void testNullTarget() throws Exception {
// Shouldn't accept null target
assertThatIllegalArgumentException().isThrownBy(() ->
new DelegatingIntroductionInterceptor(null));
}
@Test
public void testIntroductionInterceptorWithDelegation() throws Exception {
void testIntroductionInterceptorWithDelegation() throws Exception {
TestBean raw = new TestBean();
assertThat(! (raw instanceof TimeStamped)).isTrue();
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(TimeStamped.class);
TimeStamped ts = mock();
long timestamp = 111L;
given(ts.getTimeStamp()).willReturn(timestamp);
@ -70,12 +70,12 @@ public class DelegatingIntroductionInterceptorTests { @@ -70,12 +70,12 @@ public class DelegatingIntroductionInterceptorTests {
}
@Test
public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
TestBean raw = new TestBean();
assertThat(! (raw instanceof SubTimeStamped)).isTrue();
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(SubTimeStamped.class);
SubTimeStamped ts = mock();
long timestamp = 111L;
given(ts.getTimeStamp()).willReturn(timestamp);
@ -86,12 +86,12 @@ public class DelegatingIntroductionInterceptorTests { @@ -86,12 +86,12 @@ public class DelegatingIntroductionInterceptorTests {
}
@Test
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
void testIntroductionInterceptorWithSuperInterface() throws Exception {
TestBean raw = new TestBean();
assertThat(! (raw instanceof TimeStamped)).isTrue();
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(SubTimeStamped.class);
SubTimeStamped ts = mock();
long timestamp = 111L;
given(ts.getTimeStamp()).willReturn(timestamp);
@ -103,7 +103,7 @@ public class DelegatingIntroductionInterceptorTests { @@ -103,7 +103,7 @@ public class DelegatingIntroductionInterceptorTests {
}
@Test
public void testAutomaticInterfaceRecognitionInDelegate() throws Exception {
void testAutomaticInterfaceRecognitionInDelegate() throws Exception {
final long t = 1001L;
class Tester implements TimeStamped, ITester {
@Override
@ -133,7 +133,7 @@ public class DelegatingIntroductionInterceptorTests { @@ -133,7 +133,7 @@ public class DelegatingIntroductionInterceptorTests {
@Test
public void testAutomaticInterfaceRecognitionInSubclass() throws Exception {
void testAutomaticInterfaceRecognitionInSubclass() throws Exception {
final long t = 1001L;
@SuppressWarnings("serial")
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester {
@ -179,7 +179,7 @@ public class DelegatingIntroductionInterceptorTests { @@ -179,7 +179,7 @@ public class DelegatingIntroductionInterceptorTests {
@SuppressWarnings("serial")
@Test
public void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
TestBean raw = new TestBean();
assertThat(! (raw instanceof TimeStamped)).isTrue();
ProxyFactory factory = new ProxyFactory(raw);
@ -200,7 +200,7 @@ public class DelegatingIntroductionInterceptorTests { @@ -200,7 +200,7 @@ public class DelegatingIntroductionInterceptorTests {
}
@Test
public void testDelegateReturnsThisIsMassagedToReturnProxy() {
void testDelegateReturnsThisIsMassagedToReturnProxy() {
NestedTestBean target = new NestedTestBean();
String company = "Interface21";
target.setCompany(company);
@ -221,7 +221,7 @@ public class DelegatingIntroductionInterceptorTests { @@ -221,7 +221,7 @@ public class DelegatingIntroductionInterceptorTests {
}
@Test
public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception {
void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception {
SerializablePerson serializableTarget = new SerializablePerson();
String name = "Tony";
serializableTarget.setName("Tony");
@ -246,7 +246,7 @@ public class DelegatingIntroductionInterceptorTests { @@ -246,7 +246,7 @@ public class DelegatingIntroductionInterceptorTests {
// Test when target implements the interface: should get interceptor by preference.
@Test
public void testIntroductionMasksTargetImplementation() throws Exception {
void testIntroductionMasksTargetImplementation() throws Exception {
final long t = 1001L;
@SuppressWarnings("serial")
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped {

8
spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java

@ -1255,7 +1255,7 @@ class DefaultListableBeanFactoryTests { @@ -1255,7 +1255,7 @@ class DefaultListableBeanFactoryTests {
@Test
void expressionInStringArray() {
BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
BeanExpressionResolver beanExpressionResolver = mock();
given(beanExpressionResolver.evaluate(eq("#{foo}"), any(BeanExpressionContext.class)))
.willReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
lbf.setBeanExpressionResolver(beanExpressionResolver);
@ -2618,9 +2618,9 @@ class DefaultListableBeanFactoryTests { @@ -2618,9 +2618,9 @@ class DefaultListableBeanFactoryTests {
@Test
void resolveEmbeddedValue() {
StringValueResolver r1 = mock(StringValueResolver.class);
StringValueResolver r2 = mock(StringValueResolver.class);
StringValueResolver r3 = mock(StringValueResolver.class);
StringValueResolver r1 = mock();
StringValueResolver r2 = mock();
StringValueResolver r3 = mock();
lbf.addEmbeddedValueResolver(r1);
lbf.addEmbeddedValueResolver(r2);
lbf.addEmbeddedValueResolver(r3);

6
spring-beans/src/test/java/org/springframework/beans/factory/annotation/ParameterResolutionTests.java

@ -93,8 +93,8 @@ public class ParameterResolutionTests { @@ -93,8 +93,8 @@ public class ParameterResolutionTests {
@Test
public void resolveDependencyPreconditionsForParameter() {
assertThatIllegalArgumentException().isThrownBy(() ->
ParameterResolutionDelegate.resolveDependency(null, 0, null, mock(AutowireCapableBeanFactory.class)))
assertThatIllegalArgumentException()
.isThrownBy(() -> ParameterResolutionDelegate.resolveDependency(null, 0, null, mock()))
.withMessageContaining("Parameter must not be null");
}
@ -121,7 +121,7 @@ public class ParameterResolutionTests { @@ -121,7 +121,7 @@ public class ParameterResolutionTests {
public void resolveDependencyForAnnotatedParametersInTopLevelClassConstructor() throws Exception {
Constructor<?> constructor = AutowirableClass.class.getConstructor(String.class, String.class, String.class, String.class);
AutowireCapableBeanFactory beanFactory = mock(AutowireCapableBeanFactory.class);
AutowireCapableBeanFactory beanFactory = mock();
// Configure the mocked BeanFactory to return the DependencyDescriptor for convenience and
// to avoid using an ArgumentCaptor.
given(beanFactory.resolveDependency(any(), isNull())).willAnswer(invocation -> invocation.getArgument(0));

4
spring-beans/src/test/java/org/springframework/beans/factory/aot/AotServicesTests.java

@ -175,14 +175,14 @@ class AotServicesTests { @@ -175,14 +175,14 @@ class AotServicesTests {
AotServices<TestService> loaded = AotServices.factoriesAndBeans(loader, beanFactory).load(TestService.class);
assertThat(loaded.getSource(loaded.asList().get(0))).isEqualTo(Source.SPRING_FACTORIES_LOADER);
assertThat(loaded.getSource(loaded.asList().get(1))).isEqualTo(Source.BEAN_FACTORY);
TestService missing = mock(TestService.class);
TestService missing = mock();
assertThatIllegalStateException().isThrownBy(()->loaded.getSource(missing));
}
@Test
void getSourceWhenMissingThrowsException() {
AotServices<TestService> loaded = AotServices.factories().load(TestService.class);
TestService missing = mock(TestService.class);
TestService missing = mock();
assertThatIllegalStateException().isThrownBy(()->loaded.getSource(missing));
}

2
spring-beans/src/test/java/org/springframework/beans/factory/aot/AutowiredMethodArgumentsResolverTests.java

@ -115,7 +115,7 @@ class AutowiredMethodArgumentsResolverTests { @@ -115,7 +115,7 @@ class AutowiredMethodArgumentsResolverTests {
@Test
void resolveRequiredWithMultipleDependenciesReturnsValue() {
Environment environment = mock(Environment.class);
Environment environment = mock();
this.beanFactory.registerSingleton("test", "testValue");
this.beanFactory.registerSingleton("environment", environment);
RegisteredBean registeredBean = registerTestBean(this.beanFactory);

6
spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactoryTests.java

@ -110,13 +110,11 @@ class BeanDefinitionMethodGeneratorFactoryTests { @@ -110,13 +110,11 @@ class BeanDefinitionMethodGeneratorFactoryTests {
@Test
void getBeanDefinitionMethodGeneratorAddsContributionsFromProcessors() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
BeanRegistrationAotContribution beanContribution = mock(
BeanRegistrationAotContribution.class);
BeanRegistrationAotContribution beanContribution = mock();
BeanRegistrationAotProcessor processorBean = registeredBean -> beanContribution;
beanFactory.registerSingleton("processorBean", processorBean);
MockSpringFactoriesLoader springFactoriesLoader = new MockSpringFactoriesLoader();
BeanRegistrationAotContribution loaderContribution = mock(
BeanRegistrationAotContribution.class);
BeanRegistrationAotContribution loaderContribution = mock();
BeanRegistrationAotProcessor loaderProcessor = registeredBean -> loaderContribution;
springFactoriesLoader.addInstance(BeanRegistrationAotProcessor.class,
loaderProcessor);

6
spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanInstanceSupplierTests.java

@ -425,7 +425,7 @@ class BeanInstanceSupplierTests { @@ -425,7 +425,7 @@ class BeanInstanceSupplierTests {
@ParameterizedResolverTest(Sources.MULTI_ARGS)
void resolveArgumentsWithMultiArgsConstructor(Source source) {
ResourceLoader resourceLoader = new DefaultResourceLoader();
Environment environment = mock(Environment.class);
Environment environment = mock();
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
resourceLoader);
this.beanFactory.registerSingleton("environment", environment);
@ -442,7 +442,7 @@ class BeanInstanceSupplierTests { @@ -442,7 +442,7 @@ class BeanInstanceSupplierTests {
@ParameterizedResolverTest(Sources.MIXED_ARGS)
void resolveArgumentsWithMixedArgsConstructorWithUserValue(Source source) {
ResourceLoader resourceLoader = new DefaultResourceLoader();
Environment environment = mock(Environment.class);
Environment environment = mock();
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
resourceLoader);
this.beanFactory.registerSingleton("environment", environment);
@ -463,7 +463,7 @@ class BeanInstanceSupplierTests { @@ -463,7 +463,7 @@ class BeanInstanceSupplierTests {
@ParameterizedResolverTest(Sources.MIXED_ARGS)
void resolveArgumentsWithMixedArgsConstructorWithUserBeanReference(Source source) {
ResourceLoader resourceLoader = new DefaultResourceLoader();
Environment environment = mock(Environment.class);
Environment environment = mock();
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
resourceLoader);
this.beanFactory.registerSingleton("environment", environment);

2
spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java

@ -50,7 +50,7 @@ public class CustomScopeConfigurerTests { @@ -50,7 +50,7 @@ public class CustomScopeConfigurerTests {
@Test
public void testSunnyDayWithBonaFideScopeInstance() {
Scope scope = mock(Scope.class);
Scope scope = mock();
factory.registerScope(FOO_SCOPE, scope);
Map<String, Object> scopes = new HashMap<>();
scopes.put(FOO_SCOPE, scope);

2
spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java

@ -109,7 +109,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { @@ -109,7 +109,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
final String targetBeanName = "singleton";
final String expectedSingleton = "Alicia Keys";
BeanFactory beanFactory = mock(BeanFactory.class);
BeanFactory beanFactory = mock();
given(beanFactory.getBean(targetBeanName)).willReturn(expectedSingleton);
ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean();

2
spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java

@ -252,7 +252,7 @@ public class ServiceLocatorFactoryBeanTests { @@ -252,7 +252,7 @@ public class ServiceLocatorFactoryBeanTests {
@Test
public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception {
BeanFactory beanFactory = mock(BeanFactory.class);
BeanFactory beanFactory = mock();
try {
ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
factory.setBeanFactory(beanFactory);

2
spring-beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java

@ -47,7 +47,7 @@ public class FailFastProblemReporterTests { @@ -47,7 +47,7 @@ public class FailFastProblemReporterTests {
Problem problem = new Problem("VGER", new Location(new DescriptiveResource("here")),
null, new IllegalArgumentException());
Log log = mock(Log.class);
Log log = mock();
FailFastProblemReporter reporter = new FailFastProblemReporter();
reporter.setLogger(log);

4
spring-beans/src/test/java/org/springframework/beans/factory/support/RootBeanDefinitionTests.java

@ -36,7 +36,7 @@ class RootBeanDefinitionTests { @@ -36,7 +36,7 @@ class RootBeanDefinitionTests {
@Test
void setInstanceSetResolvedFactoryMethod() {
InstanceSupplier<?> instanceSupplier = mock(InstanceSupplier.class);
InstanceSupplier<?> instanceSupplier = mock();
Method method = ReflectionUtils.findMethod(String.class, "toString");
given(instanceSupplier.getFactoryMethod()).willReturn(method);
RootBeanDefinition beanDefinition = new RootBeanDefinition(String.class);
@ -47,7 +47,7 @@ class RootBeanDefinitionTests { @@ -47,7 +47,7 @@ class RootBeanDefinitionTests {
@Test
void setInstanceDoesNotOverrideResolvedFactoryMethodWithNull() {
InstanceSupplier<?> instanceSupplier = mock(InstanceSupplier.class);
InstanceSupplier<?> instanceSupplier = mock();
given(instanceSupplier.getFactoryMethod()).willReturn(null);
Method method = ReflectionUtils.findMethod(String.class, "toString");
RootBeanDefinition beanDefinition = new RootBeanDefinition(String.class);

11
spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanConfigurerSupportTests.java

@ -18,7 +18,6 @@ package org.springframework.beans.factory.wiring; @@ -18,7 +18,6 @@ package org.springframework.beans.factory.wiring;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.testfixture.beans.TestBean;
@ -37,16 +36,16 @@ import static org.mockito.Mockito.verify; @@ -37,16 +36,16 @@ import static org.mockito.Mockito.verify;
public class BeanConfigurerSupportTests {
@Test
public void supplyIncompatibleBeanFactoryImplementation() throws Exception {
public void supplyIncompatibleBeanFactoryImplementation() {
assertThatIllegalArgumentException().isThrownBy(() ->
new StubBeanConfigurerSupport().setBeanFactory(mock(BeanFactory.class)));
new StubBeanConfigurerSupport().setBeanFactory(mock()));
}
@Test
public void configureBeanDoesNothingIfBeanWiringInfoResolverResolvesToNull() throws Exception {
TestBean beanInstance = new TestBean();
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
BeanWiringInfoResolver resolver = mock();
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
configurer.setBeanWiringInfoResolver(resolver);
@ -90,7 +89,7 @@ public class BeanConfigurerSupportTests { @@ -90,7 +89,7 @@ public class BeanConfigurerSupportTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("spouse", builder.getBeanDefinition());
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
BeanWiringInfoResolver resolver = mock();
given(resolver.resolveWiringInfo(beanInstance)).willReturn(new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, false));
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
@ -110,7 +109,7 @@ public class BeanConfigurerSupportTests { @@ -110,7 +109,7 @@ public class BeanConfigurerSupportTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("Mmm, I fancy a salad!", builder.getBeanDefinition());
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
BeanWiringInfoResolver resolver = mock();
given(resolver.resolveWiringInfo(beanInstance)).willReturn(new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_TYPE, false));
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();

4
spring-beans/src/test/java/org/springframework/beans/factory/xml/ResourceEntityResolverTests.java

@ -18,7 +18,6 @@ package org.springframework.beans.factory.xml; @@ -18,7 +18,6 @@ package org.springframework.beans.factory.xml;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mockito;
import org.xml.sax.InputSource;
import org.springframework.core.io.Resource;
@ -27,6 +26,7 @@ import org.springframework.lang.Nullable; @@ -27,6 +26,7 @@ import org.springframework.lang.Nullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
/**
* Unit tests for ResourceEntityResolver.
@ -68,7 +68,7 @@ class ResourceEntityResolverTests { @@ -68,7 +68,7 @@ class ResourceEntityResolverTests {
@ParameterizedTest
@ValueSource(strings = { "https://example.org/schema.dtd", "https://example.org/schema.xsd" })
void resolveEntityCallsFallbackThatReturnsInputSource(String systemId) throws Exception {
InputSource expected = Mockito.mock(InputSource.class);
InputSource expected = mock();
ConfigurableFallbackEntityResolver resolver = new ConfigurableFallbackEntityResolver(expected);
assertThat(resolver.resolveEntity("testPublicId", systemId)).isSameAs(expected);

2
spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheManagerTests.java vendored

@ -156,7 +156,7 @@ public class CaffeineCacheManagerTests { @@ -156,7 +156,7 @@ public class CaffeineCacheManagerTests {
Cache cache1 = cm.getCache("c1");
@SuppressWarnings("unchecked")
CacheLoader<Object, Object> loader = mock(CacheLoader.class);
CacheLoader<Object, Object> loader = mock();
cm.setCacheLoader(loader);
Cache cache1x = cm.getCache("c1");

5
spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java vendored

@ -86,11 +86,10 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM @@ -86,11 +86,10 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
private final List<String> cacheNames;
private final CacheManager cacheManager;
private final CacheManager cacheManager = mock();
private CacheManagerMock() {
this.cacheNames = new ArrayList<>();
this.cacheManager = mock(CacheManager.class);
given(cacheManager.getCacheNames()).willReturn(cacheNames);
}
@ -101,7 +100,7 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM @@ -101,7 +100,7 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
@SuppressWarnings({ "unchecked", "rawtypes" })
public void addCache(String name) {
cacheNames.add(name);
Cache cache = mock(Cache.class);
Cache cache = mock();
given(cache.getName()).willReturn(name);
given(cacheManager.getCache(name)).willReturn(cache);
}

2
spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java vendored

@ -114,7 +114,7 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests { @@ -114,7 +114,7 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
@Test
public void defaultCacheNameWithDefaults() {
Method method = ReflectionUtils.findMethod(Object.class, "toString");
CacheDefaults mock = mock(CacheDefaults.class);
CacheDefaults mock = mock();
given(mock.cacheName()).willReturn("");
assertThat(source.determineCacheName(method, mock, "")).isEqualTo("java.lang.Object.toString()");
}

4
spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapterTests.java vendored

@ -61,13 +61,13 @@ public class CacheResolverAdapterTests extends AbstractJCacheTests { @@ -61,13 +61,13 @@ public class CacheResolverAdapterTests extends AbstractJCacheTests {
@SuppressWarnings({ "rawtypes", "unchecked" })
protected CacheResolver getCacheResolver(CacheInvocationContext<? extends Annotation> context, String cacheName) {
CacheResolver cacheResolver = mock(CacheResolver.class);
CacheResolver cacheResolver = mock();
javax.cache.Cache cache;
if (cacheName == null) {
cache = null;
}
else {
cache = mock(javax.cache.Cache.class);
cache = mock();
given(cache.getName()).willReturn(cacheName);
}
given(cacheResolver.resolveCache(context)).willReturn(cache);

6
spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java vendored

@ -154,7 +154,7 @@ public class JCacheErrorHandlerTests { @@ -154,7 +154,7 @@ public class JCacheErrorHandlerTests {
@Bean
@Override
public CacheErrorHandler errorHandler() {
return mock(CacheErrorHandler.class);
return mock();
}
@Bean
@ -164,14 +164,14 @@ public class JCacheErrorHandlerTests { @@ -164,14 +164,14 @@ public class JCacheErrorHandlerTests {
@Bean
public Cache mockCache() {
Cache cache = mock(Cache.class);
Cache cache = mock();
given(cache.getName()).willReturn("test");
return cache;
}
@Bean
public Cache mockErrorCache() {
Cache cache = mock(Cache.class);
Cache cache = mock();
given(cache.getName()).willReturn("error");
return cache;
}

2
spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java

@ -68,7 +68,7 @@ class QuartzSupportTests { @@ -68,7 +68,7 @@ class QuartzSupportTests {
TestBean tb = new TestBean("tb", 99);
StaticApplicationContext ac = new StaticApplicationContext();
final Scheduler scheduler = mock(Scheduler.class);
final Scheduler scheduler = mock();
SchedulerContext schedulerContext = new SchedulerContext();
given(scheduler.getContext()).willReturn(schedulerContext);

2
spring-context-support/src/testFixtures/java/org/springframework/contextsupport/testfixture/cache/TestableCacheResolver.java vendored

@ -34,7 +34,7 @@ public class TestableCacheResolver implements CacheResolver { @@ -34,7 +34,7 @@ public class TestableCacheResolver implements CacheResolver {
public <K, V> Cache<K, V> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext) {
String cacheName = cacheInvocationContext.getCacheName();
@SuppressWarnings("unchecked")
Cache<K, V> mock = mock(Cache.class);
Cache<K, V> mock = mock();
given(mock.getName()).willReturn(cacheName);
return mock;
}

3
spring-context/src/test/java/org/springframework/aop/aspectj/AfterAdviceBindingTests.java

@ -42,7 +42,7 @@ class AfterAdviceBindingTests { @@ -42,7 +42,7 @@ class AfterAdviceBindingTests {
private ClassPathXmlApplicationContext ctx;
private AdviceBindingCollaborator mockCollaborator;
private AdviceBindingCollaborator mockCollaborator = mock();
private ITestBean testBeanProxy;
@ -60,7 +60,6 @@ class AfterAdviceBindingTests { @@ -60,7 +60,6 @@ class AfterAdviceBindingTests {
// we need the real target too, not just the proxy...
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
mockCollaborator = mock(AdviceBindingCollaborator.class);
afterAdviceAspect.setCollaborator(mockCollaborator);
}

3
spring-context/src/test/java/org/springframework/aop/aspectj/AfterReturningAdviceBindingTests.java

@ -50,7 +50,7 @@ class AfterReturningAdviceBindingTests { @@ -50,7 +50,7 @@ class AfterReturningAdviceBindingTests {
private TestBean testBeanTarget;
private AfterReturningAdviceBindingCollaborator mockCollaborator;
private AfterReturningAdviceBindingCollaborator mockCollaborator = mock();
@BeforeEach
@ -59,7 +59,6 @@ class AfterReturningAdviceBindingTests { @@ -59,7 +59,6 @@ class AfterReturningAdviceBindingTests {
afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");
mockCollaborator = mock(AfterReturningAdviceBindingCollaborator.class);
afterAdviceAspect.setCollaborator(mockCollaborator);
testBeanProxy = (ITestBean) ctx.getBean("testBean");

3
spring-context/src/test/java/org/springframework/aop/aspectj/AfterThrowingAdviceBindingTests.java

@ -42,7 +42,7 @@ class AfterThrowingAdviceBindingTests { @@ -42,7 +42,7 @@ class AfterThrowingAdviceBindingTests {
private AfterThrowingAdviceBindingTestAspect afterThrowingAdviceAspect;
private AfterThrowingAdviceBindingCollaborator mockCollaborator;
private AfterThrowingAdviceBindingCollaborator mockCollaborator = mock();
@BeforeEach
@ -52,7 +52,6 @@ class AfterThrowingAdviceBindingTests { @@ -52,7 +52,6 @@ class AfterThrowingAdviceBindingTests {
testBean = (ITestBean) ctx.getBean("testBean");
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
mockCollaborator = mock(AfterThrowingAdviceBindingCollaborator.class);
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
}

6
spring-context/src/test/java/org/springframework/aop/aspectj/AroundAdviceBindingTests.java

@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify; @@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify;
*/
public class AroundAdviceBindingTests {
private AroundAdviceBindingCollaborator mockCollaborator;
private AroundAdviceBindingCollaborator mockCollaborator = mock();
private ITestBean testBeanProxy;
@ -48,11 +48,12 @@ public class AroundAdviceBindingTests { @@ -48,11 +48,12 @@ public class AroundAdviceBindingTests {
protected ApplicationContext ctx;
@BeforeEach
public void onSetUp() throws Exception {
ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
AroundAdviceBindingTestAspect aroundAdviceAspect = ((AroundAdviceBindingTestAspect) ctx.getBean("testAspect"));
AroundAdviceBindingTestAspect aroundAdviceAspect = (AroundAdviceBindingTestAspect) ctx.getBean("testAspect");
ITestBean injectedTestBean = (ITestBean) ctx.getBean("testBean");
assertThat(AopUtils.isAopProxy(injectedTestBean)).isTrue();
@ -62,7 +63,6 @@ public class AroundAdviceBindingTests { @@ -62,7 +63,6 @@ public class AroundAdviceBindingTests {
this.testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
mockCollaborator = mock(AroundAdviceBindingCollaborator.class);
aroundAdviceAspect.setCollaborator(mockCollaborator);
}

3
spring-context/src/test/java/org/springframework/aop/aspectj/BeforeAdviceBindingTests.java

@ -42,7 +42,7 @@ class BeforeAdviceBindingTests { @@ -42,7 +42,7 @@ class BeforeAdviceBindingTests {
private ClassPathXmlApplicationContext ctx;
private AdviceBindingCollaborator mockCollaborator;
private AdviceBindingCollaborator mockCollaborator = mock();
private ITestBean testBeanProxy;
@ -61,7 +61,6 @@ class BeforeAdviceBindingTests { @@ -61,7 +61,6 @@ class BeforeAdviceBindingTests {
AdviceBindingTestAspect beforeAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
mockCollaborator = mock(AdviceBindingCollaborator.class);
beforeAdviceAspect.setCollaborator(mockCollaborator);
}

10
spring-context/src/test/java/org/springframework/aop/config/MethodLocatingFactoryBeanTests.java

@ -18,7 +18,6 @@ package org.springframework.aop.config; @@ -18,7 +18,6 @@ package org.springframework.aop.config;
import java.lang.reflect.Method;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
@ -36,14 +35,9 @@ import static org.mockito.Mockito.verify; @@ -36,14 +35,9 @@ import static org.mockito.Mockito.verify;
public class MethodLocatingFactoryBeanTests {
private static final String BEAN_NAME = "string";
private MethodLocatingFactoryBean factory;
private BeanFactory beanFactory;
private MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
private BeanFactory beanFactory = mock();
@BeforeEach
public void setUp() {
factory = new MethodLocatingFactoryBean();
beanFactory = mock(BeanFactory.class);
}
@Test
public void testIsSingleton() {

4
spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java vendored

@ -183,7 +183,7 @@ class CacheErrorHandlerTests { @@ -183,7 +183,7 @@ class CacheErrorHandlerTests {
@Bean
@Override
public CacheErrorHandler errorHandler() {
return mock(CacheErrorHandler.class);
return mock();
}
@Bean
@ -201,7 +201,7 @@ class CacheErrorHandlerTests { @@ -201,7 +201,7 @@ class CacheErrorHandlerTests {
@Bean
public Cache mockCache() {
Cache cache = mock(Cache.class);
Cache cache = mock();
given(cache.getName()).willReturn("test");
return cache;
}

2
spring-context/src/test/java/org/springframework/cache/interceptor/LoggingCacheErrorHandlerTests.java vendored

@ -42,7 +42,7 @@ class LoggingCacheErrorHandlerTests { @@ -42,7 +42,7 @@ class LoggingCacheErrorHandlerTests {
private static final String KEY = "enigma";
private final Log logger = mock(Log.class);
private final Log logger = mock();
private LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(this.logger, false);

8
spring-context/src/test/java/org/springframework/context/annotation/DeferredImportSelectorTests.java

@ -33,25 +33,25 @@ public class DeferredImportSelectorTests { @@ -33,25 +33,25 @@ public class DeferredImportSelectorTests {
@Test
public void entryEqualsSameInstance() {
AnnotationMetadata metadata = mock(AnnotationMetadata.class);
AnnotationMetadata metadata = mock();
Group.Entry entry = new Group.Entry(metadata, "com.example.Test");
assertThat(entry).isEqualTo(entry);
}
@Test
public void entryEqualsSameMetadataAndClassName() {
AnnotationMetadata metadata = mock(AnnotationMetadata.class);
AnnotationMetadata metadata = mock();
assertThat(new Group.Entry(metadata, "com.example.Test")).isEqualTo(new Group.Entry(metadata, "com.example.Test"));
}
@Test
public void entryEqualDifferentMetadataAndSameClassName() {
assertThat(new Group.Entry(mock(AnnotationMetadata.class), "com.example.Test")).isNotEqualTo(new Group.Entry(mock(AnnotationMetadata.class), "com.example.Test"));
assertThat(new Group.Entry(mock(), "com.example.Test")).isNotEqualTo(new Group.Entry(mock(), "com.example.Test"));
}
@Test
public void entryEqualSameMetadataAnDifferentClassName() {
AnnotationMetadata metadata = mock(AnnotationMetadata.class);
AnnotationMetadata metadata = mock();
assertThat(new Group.Entry(metadata, "com.example.AnotherTest")).isNotEqualTo(new Group.Entry(metadata, "com.example.Test"));
}
}

6
spring-context/src/test/java/org/springframework/context/annotation/EnableLoadTimeWeavingTests.java

@ -84,7 +84,7 @@ class EnableLoadTimeWeavingTests { @@ -84,7 +84,7 @@ class EnableLoadTimeWeavingTests {
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
return mock(LoadTimeWeaver.class);
return mock();
}
}
@ -94,7 +94,7 @@ class EnableLoadTimeWeavingTests { @@ -94,7 +94,7 @@ class EnableLoadTimeWeavingTests {
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
return mock(LoadTimeWeaver.class);
return mock();
}
}
@ -104,7 +104,7 @@ class EnableLoadTimeWeavingTests { @@ -104,7 +104,7 @@ class EnableLoadTimeWeavingTests {
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
return mock(LoadTimeWeaver.class);
return mock();
}
}

3
spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessorTests.java

@ -28,7 +28,6 @@ import org.springframework.aot.test.generate.TestGenerationContext; @@ -28,7 +28,6 @@ import org.springframework.aot.test.generate.TestGenerationContext;
import org.springframework.beans.factory.aot.AotServices;
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
import org.springframework.beans.factory.aot.BeanFactoryInitializationCode;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
@ -76,7 +75,7 @@ class ReflectiveProcessorBeanFactoryInitializationAotProcessorTests { @@ -76,7 +75,7 @@ class ReflectiveProcessorBeanFactoryInitializationAotProcessorTests {
}
BeanFactoryInitializationAotContribution contribution = this.processor.processAheadOfTime(beanFactory);
assertThat(contribution).isNotNull();
contribution.applyTo(this.generationContext, mock(BeanFactoryInitializationCode.class));
contribution.applyTo(this.generationContext, mock());
}
@Reflective

10
spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java

@ -136,7 +136,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen @@ -136,7 +136,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
@Test
public void simpleApplicationEventMulticasterWithTaskExecutor() {
@SuppressWarnings("unchecked")
ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
ApplicationListener<ApplicationEvent> listener = mock();
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
@ -153,7 +153,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen @@ -153,7 +153,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
@Test
public void simpleApplicationEventMulticasterWithException() {
@SuppressWarnings("unchecked")
ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
ApplicationListener<ApplicationEvent> listener = mock();
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
@ -169,7 +169,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen @@ -169,7 +169,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
@Test
public void simpleApplicationEventMulticasterWithErrorHandler() {
@SuppressWarnings("unchecked")
ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
ApplicationListener<ApplicationEvent> listener = mock();
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
@ -246,8 +246,8 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen @@ -246,8 +246,8 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
@Test
public void testEventPublicationInterceptor() throws Throwable {
MethodInvocation invocation = mock(MethodInvocation.class);
ApplicationContext ctx = mock(ApplicationContext.class);
MethodInvocation invocation = mock();
ApplicationContext ctx = mock();
EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
interceptor.setApplicationEventClass(MyEvent.class);

2
spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java

@ -51,7 +51,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv @@ -51,7 +51,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
private final SampleEvents sampleEvents = spy(new SampleEvents());
private final ApplicationContext context = mock(ApplicationContext.class);
private final ApplicationContext context = mock();
@Test

2
spring-context/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java

@ -47,7 +47,7 @@ class EventPublicationInterceptorTests { @@ -47,7 +47,7 @@ class EventPublicationInterceptorTests {
@BeforeEach
void setup() {
ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
ApplicationEventPublisher publisher = mock();
this.interceptor.setApplicationEventPublisher(publisher);
}

4
spring-context/src/test/java/org/springframework/context/event/GenericApplicationListenerAdapterTests.java

@ -36,7 +36,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE @@ -36,7 +36,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
@Test
public void supportsEventTypeWithSmartApplicationListener() {
SmartApplicationListener smartListener = mock(SmartApplicationListener.class);
SmartApplicationListener smartListener = mock();
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
ResolvableType type = ResolvableType.forClass(ApplicationEvent.class);
listener.supportsEventType(type);
@ -45,7 +45,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE @@ -45,7 +45,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
@Test
public void supportsSourceTypeWithSmartApplicationListener() {
SmartApplicationListener smartListener = mock(SmartApplicationListener.class);
SmartApplicationListener smartListener = mock();
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
listener.supportsSourceType(Object.class);
verify(smartListener, times(1)).supportsSourceType(Object.class);

6
spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java

@ -310,7 +310,7 @@ class GenericApplicationContextTests { @@ -310,7 +310,7 @@ class GenericApplicationContextTests {
@Test
void refreshForAotRegistersEnvironment() {
ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
ConfigurableEnvironment environment = mock();
GenericApplicationContext context = new GenericApplicationContext();
context.setEnvironment(environment);
context.refreshForAotProcessing(new RuntimeHints());
@ -363,7 +363,7 @@ class GenericApplicationContextTests { @@ -363,7 +363,7 @@ class GenericApplicationContextTests {
@Test
void refreshForAotInvokesBeanFactoryPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
BeanFactoryPostProcessor bfpp = mock(BeanFactoryPostProcessor.class);
BeanFactoryPostProcessor bfpp = mock();
context.addBeanFactoryPostProcessor(bfpp);
context.refreshForAotProcessing(new RuntimeHints());
verify(bfpp).postProcessBeanFactory(context.getBeanFactory());
@ -510,7 +510,7 @@ class GenericApplicationContextTests { @@ -510,7 +510,7 @@ class GenericApplicationContextTests {
}
private MergedBeanDefinitionPostProcessor registerMockMergedBeanDefinitionPostProcessor(GenericApplicationContext context) {
MergedBeanDefinitionPostProcessor bpp = mock(MergedBeanDefinitionPostProcessor.class);
MergedBeanDefinitionPostProcessor bpp = mock();
context.registerBeanDefinition("bpp", BeanDefinitionBuilder.rootBeanDefinition(
MergedBeanDefinitionPostProcessor.class, () -> bpp)
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE).getBeanDefinition());

2
spring-context/src/test/java/org/springframework/jndi/JndiObjectFactoryBeanTests.java

@ -372,7 +372,7 @@ public class JndiObjectFactoryBeanTests { @@ -372,7 +372,7 @@ public class JndiObjectFactoryBeanTests {
public void testLookupWithExposeAccessContext() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
TestBean tb = new TestBean();
final Context mockCtx = mock(Context.class);
final Context mockCtx = mock();
given(mockCtx.lookup("foo")).willReturn(tb);
jof.setJndiTemplate(new JndiTemplate() {
@Override

14
spring-context/src/test/java/org/springframework/jndi/JndiTemplateTests.java

@ -39,7 +39,7 @@ public class JndiTemplateTests { @@ -39,7 +39,7 @@ public class JndiTemplateTests {
public void testLookupSucceeds() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
final Context context = mock();
given(context.lookup(name)).willReturn(o);
JndiTemplate jt = new JndiTemplate() {
@ -58,7 +58,7 @@ public class JndiTemplateTests { @@ -58,7 +58,7 @@ public class JndiTemplateTests {
public void testLookupFails() throws Exception {
NameNotFoundException ne = new NameNotFoundException();
String name = "foo";
final Context context = mock(Context.class);
final Context context = mock();
given(context.lookup(name)).willThrow(ne);
JndiTemplate jt = new JndiTemplate() {
@ -76,7 +76,7 @@ public class JndiTemplateTests { @@ -76,7 +76,7 @@ public class JndiTemplateTests {
@Test
public void testLookupReturnsNull() throws Exception {
String name = "foo";
final Context context = mock(Context.class);
final Context context = mock();
given(context.lookup(name)).willReturn(null);
JndiTemplate jt = new JndiTemplate() {
@ -95,7 +95,7 @@ public class JndiTemplateTests { @@ -95,7 +95,7 @@ public class JndiTemplateTests {
public void testLookupFailsWithTypeMismatch() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
final Context context = mock();
given(context.lookup(name)).willReturn(o);
JndiTemplate jt = new JndiTemplate() {
@ -114,7 +114,7 @@ public class JndiTemplateTests { @@ -114,7 +114,7 @@ public class JndiTemplateTests {
public void testBind() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
final Context context = mock();
JndiTemplate jt = new JndiTemplate() {
@Override
@ -132,7 +132,7 @@ public class JndiTemplateTests { @@ -132,7 +132,7 @@ public class JndiTemplateTests {
public void testRebind() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
final Context context = mock();
JndiTemplate jt = new JndiTemplate() {
@Override
@ -149,7 +149,7 @@ public class JndiTemplateTests { @@ -149,7 +149,7 @@ public class JndiTemplateTests {
@Test
public void testUnbind() throws Exception {
String name = "something";
final Context context = mock(Context.class);
final Context context = mock();
JndiTemplate jt = new JndiTemplate() {
@Override

4
spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java

@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit; @@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
@ -57,6 +56,7 @@ import org.springframework.util.ReflectionUtils; @@ -57,6 +56,7 @@ import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
/**
* Tests use of @EnableAsync on @Configuration classes.
@ -495,7 +495,7 @@ public class EnableAsyncTests { @@ -495,7 +495,7 @@ public class EnableAsyncTests {
@Bean
@Lazy
public AsyncBean asyncBean() {
return Mockito.mock(AsyncBean.class);
return mock();
}
}

14
spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java

@ -49,7 +49,7 @@ class ScheduledExecutorFactoryBeanTests { @@ -49,7 +49,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test
@SuppressWarnings("serial")
void shutdownNowIsPropagatedToTheExecutorOnDestroy() throws Exception {
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
final ScheduledExecutorService executor = mock();
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@Override
@ -67,7 +67,7 @@ class ScheduledExecutorFactoryBeanTests { @@ -67,7 +67,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test
@SuppressWarnings("serial")
void shutdownIsPropagatedToTheExecutorOnDestroy() throws Exception {
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
final ScheduledExecutorService executor = mock();
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@Override
@ -86,7 +86,7 @@ class ScheduledExecutorFactoryBeanTests { @@ -86,7 +86,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void oneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception {
Runnable runnable = mock(Runnable.class);
Runnable runnable = mock();
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
factory.setScheduledExecutorTasks(new ScheduledExecutorTask(runnable));
@ -100,7 +100,7 @@ class ScheduledExecutorFactoryBeanTests { @@ -100,7 +100,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
Runnable runnable = mock(Runnable.class);
Runnable runnable = mock();
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
task.setPeriod(500);
@ -118,7 +118,7 @@ class ScheduledExecutorFactoryBeanTests { @@ -118,7 +118,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
Runnable runnable = mock(Runnable.class);
Runnable runnable = mock();
willThrow(new IllegalStateException()).given(runnable).run();
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
@ -138,7 +138,7 @@ class ScheduledExecutorFactoryBeanTests { @@ -138,7 +138,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
Runnable runnable = mock(Runnable.class);
Runnable runnable = mock();
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
task.setPeriod(500);
@ -158,7 +158,7 @@ class ScheduledExecutorFactoryBeanTests { @@ -158,7 +158,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
Runnable runnable = mock(Runnable.class);
Runnable runnable = mock();
willThrow(new IllegalStateException()).given(runnable).run();
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);

2
spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolExecutorFactoryBeanTests.java

@ -97,7 +97,7 @@ class ThreadPoolExecutorFactoryBeanTests { @@ -97,7 +97,7 @@ class ThreadPoolExecutorFactoryBeanTests {
int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue,
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return mock(ThreadPoolExecutor.class);
return mock();
}
}

8
spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskRegistrarTests.java

@ -50,28 +50,28 @@ class ScheduledTaskRegistrarTests { @@ -50,28 +50,28 @@ class ScheduledTaskRegistrarTests {
@Test
void getTriggerTasks() {
TriggerTask mockTriggerTask = mock(TriggerTask.class);
TriggerTask mockTriggerTask = mock();
this.taskRegistrar.setTriggerTasksList(Collections.singletonList(mockTriggerTask));
assertThat(this.taskRegistrar.getTriggerTaskList()).containsExactly(mockTriggerTask);
}
@Test
void getCronTasks() {
CronTask mockCronTask = mock(CronTask.class);
CronTask mockCronTask = mock();
this.taskRegistrar.setCronTasksList(Collections.singletonList(mockCronTask));
assertThat(this.taskRegistrar.getCronTaskList()).containsExactly(mockCronTask);
}
@Test
void getFixedRateTasks() {
IntervalTask mockFixedRateTask = mock(IntervalTask.class);
IntervalTask mockFixedRateTask = mock();
this.taskRegistrar.setFixedRateTasksList(Collections.singletonList(mockFixedRateTask));
assertThat(this.taskRegistrar.getFixedRateTaskList()).containsExactly(mockFixedRateTask);
}
@Test
void getFixedDelayTasks() {
IntervalTask mockFixedDelayTask = mock(IntervalTask.class);
IntervalTask mockFixedDelayTask = mock();
this.taskRegistrar.setFixedDelayTasksList(Collections.singletonList(mockFixedDelayTask));
assertThat(this.taskRegistrar.getFixedDelayTaskList()).containsExactly(mockFixedDelayTask);
}

2
spring-context/src/test/java/org/springframework/scripting/bsh/BshScriptFactoryTests.java

@ -213,7 +213,7 @@ class BshScriptFactoryTests { @@ -213,7 +213,7 @@ class BshScriptFactoryTests {
@Test
void scriptThatCompilesButIsJustPlainBad() throws IOException {
ScriptSource script = mock(ScriptSource.class);
ScriptSource script = mock();
final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
given(script.getScriptAsString()).willReturn(badScript);
given(script.isModified()).willReturn(true);

6
spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java

@ -284,7 +284,7 @@ public class GroovyScriptFactoryTests { @@ -284,7 +284,7 @@ public class GroovyScriptFactoryTests {
@Test
public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
ScriptSource script = mock(ScriptSource.class);
ScriptSource script = mock();
String badScript = "class Foo { public Foo(String foo) {}}";
given(script.getScriptAsString()).willReturn(badScript);
given(script.suggestedClassName()).willReturn("someName");
@ -297,7 +297,7 @@ public class GroovyScriptFactoryTests { @@ -297,7 +297,7 @@ public class GroovyScriptFactoryTests {
@Test
public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
ScriptSource script = mock(ScriptSource.class);
ScriptSource script = mock();
String badScript = "class Foo { protected Foo() {} \n String toString() { 'X' }}";
given(script.getScriptAsString()).willReturn(badScript);
given(script.suggestedClassName()).willReturn("someName");
@ -352,7 +352,7 @@ public class GroovyScriptFactoryTests { @@ -352,7 +352,7 @@ public class GroovyScriptFactoryTests {
@Test
public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPassedIn() throws Exception {
ScriptSource script = mock(ScriptSource.class);
ScriptSource script = mock();
given(script.getScriptAsString()).willReturn("class Bar {}");
given(script.suggestedClassName()).willReturn("someName");

4
spring-context/src/test/java/org/springframework/scripting/support/RefreshableScriptTargetSourceTests.java

@ -18,8 +18,6 @@ package org.springframework.scripting.support; @@ -18,8 +18,6 @@ package org.springframework.scripting.support;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
@ -31,7 +29,7 @@ public class RefreshableScriptTargetSourceTests { @@ -31,7 +29,7 @@ public class RefreshableScriptTargetSourceTests {
@Test
public void createWithNullScriptSource() throws Exception {
assertThatIllegalArgumentException().isThrownBy(() ->
new RefreshableScriptTargetSource(mock(BeanFactory.class), "a.bean", null, null, false));
new RefreshableScriptTargetSource(mock(), "a.bean", null, null, false));
}
}

6
spring-context/src/test/java/org/springframework/scripting/support/ResourceScriptSourceTests.java

@ -36,7 +36,7 @@ public class ResourceScriptSourceTests { @@ -36,7 +36,7 @@ public class ResourceScriptSourceTests {
@Test
public void doesNotPropagateFatalExceptionOnResourceThatCannotBeResolvedToAFile() throws Exception {
Resource resource = mock(Resource.class);
Resource resource = mock();
given(resource.lastModified()).willThrow(new IOException());
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
@ -46,14 +46,14 @@ public class ResourceScriptSourceTests { @@ -46,14 +46,14 @@ public class ResourceScriptSourceTests {
@Test
public void beginsInModifiedState() throws Exception {
Resource resource = mock(Resource.class);
Resource resource = mock();
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
assertThat(scriptSource.isModified()).isTrue();
}
@Test
public void lastModifiedWorksWithResourceThatDoesNotSupportFileBasedReading() throws Exception {
Resource resource = mock(Resource.class);
Resource resource = mock();
// underlying File is asked for so that the last modified time can be checked...
// And then mock the file changing; i.e. the File says it has been modified
given(resource.lastModified()).willReturn(100L, 100L, 200L);

3
spring-context/src/test/java/org/springframework/scripting/support/ScriptFactoryPostProcessorTests.java

@ -19,7 +19,6 @@ package org.springframework.scripting.support; @@ -19,7 +19,6 @@ package org.springframework.scripting.support;
import org.junit.jupiter.api.Test;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@ -88,7 +87,7 @@ class ScriptFactoryPostProcessorTests { @@ -88,7 +87,7 @@ class ScriptFactoryPostProcessorTests {
@Test
void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() {
assertThatIllegalStateException().isThrownBy(() ->
new ScriptFactoryPostProcessor().setBeanFactory(mock(BeanFactory.class)));
new ScriptFactoryPostProcessor().setBeanFactory(mock()));
}
@Test

2
spring-core/src/test/java/org/springframework/aot/generate/GeneratedClassesTests.java

@ -160,7 +160,7 @@ class GeneratedClassesTests { @@ -160,7 +160,7 @@ class GeneratedClassesTests {
@Test
@SuppressWarnings("unchecked")
void writeToInvokeTypeSpecCustomizer() throws IOException {
Consumer<TypeSpec.Builder> typeSpecCustomizer = mock(Consumer.class);
Consumer<TypeSpec.Builder> typeSpecCustomizer = mock();
this.generatedClasses.addForFeatureComponent("one", TestComponent.class, typeSpecCustomizer);
verifyNoInteractions(typeSpecCustomizer);
InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles();

2
spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java

@ -57,7 +57,7 @@ class ReflectionHintsTests { @@ -57,7 +57,7 @@ class ReflectionHintsTests {
@Test
@SuppressWarnings("unchecked")
void registerTypeIfPresentIgnoresMissingClass() {
Consumer<TypeHint.Builder> hintBuilder = mock(Consumer.class);
Consumer<TypeHint.Builder> hintBuilder = mock();
this.reflectionHints.registerTypeIfPresent(null, "com.example.DoesNotExist", hintBuilder);
assertThat(this.reflectionHints.typeHints()).isEmpty();
verifyNoInteractions(hintBuilder);

2
spring-core/src/test/java/org/springframework/aot/hint/ResourceHintsTests.java

@ -134,7 +134,7 @@ class ResourceHintsTests { @@ -134,7 +134,7 @@ class ResourceHintsTests {
@Test
@SuppressWarnings("unchecked")
void registerIfPresentIgnoreMissingLocation() {
Consumer<ResourcePatternHints.Builder> hintBuilder = mock(Consumer.class);
Consumer<ResourcePatternHints.Builder> hintBuilder = mock();
this.resourceHints.registerPatternIfPresent(null, "location/does-not-exist/", hintBuilder);
assertThat(this.resourceHints.resourcePatternHints()).isEmpty();
verifyNoInteractions(hintBuilder);

2
spring-core/src/test/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrarTests.java

@ -51,7 +51,7 @@ class ReflectiveRuntimeHintsRegistrarTests { @@ -51,7 +51,7 @@ class ReflectiveRuntimeHintsRegistrarTests {
@Test
void shouldIgnoreNonAnnotatedType() {
RuntimeHints mock = mock(RuntimeHints.class);
RuntimeHints mock = mock();
this.registrar.registerRuntimeHints(mock, String.class);
verifyNoInteractions(mock);
}

2
spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java

@ -869,7 +869,7 @@ class ResolvableTypeTests { @@ -869,7 +869,7 @@ class ResolvableTypeTests {
@Test
void resolveTypeWithCustomVariableResolver() throws Exception {
VariableResolver variableResolver = mock(VariableResolver.class);
VariableResolver variableResolver = mock();
given(variableResolver.getSource()).willReturn(this);
ResolvableType longType = ResolvableType.forClass(Long.class);
given(variableResolver.resolveVariable(any())).willReturn(longType);

2
spring-core/src/test/java/org/springframework/core/annotation/AttributeMethodsTests.java

@ -118,7 +118,7 @@ class AttributeMethodsTests { @@ -118,7 +118,7 @@ class AttributeMethodsTests {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
void isValidWhenDoesNotHaveTypeNotPresentExceptionReturnsTrue() {
ClassValue annotation = mock(ClassValue.class);
ClassValue annotation = mock();
given(annotation.value()).willReturn((Class) InputStream.class);
AttributeMethods attributes = AttributeMethods.forAnnotationType(annotation.annotationType());
assertThat(attributes.isValid(annotation)).isTrue();

4
spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsCollectionTests.java

@ -53,7 +53,7 @@ class MergedAnnotationsCollectionTests { @@ -53,7 +53,7 @@ class MergedAnnotationsCollectionTests {
@Test
void createWhenAnnotationIsNotDirectlyPresentThrowsException() {
MergedAnnotation<?> annotation = mock(MergedAnnotation.class);
MergedAnnotation<?> annotation = mock();
given(annotation.isDirectlyPresent()).willReturn(false);
assertThatIllegalArgumentException().isThrownBy(() ->
MergedAnnotationsCollection.of(Collections.singleton(annotation)))
@ -62,7 +62,7 @@ class MergedAnnotationsCollectionTests { @@ -62,7 +62,7 @@ class MergedAnnotationsCollectionTests {
@Test
void createWhenAnnotationAggregateIndexIsNotZeroThrowsException() {
MergedAnnotation<?> annotation = mock(MergedAnnotation.class);
MergedAnnotation<?> annotation = mock();
given(annotation.isDirectlyPresent()).willReturn(true);
given(annotation.getAggregateIndex()).willReturn(1);
assertThatIllegalArgumentException().isThrownBy(() ->

2
spring-core/src/test/java/org/springframework/core/io/PathResourceTests.java

@ -193,7 +193,7 @@ class PathResourceTests { @@ -193,7 +193,7 @@ class PathResourceTests {
@Test
void getFileUnsupported() throws IOException {
Path path = mock(Path.class);
Path path = mock();
given(path.normalize()).willReturn(path);
given(path.toFile()).willThrow(new UnsupportedOperationException());
PathResource resource = new PathResource(path);

10
spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java

@ -101,7 +101,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests { @@ -101,7 +101,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
void readByteChannelError(DataBufferFactory bufferFactory) throws Exception {
super.bufferFactory = bufferFactory;
ReadableByteChannel channel = mock(ReadableByteChannel.class);
ReadableByteChannel channel = mock();
given(channel.read(any()))
.willAnswer(invocation -> {
ByteBuffer buffer = invocation.getArgument(0);
@ -166,7 +166,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests { @@ -166,7 +166,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
void readAsynchronousFileChannelError(DataBufferFactory bufferFactory) throws Exception {
super.bufferFactory = bufferFactory;
AsynchronousFileChannel channel = mock(AsynchronousFileChannel.class);
AsynchronousFileChannel channel = mock();
willAnswer(invocation -> {
ByteBuffer byteBuffer = invocation.getArgument(0);
byteBuffer.put("foo".getBytes(StandardCharsets.UTF_8));
@ -360,7 +360,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests { @@ -360,7 +360,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux = Flux.just(foo, bar);
WritableByteChannel channel = mock(WritableByteChannel.class);
WritableByteChannel channel = mock();
given(channel.write(any()))
.willAnswer(invocation -> {
ByteBuffer buffer = invocation.getArgument(0);
@ -470,7 +470,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests { @@ -470,7 +470,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux = Flux.just(foo, bar);
AsynchronousFileChannel channel = mock(AsynchronousFileChannel.class);
AsynchronousFileChannel channel = mock();
willAnswer(invocation -> {
ByteBuffer buffer = invocation.getArgument(0);
long pos = invocation.getArgument(1);
@ -777,7 +777,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests { @@ -777,7 +777,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
void SPR16070(DataBufferFactory bufferFactory) throws Exception {
super.bufferFactory = bufferFactory;
ReadableByteChannel channel = mock(ReadableByteChannel.class);
ReadableByteChannel channel = mock();
given(channel.read(any()))
.willAnswer(putByte('a'))
.willAnswer(putByte('b'))

14
spring-core/src/test/java/org/springframework/core/io/support/ResourceRegionTests.java

@ -18,8 +18,6 @@ package org.springframework.core.io.support; @@ -18,8 +18,6 @@ package org.springframework.core.io.support;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.Resource;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
@ -32,20 +30,20 @@ class ResourceRegionTests { @@ -32,20 +30,20 @@ class ResourceRegionTests {
@Test
void shouldThrowExceptionWithNullResource() {
assertThatIllegalArgumentException().isThrownBy(() ->
new ResourceRegion(null, 0, 1));
assertThatIllegalArgumentException()
.isThrownBy(() -> new ResourceRegion(null, 0, 1));
}
@Test
void shouldThrowExceptionForNegativePosition() {
assertThatIllegalArgumentException().isThrownBy(() ->
new ResourceRegion(mock(Resource.class), -1, 1));
assertThatIllegalArgumentException()
.isThrownBy(() -> new ResourceRegion(mock(), -1, 1));
}
@Test
void shouldThrowExceptionForNegativeCount() {
assertThatIllegalArgumentException().isThrownBy(() ->
new ResourceRegion(mock(Resource.class), 0, -1));
assertThatIllegalArgumentException()
.isThrownBy(() -> new ResourceRegion(mock(), 0, -1));
}
}

6
spring-core/src/test/java/org/springframework/core/io/support/SpringFactoriesLoaderTests.java

@ -107,7 +107,7 @@ class SpringFactoriesLoaderTests { @@ -107,7 +107,7 @@ class SpringFactoriesLoaderTests {
@Test
void loadWithLoggingFailureHandlerWhenIncompatibleTypeReturnsEmptyList() {
Log logger = mock(Log.class);
Log logger = mock();
FailureHandler failureHandler = FailureHandler.logging(logger);
List<String> factories = SpringFactoriesLoader.forDefaultResourceLocation().load(String.class, failureHandler);
assertThat(factories).isEmpty();
@ -138,7 +138,7 @@ class SpringFactoriesLoaderTests { @@ -138,7 +138,7 @@ class SpringFactoriesLoaderTests {
@Test
void loadWithLoggingFailureHandlerWhenMissingArgumentDropsItem() {
Log logger = mock(Log.class);
Log logger = mock();
FailureHandler failureHandler = FailureHandler.logging(logger);
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation(LimitedClassLoader.multipleArgumentFactories)
.load(DummyFactory.class, failureHandler);
@ -202,7 +202,7 @@ class SpringFactoriesLoaderTests { @@ -202,7 +202,7 @@ class SpringFactoriesLoaderTests {
@Test
void loggingReturnsHandlerThatLogs() {
Log logger = mock(Log.class);
Log logger = mock();
FailureHandler handler = FailureHandler.logging(logger);
RuntimeException cause = new RuntimeException();
handler.handleFailure(DummyFactory.class, MyDummyFactory1.class.getName(), cause);

4
spring-core/src/test/java/org/springframework/core/log/CompositeLogTests.java

@ -33,9 +33,9 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -33,9 +33,9 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
*/
public class CompositeLogTests {
private final Log logger1 = mock(Log.class);
private final Log logger1 = mock();
private final Log logger2 = mock(Log.class);
private final Log logger2 = mock();
private final CompositeLog compositeLog = new CompositeLog(Arrays.asList(logger1, logger2));

4
spring-core/src/test/java/org/springframework/util/StreamUtilsTests.java

@ -100,7 +100,7 @@ class StreamUtilsTests { @@ -100,7 +100,7 @@ class StreamUtilsTests {
@Test
void nonClosingInputStream() throws Exception {
InputStream source = mock(InputStream.class);
InputStream source = mock();
InputStream nonClosing = StreamUtils.nonClosing(source);
nonClosing.read();
nonClosing.read(bytes);
@ -115,7 +115,7 @@ class StreamUtilsTests { @@ -115,7 +115,7 @@ class StreamUtilsTests {
@Test
void nonClosingOutputStream() throws Exception {
OutputStream source = mock(OutputStream.class);
OutputStream source = mock();
OutputStream nonClosing = StreamUtils.nonClosing(source);
nonClosing.write(1);
nonClosing.write(bytes);

14
spring-core/src/test/java/org/springframework/util/UnmodifiableMultiValueMapTests.java

@ -43,7 +43,7 @@ class UnmodifiableMultiValueMapTests { @@ -43,7 +43,7 @@ class UnmodifiableMultiValueMapTests {
@Test
@SuppressWarnings("unchecked")
void delegation() {
MultiValueMap<String, String> mock = mock(MultiValueMap.class);
MultiValueMap<String, String> mock = mock();
UnmodifiableMultiValueMap<String, String> map = new UnmodifiableMultiValueMap<>(mock);
given(mock.size()).willReturn(1);
@ -101,8 +101,8 @@ class UnmodifiableMultiValueMapTests { @@ -101,8 +101,8 @@ class UnmodifiableMultiValueMapTests {
@Test
@SuppressWarnings("unchecked")
void entrySetDelegation() {
MultiValueMap<String, String> mockMap = mock(MultiValueMap.class);
Set<Map.Entry<String, List<String>>> mockSet = mock(Set.class);
MultiValueMap<String, String> mockMap = mock();
Set<Map.Entry<String, List<String>>> mockSet = mock();
given(mockMap.entrySet()).willReturn(mockSet);
Set<Map.Entry<String, List<String>>> set = new UnmodifiableMultiValueMap<>(mockMap).entrySet();
@ -112,7 +112,7 @@ class UnmodifiableMultiValueMapTests { @@ -112,7 +112,7 @@ class UnmodifiableMultiValueMapTests {
given(mockSet.isEmpty()).willReturn(false);
assertThat(set.isEmpty()).isFalse();
Map.Entry<String, List<String>> mockedEntry = mock(Map.Entry.class);
Map.Entry<String, List<String>> mockedEntry = mock();
given(mockSet.contains(mockedEntry)).willReturn(true);
assertThat(set.contains(mockedEntry)).isTrue();
@ -120,7 +120,7 @@ class UnmodifiableMultiValueMapTests { @@ -120,7 +120,7 @@ class UnmodifiableMultiValueMapTests {
given(mockSet.containsAll(mockEntries)).willReturn(true);
assertThat(set.containsAll(mockEntries)).isTrue();
Iterator<Map.Entry<String, List<String>>> mockIterator = mock(Iterator.class);
Iterator<Map.Entry<String, List<String>>> mockIterator = mock();
given(mockSet.iterator()).willReturn(mockIterator);
given(mockIterator.hasNext()).willReturn(false);
assertThat(set.iterator()).isExhausted();
@ -143,8 +143,8 @@ class UnmodifiableMultiValueMapTests { @@ -143,8 +143,8 @@ class UnmodifiableMultiValueMapTests {
@Test
@SuppressWarnings("unchecked")
void valuesDelegation() {
MultiValueMap<String, String> mockMap = mock(MultiValueMap.class);
Collection<List<String>> mockValues = mock(Collection.class);
MultiValueMap<String, String> mockMap = mock();
Collection<List<String>> mockValues = mock();
given(mockMap.values()).willReturn(mockValues);
Collection<List<String>> values = new UnmodifiableMultiValueMap<>(mockMap).values();

22
spring-core/src/test/java/org/springframework/util/concurrent/FutureAdapterTests.java

@ -20,7 +20,6 @@ import java.util.concurrent.ExecutionException; @@ -20,7 +20,6 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -33,22 +32,17 @@ import static org.mockito.Mockito.mock; @@ -33,22 +32,17 @@ import static org.mockito.Mockito.mock;
@SuppressWarnings("deprecation")
class FutureAdapterTests {
private FutureAdapter<String, Integer> adapter;
@SuppressWarnings("unchecked")
private Future<Integer> adaptee = mock();
private Future<Integer> adaptee;
private FutureAdapter<String, Integer> adapter = new FutureAdapter<>(adaptee) {
@Override
protected String adapt(Integer adapteeResult) throws ExecutionException {
return adapteeResult.toString();
}
};
@BeforeEach
@SuppressWarnings("unchecked")
void setUp() {
adaptee = mock(Future.class);
adapter = new FutureAdapter<>(adaptee) {
@Override
protected String adapt(Integer adapteeResult) throws ExecutionException {
return adapteeResult.toString();
}
};
}
@Test
void cancel() {

22
spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java

@ -94,8 +94,8 @@ class ListenableFutureTaskTests { @@ -94,8 +94,8 @@ class ListenableFutureTaskTests {
final String s = "Hello World";
Callable<String> callable = () -> s;
SuccessCallback<String> successCallback = mock(SuccessCallback.class);
FailureCallback failureCallback = mock(FailureCallback.class);
SuccessCallback<String> successCallback = mock();
FailureCallback failureCallback = mock();
ListenableFutureTask<String> task = new ListenableFutureTask<>(callable);
task.addCallback(successCallback, failureCallback);
task.run();
@ -115,20 +115,22 @@ class ListenableFutureTaskTests { @@ -115,20 +115,22 @@ class ListenableFutureTaskTests {
throw ex;
};
SuccessCallback<String> successCallback = mock(SuccessCallback.class);
FailureCallback failureCallback = mock(FailureCallback.class);
SuccessCallback<String> successCallback = mock();
FailureCallback failureCallback = mock();
ListenableFutureTask<String> task = new ListenableFutureTask<>(callable);
task.addCallback(successCallback, failureCallback);
task.run();
verify(failureCallback).onFailure(ex);
verifyNoInteractions(successCallback);
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
task::get)
.satisfies(e -> assertThat(e.getCause().getMessage()).isEqualTo(s));
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
task.completable()::get)
.satisfies(e -> assertThat(e.getCause().getMessage()).isEqualTo(s));
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(task::get)
.havingCause()
.withMessage(s);
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(task.completable()::get)
.havingCause()
.withMessage(s);
}
}

4
spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java

@ -361,7 +361,7 @@ class SettableListenableFutureTests { @@ -361,7 +361,7 @@ class SettableListenableFutureTests {
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void cancelDoesNotNotifyCallbacksOnSet() {
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
ListenableFutureCallback callback = mock();
settableListenableFuture.addCallback(callback);
settableListenableFuture.cancel(true);
@ -378,7 +378,7 @@ class SettableListenableFutureTests { @@ -378,7 +378,7 @@ class SettableListenableFutureTests {
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void cancelDoesNotNotifyCallbacksOnSetException() {
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
ListenableFutureCallback callback = mock();
settableListenableFuture.addCallback(callback);
settableListenableFuture.cancel(true);

4
spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java

@ -170,7 +170,7 @@ abstract class AbstractStaxXMLReaderTests { @@ -170,7 +170,7 @@ abstract class AbstractStaxXMLReaderTests {
private LexicalHandler mockLexicalHandler() throws Exception {
LexicalHandler lexicalHandler = mock(LexicalHandler.class);
LexicalHandler lexicalHandler = mock();
willAnswer(new CopyCharsAnswer()).given(lexicalHandler).comment(any(char[].class), anyInt(), anyInt());
return lexicalHandler;
}
@ -180,7 +180,7 @@ abstract class AbstractStaxXMLReaderTests { @@ -180,7 +180,7 @@ abstract class AbstractStaxXMLReaderTests {
}
protected final ContentHandler mockContentHandler() throws Exception {
ContentHandler contentHandler = mock(ContentHandler.class);
ContentHandler contentHandler = mock();
willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt());
willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
willAnswer(invocation -> {

2
spring-core/src/test/java/org/springframework/util/xml/StaxEventXMLReaderTests.java

@ -48,7 +48,7 @@ class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTests { @@ -48,7 +48,7 @@ class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTests {
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
eventReader.nextTag(); // skip to root
StaxEventXMLReader xmlReader = new StaxEventXMLReader(eventReader);
ContentHandler contentHandler = mock(ContentHandler.class);
ContentHandler contentHandler = mock();
xmlReader.setContentHandler(contentHandler);
xmlReader.parse(new InputSource());
verify(contentHandler).startDocument();

2
spring-core/src/test/java/org/springframework/util/xml/StaxStreamXMLReaderTests.java

@ -55,7 +55,7 @@ class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTests { @@ -55,7 +55,7 @@ class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTests {
assertThat(streamReader.getName()).as("Invalid element").isEqualTo(new QName("http://springframework.org/spring-ws", "child"));
StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader);
ContentHandler contentHandler = mock(ContentHandler.class);
ContentHandler contentHandler = mock();
xmlReader.setContentHandler(contentHandler);
xmlReader.parse(new InputSource());

14
spring-jdbc/src/test/java/org/springframework/jdbc/core/AbstractRowMapperTests.java

@ -120,27 +120,23 @@ public abstract class AbstractRowMapperTests { @@ -120,27 +120,23 @@ public abstract class AbstractRowMapperTests {
protected static class Mock {
private Connection connection;
private Connection connection = mock();
private ResultSetMetaData resultSetMetaData;
private ResultSetMetaData resultSetMetaData = mock();
private ResultSet resultSet;
private ResultSet resultSet = mock();
private Statement statement;
private Statement statement = mock();
private JdbcTemplate jdbcTemplate;
public Mock() throws Exception {
this(MockType.ONE);
}
@SuppressWarnings("unchecked")
public Mock(MockType type) throws Exception {
connection = mock(Connection.class);
statement = mock(Statement.class);
resultSet = mock(ResultSet.class);
resultSetMetaData = mock(ResultSetMetaData.class);
given(connection.createStatement()).willReturn(statement);
given(statement.executeQuery(anyString())).willReturn(resultSet);
given(resultSet.getMetaData()).willReturn(resultSetMetaData);

21
spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java

@ -50,30 +50,23 @@ import static org.mockito.Mockito.verify; @@ -50,30 +50,23 @@ import static org.mockito.Mockito.verify;
*/
public class JdbcTemplateQueryTests {
private Connection connection;
private Connection connection = mock();
private DataSource dataSource;
private DataSource dataSource = mock();
private Statement statement;
private Statement statement = mock();
private PreparedStatement preparedStatement;
private PreparedStatement preparedStatement = mock();
private ResultSet resultSet;
private ResultSet resultSet = mock();
private ResultSetMetaData resultSetMetaData;
private ResultSetMetaData resultSetMetaData = mock();
private JdbcTemplate template;
private JdbcTemplate template = new JdbcTemplate(this.dataSource);
@BeforeEach
public void setUp() throws Exception {
this.connection = mock(Connection.class);
this.dataSource = mock(DataSource.class);
this.statement = mock(Statement.class);
this.preparedStatement = mock(PreparedStatement.class);
this.resultSet = mock(ResultSet.class);
this.resultSetMetaData = mock(ResultSetMetaData.class);
this.template = new JdbcTemplate(this.dataSource);
given(this.dataSource.getConnection()).willReturn(this.connection);
given(this.resultSet.getMetaData()).willReturn(this.resultSetMetaData);
given(this.resultSetMetaData.getColumnCount()).willReturn(1);

30
spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java

@ -75,30 +75,23 @@ import static org.mockito.Mockito.verify; @@ -75,30 +75,23 @@ import static org.mockito.Mockito.verify;
*/
public class JdbcTemplateTests {
private Connection connection;
private Connection connection = mock();
private DataSource dataSource;
private DataSource dataSource = mock();
private PreparedStatement preparedStatement;
private Statement statement = mock();
private Statement statement;
private PreparedStatement preparedStatement = mock();
private ResultSet resultSet;
private ResultSet resultSet = mock();
private JdbcTemplate template;
private CallableStatement callableStatement = mock();
private CallableStatement callableStatement;
private JdbcTemplate template = new JdbcTemplate(this.dataSource);
@BeforeEach
public void setup() throws Exception {
this.connection = mock(Connection.class);
this.dataSource = mock(DataSource.class);
this.preparedStatement = mock(PreparedStatement.class);
this.statement = mock(Statement.class);
this.resultSet = mock(ResultSet.class);
this.template = new JdbcTemplate(this.dataSource);
this.callableStatement = mock(CallableStatement.class);
given(this.dataSource.getConnection()).willReturn(this.connection);
given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement);
given(this.preparedStatement.executeQuery()).willReturn(this.resultSet);
@ -779,7 +772,6 @@ public class JdbcTemplateTests { @@ -779,7 +772,6 @@ public class JdbcTemplateTests {
@Test
public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws SQLException {
SQLException sqlException = new SQLException("foo", "07xxx");
this.dataSource = mock(DataSource.class);
given(this.dataSource.getConnection()).willThrow(sqlException);
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
@ -792,7 +784,6 @@ public class JdbcTemplateTests { @@ -792,7 +784,6 @@ public class JdbcTemplateTests {
@Test
public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() throws SQLException {
SQLException sqlException = new SQLException("foo", "07xxx");
this.dataSource = mock(DataSource.class);
given(this.dataSource.getConnection()).willThrow(sqlException);
this.template = new JdbcTemplate();
this.template.setDataSource(this.dataSource);
@ -826,7 +817,6 @@ public class JdbcTemplateTests { @@ -826,7 +817,6 @@ public class JdbcTemplateTests {
throws SQLException {
SQLException sqlException = new SQLException("foo", "07xxx");
this.dataSource = mock(DataSource.class);
given(this.dataSource.getConnection()).willThrow(sqlException);
this.template = new JdbcTemplate();
this.template.setDataSource(this.dataSource);
@ -1008,7 +998,7 @@ public class JdbcTemplateTests { @@ -1008,7 +998,7 @@ public class JdbcTemplateTests {
@Test
public void testStaticResultSetClosed() throws Exception {
ResultSet resultSet2 = mock(ResultSet.class);
ResultSet resultSet2 = mock();
reset(this.preparedStatement);
given(this.preparedStatement.executeQuery()).willReturn(resultSet2);
given(this.connection.createStatement()).willReturn(this.statement);
@ -1071,7 +1061,7 @@ public class JdbcTemplateTests { @@ -1071,7 +1061,7 @@ public class JdbcTemplateTests {
public void testEquallyNamedColumn() throws SQLException {
given(this.connection.createStatement()).willReturn(this.statement);
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
ResultSetMetaData metaData = mock();
given(metaData.getColumnCount()).willReturn(2);
given(metaData.getColumnLabel(1)).willReturn("x");
given(metaData.getColumnLabel(2)).willReturn("X");
@ -1088,7 +1078,7 @@ public class JdbcTemplateTests { @@ -1088,7 +1078,7 @@ public class JdbcTemplateTests {
private void mockDatabaseMetaData(boolean supportsBatchUpdates) throws SQLException {
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
DatabaseMetaData databaseMetaData = mock();
given(databaseMetaData.getDatabaseProductName()).willReturn("MySQL");
given(databaseMetaData.supportsBatchUpdates()).willReturn(supportsBatchUpdates);
given(this.connection.getMetaData()).willReturn(databaseMetaData);

8
spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java

@ -45,13 +45,13 @@ import static org.mockito.Mockito.verify; @@ -45,13 +45,13 @@ import static org.mockito.Mockito.verify;
*/
public class RowMapperTests {
private final Connection connection = mock(Connection.class);
private final Connection connection = mock();
private final Statement statement = mock(Statement.class);
private final Statement statement = mock();
private final PreparedStatement preparedStatement = mock(PreparedStatement.class);
private final PreparedStatement preparedStatement = mock();
private final ResultSet resultSet = mock(ResultSet.class);
private final ResultSet resultSet = mock();
private final JdbcTemplate template = new JdbcTemplate();

12
spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java

@ -47,8 +47,8 @@ public class SingleColumnRowMapperTests { @@ -47,8 +47,8 @@ public class SingleColumnRowMapperTests {
SingleColumnRowMapper<LocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(LocalDateTime.class);
ResultSet resultSet = mock(ResultSet.class);
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
ResultSet resultSet = mock();
ResultSetMetaData metaData = mock();
given(metaData.getColumnCount()).willReturn(1);
given(resultSet.getMetaData()).willReturn(metaData);
given(resultSet.getObject(1, LocalDateTime.class))
@ -70,8 +70,8 @@ public class SingleColumnRowMapperTests { @@ -70,8 +70,8 @@ public class SingleColumnRowMapperTests {
SingleColumnRowMapper<MyLocalDateTime> rowMapper =
SingleColumnRowMapper.newInstance(MyLocalDateTime.class, myConversionService);
ResultSet resultSet = mock(ResultSet.class);
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
ResultSet resultSet = mock();
ResultSetMetaData metaData = mock();
given(metaData.getColumnCount()).willReturn(1);
given(resultSet.getMetaData()).willReturn(metaData);
given(resultSet.getObject(1, MyLocalDateTime.class))
@ -89,8 +89,8 @@ public class SingleColumnRowMapperTests { @@ -89,8 +89,8 @@ public class SingleColumnRowMapperTests {
SingleColumnRowMapper<LocalDateTime> rowMapper =
SingleColumnRowMapper.newInstance(LocalDateTime.class, null);
ResultSet resultSet = mock(ResultSet.class);
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
ResultSet resultSet = mock();
ResultSetMetaData metaData = mock();
given(metaData.getColumnCount()).willReturn(1);
given(resultSet.getMetaData()).willReturn(metaData);
given(resultSet.getObject(1, LocalDateTime.class))

31
spring-jdbc/src/test/java/org/springframework/jdbc/core/StatementCreatorUtilsTests.java

@ -24,7 +24,6 @@ import java.sql.SQLException; @@ -24,7 +24,6 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.GregorianCalendar;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.mockito.BDDMockito.given;
@ -38,13 +37,7 @@ import static org.mockito.Mockito.verify; @@ -38,13 +37,7 @@ import static org.mockito.Mockito.verify;
*/
public class StatementCreatorUtilsTests {
private PreparedStatement preparedStatement;
@BeforeEach
public void setUp() {
preparedStatement = mock(PreparedStatement.class);
}
private PreparedStatement preparedStatement = mock();
@Test
@ -62,8 +55,8 @@ public class StatementCreatorUtilsTests { @@ -62,8 +55,8 @@ public class StatementCreatorUtilsTests {
@Test
public void testSetParameterValueWithNullAndUnknownType() throws SQLException {
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
Connection con = mock(Connection.class);
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
Connection con = mock();
DatabaseMetaData dbmd = mock();
given(preparedStatement.getConnection()).willReturn(con);
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
given(dbmd.getDriverName()).willReturn("Oracle Driver");
@ -76,8 +69,8 @@ public class StatementCreatorUtilsTests { @@ -76,8 +69,8 @@ public class StatementCreatorUtilsTests {
@Test
public void testSetParameterValueWithNullAndUnknownTypeOnInformix() throws SQLException {
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
Connection con = mock(Connection.class);
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
Connection con = mock();
DatabaseMetaData dbmd = mock();
given(preparedStatement.getConnection()).willReturn(con);
given(con.getMetaData()).willReturn(dbmd);
given(dbmd.getDatabaseProductName()).willReturn("Informix Dynamic Server");
@ -92,8 +85,8 @@ public class StatementCreatorUtilsTests { @@ -92,8 +85,8 @@ public class StatementCreatorUtilsTests {
@Test
public void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded() throws SQLException {
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
Connection con = mock(Connection.class);
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
Connection con = mock();
DatabaseMetaData dbmd = mock();
given(preparedStatement.getConnection()).willReturn(con);
given(con.getMetaData()).willReturn(dbmd);
given(dbmd.getDatabaseProductName()).willReturn("Apache Derby");
@ -107,7 +100,7 @@ public class StatementCreatorUtilsTests { @@ -107,7 +100,7 @@ public class StatementCreatorUtilsTests {
@Test
public void testSetParameterValueWithNullAndGetParameterTypeWorking() throws SQLException {
ParameterMetaData pmd = mock(ParameterMetaData.class);
ParameterMetaData pmd = mock();
given(preparedStatement.getParameterMetaData()).willReturn(pmd);
given(pmd.getParameterType(1)).willReturn(Types.SMALLINT);
StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, null);
@ -212,8 +205,8 @@ public class StatementCreatorUtilsTests { @@ -212,8 +205,8 @@ public class StatementCreatorUtilsTests {
@Test // SPR-8571
public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLException {
Connection con = mock(Connection.class);
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
Connection con = mock();
DatabaseMetaData dbmd = mock();
given(preparedStatement.getConnection()).willReturn(con);
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
given(con.getMetaData()).willReturn(dbmd);
@ -224,8 +217,8 @@ public class StatementCreatorUtilsTests { @@ -224,8 +217,8 @@ public class StatementCreatorUtilsTests {
@Test // SPR-8571
public void testSetParameterValueWithNullAndVendorSpecificType() throws SQLException {
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
Connection con = mock(Connection.class);
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
Connection con = mock();
DatabaseMetaData dbmd = mock();
given(preparedStatement.getConnection()).willReturn(con);
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
given(dbmd.getDriverName()).willReturn("Oracle Driver");

20
spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplateTests.java

@ -83,29 +83,23 @@ public class NamedParameterJdbcTemplateTests { @@ -83,29 +83,23 @@ public class NamedParameterJdbcTemplateTests {
private static final String[] COLUMN_NAMES = new String[] {"id", "forename"};
private Connection connection;
private Connection connection = mock();
private DataSource dataSource;
private DataSource dataSource = mock();
private PreparedStatement preparedStatement;
private PreparedStatement preparedStatement = mock();
private ResultSet resultSet;
private ResultSet resultSet = mock();
private DatabaseMetaData databaseMetaData;
private DatabaseMetaData databaseMetaData = mock();
private Map<String, Object> params = new HashMap<>();
private NamedParameterJdbcTemplate namedParameterTemplate = new NamedParameterJdbcTemplate(dataSource);
private NamedParameterJdbcTemplate namedParameterTemplate;
private Map<String, Object> params = new HashMap<>();
@BeforeEach
public void setup() throws Exception {
connection = mock(Connection.class);
dataSource = mock(DataSource.class);
preparedStatement = mock(PreparedStatement.class);
resultSet = mock(ResultSet.class);
namedParameterTemplate = new NamedParameterJdbcTemplate(dataSource);
databaseMetaData = mock(DatabaseMetaData.class);
given(dataSource.getConnection()).willReturn(connection);
given(connection.prepareStatement(anyString())).willReturn(preparedStatement);
given(preparedStatement.getConnection()).willReturn(connection);

18
spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java

@ -48,27 +48,21 @@ import static org.mockito.Mockito.verify; @@ -48,27 +48,21 @@ import static org.mockito.Mockito.verify;
*/
public class NamedParameterQueryTests {
private DataSource dataSource;
private Connection connection = mock();
private Connection connection;
private DataSource dataSource = mock();
private PreparedStatement preparedStatement;
private PreparedStatement preparedStatement = mock();
private ResultSet resultSet;
private ResultSet resultSet = mock();
private ResultSetMetaData resultSetMetaData;
private ResultSetMetaData resultSetMetaData = mock();
private NamedParameterJdbcTemplate template;
private NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource);
@BeforeEach
public void setup() throws Exception {
connection = mock(Connection.class);
dataSource = mock(DataSource.class);
preparedStatement = mock(PreparedStatement.class);
resultSet = mock(ResultSet.class);
resultSetMetaData = mock(ResultSetMetaData.class);
template = new NamedParameterJdbcTemplate(dataSource);
given(dataSource.getConnection()).willReturn(connection);
given(resultSetMetaData.getColumnCount()).willReturn(1);
given(resultSetMetaData.getColumnLabel(1)).willReturn("age");

9
spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/CallMetaDataContextTests.java

@ -47,21 +47,18 @@ import static org.mockito.Mockito.verify; @@ -47,21 +47,18 @@ import static org.mockito.Mockito.verify;
*/
public class CallMetaDataContextTests {
private DataSource dataSource;
private DataSource dataSource = mock();
private Connection connection;
private Connection connection = mock();
private DatabaseMetaData databaseMetaData;
private DatabaseMetaData databaseMetaData = mock();
private CallMetaDataContext context = new CallMetaDataContext();
@BeforeEach
public void setUp() throws Exception {
connection = mock(Connection.class);
databaseMetaData = mock(DatabaseMetaData.class);
given(connection.getMetaData()).willReturn(databaseMetaData);
dataSource = mock(DataSource.class);
given(dataSource.getConnection()).willReturn(connection);
}

16
spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcCallTests.java

@ -50,13 +50,13 @@ import static org.mockito.Mockito.verify; @@ -50,13 +50,13 @@ import static org.mockito.Mockito.verify;
*/
class SimpleJdbcCallTests {
private final Connection connection = mock(Connection.class);
private final Connection connection = mock();
private final DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
private final DatabaseMetaData databaseMetaData = mock();
private final DataSource dataSource = mock(DataSource.class);
private final DataSource dataSource = mock();
private final CallableStatement callableStatement = mock(CallableStatement.class);
private final CallableStatement callableStatement = mock();
@BeforeEach
@ -233,8 +233,8 @@ class SimpleJdbcCallTests { @@ -233,8 +233,8 @@ class SimpleJdbcCallTests {
*/
@Test // gh-26486
void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
ResultSet proceduresResultSet = mock(ResultSet.class);
ResultSet procedureColumnsResultSet = mock(ResultSet.class);
ResultSet proceduresResultSet = mock();
ResultSet procedureColumnsResultSet = mock();
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
given(databaseMetaData.getUserName()).willReturn("ME");
@ -301,8 +301,8 @@ class SimpleJdbcCallTests { @@ -301,8 +301,8 @@ class SimpleJdbcCallTests {
}
private void initializeAddInvoiceWithMetaData(boolean isFunction) throws SQLException {
ResultSet proceduresResultSet = mock(ResultSet.class);
ResultSet procedureColumnsResultSet = mock(ResultSet.class);
ResultSet proceduresResultSet = mock();
ResultSet procedureColumnsResultSet = mock();
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
given(databaseMetaData.getUserName()).willReturn("ME");
given(databaseMetaData.storesUpperCaseIdentifiers()).willReturn(true);

16
spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java

@ -45,11 +45,11 @@ import static org.mockito.Mockito.verify; @@ -45,11 +45,11 @@ import static org.mockito.Mockito.verify;
*/
class SimpleJdbcInsertTests {
private final Connection connection = mock(Connection.class);
private final Connection connection = mock();
private final DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
private final DatabaseMetaData databaseMetaData = mock();
private final DataSource dataSource = mock(DataSource.class);
private final DataSource dataSource = mock();
@BeforeEach
@ -66,7 +66,7 @@ class SimpleJdbcInsertTests { @@ -66,7 +66,7 @@ class SimpleJdbcInsertTests {
@Test
void noSuchTable() throws Exception {
ResultSet resultSet = mock(ResultSet.class);
ResultSet resultSet = mock();
given(resultSet.next()).willReturn(false);
given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB");
@ -86,13 +86,13 @@ class SimpleJdbcInsertTests { @@ -86,13 +86,13 @@ class SimpleJdbcInsertTests {
@Test // gh-26486
void retrieveColumnNamesFromMetadata() throws Exception {
ResultSet tableResultSet = mock(ResultSet.class);
ResultSet tableResultSet = mock();
given(tableResultSet.next()).willReturn(true, false);
given(databaseMetaData.getUserName()).willReturn("me");
given(databaseMetaData.getTables(null, null, "me", null)).willReturn(tableResultSet);
ResultSet columnResultSet = mock(ResultSet.class);
ResultSet columnResultSet = mock();
given(databaseMetaData.getColumns(null, "me", null, null)).willReturn(columnResultSet);
given(columnResultSet.next()).willReturn(true, true, false);
given(columnResultSet.getString("COLUMN_NAME")).willReturn("col1", "col2");
@ -109,13 +109,13 @@ class SimpleJdbcInsertTests { @@ -109,13 +109,13 @@ class SimpleJdbcInsertTests {
@Test // gh-26486
void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
ResultSet tableResultSet = mock(ResultSet.class);
ResultSet tableResultSet = mock();
given(tableResultSet.next()).willReturn(true, false);
given(databaseMetaData.getUserName()).willReturn("me");
given(databaseMetaData.getTables(null, null, "me", null)).willReturn(tableResultSet);
ResultSet columnResultSet = mock(ResultSet.class);
ResultSet columnResultSet = mock();
given(databaseMetaData.getColumns(null, "me", null, null)).willReturn(columnResultSet);
// true, true, false --> simulates processing of two columns
given(columnResultSet.next()).willReturn(true, true, false);

19
spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java

@ -44,22 +44,19 @@ import static org.mockito.Mockito.verify; @@ -44,22 +44,19 @@ import static org.mockito.Mockito.verify;
*
* @author Thomas Risberg
*/
public class TableMetaDataContextTests {
public class TableMetaDataContextTests {
private Connection connection;
private DataSource dataSource = mock();
private DataSource dataSource;
private Connection connection = mock();
private DatabaseMetaData databaseMetaData;
private DatabaseMetaData databaseMetaData = mock();
private TableMetaDataContext context = new TableMetaDataContext();
@BeforeEach
public void setUp() throws Exception {
connection = mock(Connection.class);
dataSource = mock(DataSource.class);
databaseMetaData = mock(DatabaseMetaData.class);
given(connection.getMetaData()).willReturn(databaseMetaData);
given(dataSource.getConnection()).willReturn(connection);
}
@ -70,13 +67,13 @@ public class TableMetaDataContextTests { @@ -70,13 +67,13 @@ public class TableMetaDataContextTests {
final String TABLE = "customers";
final String USER = "me";
ResultSet metaDataResultSet = mock(ResultSet.class);
ResultSet metaDataResultSet = mock();
given(metaDataResultSet.next()).willReturn(true, false);
given(metaDataResultSet.getString("TABLE_SCHEM")).willReturn(USER);
given(metaDataResultSet.getString("TABLE_NAME")).willReturn(TABLE);
given(metaDataResultSet.getString("TABLE_TYPE")).willReturn("TABLE");
ResultSet columnsResultSet = mock(ResultSet.class);
ResultSet columnsResultSet = mock();
given(columnsResultSet.next()).willReturn(
true, true, true, true, false);
given(columnsResultSet.getString("COLUMN_NAME")).willReturn(
@ -126,13 +123,13 @@ public class TableMetaDataContextTests { @@ -126,13 +123,13 @@ public class TableMetaDataContextTests {
final String TABLE = "customers";
final String USER = "me";
ResultSet metaDataResultSet = mock(ResultSet.class);
ResultSet metaDataResultSet = mock();
given(metaDataResultSet.next()).willReturn(true, false);
given(metaDataResultSet.getString("TABLE_SCHEM")).willReturn(USER);
given(metaDataResultSet.getString("TABLE_NAME")).willReturn(TABLE);
given(metaDataResultSet.getString("TABLE_TYPE")).willReturn("TABLE");
ResultSet columnsResultSet = mock(ResultSet.class);
ResultSet columnsResultSet = mock();
given(columnsResultSet.next()).willReturn(true, false);
given(columnsResultSet.getString("COLUMN_NAME")).willReturn("id");
given(columnsResultSet.getInt("DATA_TYPE")).willReturn(Types.INTEGER);

8
spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReaderTests.java

@ -42,17 +42,17 @@ class JdbcBeanDefinitionReaderTests { @@ -42,17 +42,17 @@ class JdbcBeanDefinitionReaderTests {
void readBeanDefinitionFromMockedDataSource() throws Exception {
String sql = "SELECT NAME AS NAME, PROPERTY AS PROPERTY, VALUE AS VALUE FROM T";
Connection connection = mock(Connection.class);
DataSource dataSource = mock(DataSource.class);
Connection connection = mock();
DataSource dataSource = mock();
given(dataSource.getConnection()).willReturn(connection);
ResultSet resultSet = mock(ResultSet.class);
ResultSet resultSet = mock();
given(resultSet.next()).willReturn(true, true, false);
given(resultSet.getString(1)).willReturn("one", "one");
given(resultSet.getString(2)).willReturn("(class)", "age");
given(resultSet.getString(3)).willReturn("org.springframework.beans.testfixture.beans.TestBean", "53");
Statement statement = mock(Statement.class);
Statement statement = mock();
given(statement.executeQuery(sql)).willReturn(resultSet);
given(connection.createStatement()).willReturn(statement);

2
spring-jdbc/src/test/java/org/springframework/jdbc/core/support/JdbcDaoSupportTests.java

@ -36,7 +36,7 @@ public class JdbcDaoSupportTests { @@ -36,7 +36,7 @@ public class JdbcDaoSupportTests {
@Test
public void testJdbcDaoSupportWithDataSource() throws Exception {
DataSource ds = mock(DataSource.class);
DataSource ds = mock();
final List<String> test = new ArrayList<>();
JdbcDaoSupport dao = new JdbcDaoSupport() {
@Override

14
spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java

@ -42,9 +42,9 @@ public class LobSupportTests { @@ -42,9 +42,9 @@ public class LobSupportTests {
@Test
public void testCreatingPreparedStatementCallback() throws SQLException {
LobHandler handler = mock(LobHandler.class);
LobCreator creator = mock(LobCreator.class);
PreparedStatement ps = mock(PreparedStatement.class);
LobHandler handler = mock();
LobCreator creator = mock();
PreparedStatement ps = mock();
given(handler.getLobCreator()).willReturn(creator);
given(ps.executeUpdate()).willReturn(3);
@ -73,7 +73,7 @@ public class LobSupportTests { @@ -73,7 +73,7 @@ public class LobSupportTests {
@Test
public void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLException {
ResultSet rset = mock(ResultSet.class);
ResultSet rset = mock();
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
lobRse.extractData(rset));
@ -82,7 +82,7 @@ public class LobSupportTests { @@ -82,7 +82,7 @@ public class LobSupportTests {
@Test
public void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLException {
ResultSet rset = mock(ResultSet.class);
ResultSet rset = mock();
given(rset.next()).willReturn(true, false);
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
lobRse.extractData(rset);
@ -92,7 +92,7 @@ public class LobSupportTests { @@ -92,7 +92,7 @@ public class LobSupportTests {
@Test
public void testAbstractLobStreamingResultSetExtractorMultipleRows()
throws SQLException {
ResultSet rset = mock(ResultSet.class);
ResultSet rset = mock();
given(rset.next()).willReturn(true, true, false);
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
@ -103,7 +103,7 @@ public class LobSupportTests { @@ -103,7 +103,7 @@ public class LobSupportTests {
@Test
public void testAbstractLobStreamingResultSetExtractorCorrectException()
throws SQLException {
ResultSet rset = mock(ResultSet.class);
ResultSet rset = mock();
given(rset.next()).willReturn(true);
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(true);
assertThatExceptionOfType(LobRetrievalFailureException.class).isThrownBy(() ->

36
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java

@ -63,19 +63,18 @@ import static org.mockito.Mockito.verify; @@ -63,19 +63,18 @@ import static org.mockito.Mockito.verify;
*/
public class DataSourceJtaTransactionTests {
private Connection connection;
private DataSource dataSource;
private UserTransaction userTransaction;
private TransactionManager transactionManager;
private Transaction transaction;
private DataSource dataSource = mock();
private Connection connection = mock();
private UserTransaction userTransaction = mock();
private TransactionManager transactionManager = mock();
private Transaction transaction = mock();
@BeforeEach
public void setup() throws Exception {
connection =mock(Connection.class);
dataSource = mock(DataSource.class);
userTransaction = mock(UserTransaction.class);
transactionManager = mock(TransactionManager.class);
transaction = mock(Transaction.class);
given(dataSource.getConnection()).willReturn(connection);
}
@ -365,9 +364,9 @@ public class DataSourceJtaTransactionTests { @@ -365,9 +364,9 @@ public class DataSourceJtaTransactionTests {
Status.STATUS_ACTIVE);
}
final DataSource dataSource = mock(DataSource.class);
final Connection connection1 = mock(Connection.class);
final Connection connection2 = mock(Connection.class);
final DataSource dataSource = mock();
final Connection connection1 = mock();
final Connection connection2 = mock();
given(dataSource.getConnection()).willReturn(connection1, connection2);
final JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
@ -686,14 +685,15 @@ public class DataSourceJtaTransactionTests { @@ -686,14 +685,15 @@ public class DataSourceJtaTransactionTests {
}
private void doTestJtaTransactionWithIsolationLevelDataSourceRouter(boolean dataSourceLookup) throws Exception {
given( userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
given(userTransaction.getStatus())
.willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
final DataSource dataSource1 = mock(DataSource.class);
final Connection connection1 = mock(Connection.class);
final DataSource dataSource1 = mock();
final Connection connection1 = mock();
given(dataSource1.getConnection()).willReturn(connection1);
final DataSource dataSource2 = mock(DataSource.class);
final Connection connection2 = mock(Connection.class);
final DataSource dataSource2 = mock();
final Connection connection2 = mock();
given(dataSource2.getConnection()).willReturn(connection2);
final IsolationLevelDataSourceRouter dsToUse = new IsolationLevelDataSourceRouter();

53
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java

@ -67,21 +67,18 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING; @@ -67,21 +67,18 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
* @since 04.07.2003
* @see org.springframework.jdbc.support.JdbcTransactionManagerTests
*/
public class DataSourceTransactionManagerTests {
public class DataSourceTransactionManagerTests {
private DataSource ds;
private DataSource ds = mock();
private Connection con;
private Connection con = mock();
private DataSourceTransactionManager tm;
private DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);
@BeforeEach
public void setup() throws Exception {
ds = mock(DataSource.class);
con = mock(Connection.class);
given(ds.getConnection()).willReturn(con);
tm = new DataSourceTransactionManager(ds);
}
@AfterEach
@ -515,8 +512,8 @@ public class DataSourceTransactionManagerTests { @@ -515,8 +512,8 @@ public class DataSourceTransactionManagerTests {
@Test
public void testParticipatingTransactionWithDifferentConnectionObtainedFromSynch() throws Exception {
DataSource ds2 = mock(DataSource.class);
final Connection con2 = mock(Connection.class);
DataSource ds2 = mock();
final Connection con2 = mock();
given(ds2.getConnection()).willReturn(con2);
boolean condition2 = !TransactionSynchronizationManager.hasResource(ds);
@ -651,8 +648,8 @@ public class DataSourceTransactionManagerTests { @@ -651,8 +648,8 @@ public class DataSourceTransactionManagerTests {
@Test
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedDataSource() throws Exception {
Connection con2 = mock(Connection.class);
final DataSource ds2 = mock(DataSource.class);
Connection con2 = mock();
final DataSource ds2 = mock();
given(ds2.getConnection()).willReturn(con2);
final TransactionTemplate tt = new TransactionTemplate(tm);
@ -705,7 +702,7 @@ public class DataSourceTransactionManagerTests { @@ -705,7 +702,7 @@ public class DataSourceTransactionManagerTests {
@Test
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedFailingDataSource() throws Exception {
final DataSource ds2 = mock(DataSource.class);
final DataSource ds2 = mock();
SQLException failure = new SQLException();
given(ds2.getConnection()).willThrow(failure);
@ -857,8 +854,8 @@ public class DataSourceTransactionManagerTests { @@ -857,8 +854,8 @@ public class DataSourceTransactionManagerTests {
@Test
public void testPropagationSupportsAndRequiresNewWithEarlyAccess() throws Exception {
final Connection con1 = mock(Connection.class);
final Connection con2 = mock(Connection.class);
final Connection con1 = mock();
final Connection con2 = mock();
given(ds.getConnection()).willReturn(con1, con2);
final
@ -936,7 +933,7 @@ public class DataSourceTransactionManagerTests { @@ -936,7 +933,7 @@ public class DataSourceTransactionManagerTests {
tm.setEnforceReadOnly(true);
given(con.getAutoCommit()).willReturn(true);
Statement stmt = mock(Statement.class);
Statement stmt = mock();
given(con.createStatement()).willReturn(stmt);
TransactionTemplate tt = new TransactionTemplate(tm);
@ -970,7 +967,7 @@ public class DataSourceTransactionManagerTests { @@ -970,7 +967,7 @@ public class DataSourceTransactionManagerTests {
@ValueSource(ints = {1, 10})
@EnabledForTestGroups(LONG_RUNNING)
public void transactionWithTimeout(int timeout) throws Exception {
PreparedStatement ps = mock(PreparedStatement.class);
PreparedStatement ps = mock();
given(con.getAutoCommit()).willReturn(true);
given(con.prepareStatement("some SQL statement")).willReturn(ps);
@ -1342,8 +1339,8 @@ public class DataSourceTransactionManagerTests { @@ -1342,8 +1339,8 @@ public class DataSourceTransactionManagerTests {
}
private void doTestExistingTransactionWithPropagationNested(final int count) throws Exception {
DatabaseMetaData md = mock(DatabaseMetaData.class);
Savepoint sp = mock(Savepoint.class);
DatabaseMetaData md = mock();
Savepoint sp = mock();
given(md.supportsSavepoints()).willReturn(true);
given(con.getMetaData()).willReturn(md);
@ -1391,8 +1388,8 @@ public class DataSourceTransactionManagerTests { @@ -1391,8 +1388,8 @@ public class DataSourceTransactionManagerTests {
@Test
public void testExistingTransactionWithPropagationNestedAndRollback() throws Exception {
DatabaseMetaData md = mock(DatabaseMetaData.class);
Savepoint sp = mock(Savepoint.class);
DatabaseMetaData md = mock();
Savepoint sp = mock();
given(md.supportsSavepoints()).willReturn(true);
given(con.getMetaData()).willReturn(md);
@ -1438,8 +1435,8 @@ public class DataSourceTransactionManagerTests { @@ -1438,8 +1435,8 @@ public class DataSourceTransactionManagerTests {
@Test
public void testExistingTransactionWithPropagationNestedAndRequiredRollback() throws Exception {
DatabaseMetaData md = mock(DatabaseMetaData.class);
Savepoint sp = mock(Savepoint.class);
DatabaseMetaData md = mock();
Savepoint sp = mock();
given(md.supportsSavepoints()).willReturn(true);
given(con.getMetaData()).willReturn(md);
@ -1498,8 +1495,8 @@ public class DataSourceTransactionManagerTests { @@ -1498,8 +1495,8 @@ public class DataSourceTransactionManagerTests {
@Test
public void testExistingTransactionWithPropagationNestedAndRequiredRollbackOnly() throws Exception {
DatabaseMetaData md = mock(DatabaseMetaData.class);
Savepoint sp = mock(Savepoint.class);
DatabaseMetaData md = mock();
Savepoint sp = mock();
given(md.supportsSavepoints()).willReturn(true);
given(con.getMetaData()).willReturn(md);
@ -1558,8 +1555,8 @@ public class DataSourceTransactionManagerTests { @@ -1558,8 +1555,8 @@ public class DataSourceTransactionManagerTests {
@Test
public void testExistingTransactionWithManualSavepoint() throws Exception {
DatabaseMetaData md = mock(DatabaseMetaData.class);
Savepoint sp = mock(Savepoint.class);
DatabaseMetaData md = mock();
Savepoint sp = mock();
given(md.supportsSavepoints()).willReturn(true);
given(con.getMetaData()).willReturn(md);
@ -1592,8 +1589,8 @@ public class DataSourceTransactionManagerTests { @@ -1592,8 +1589,8 @@ public class DataSourceTransactionManagerTests {
@Test
public void testExistingTransactionWithManualSavepointAndRollback() throws Exception {
DatabaseMetaData md = mock(DatabaseMetaData.class);
Savepoint sp = mock(Savepoint.class);
DatabaseMetaData md = mock();
Savepoint sp = mock();
given(md.supportsSavepoints()).willReturn(true);
given(con.getMetaData()).willReturn(md);

4
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceUtilsTests.java

@ -38,7 +38,7 @@ class DataSourceUtilsTests { @@ -38,7 +38,7 @@ class DataSourceUtilsTests {
@Test
void testConnectionNotAcquiredExceptionIsPropagated() throws SQLException {
DataSource dataSource = mock(DataSource.class);
DataSource dataSource = mock();
when(dataSource.getConnection()).thenReturn(null);
assertThatThrownBy(() -> DataSourceUtils.getConnection(dataSource))
.isInstanceOf(CannotGetJdbcConnectionException.class)
@ -48,7 +48,7 @@ class DataSourceUtilsTests { @@ -48,7 +48,7 @@ class DataSourceUtilsTests {
@Test
void testConnectionSQLExceptionIsPropagated() throws SQLException {
DataSource dataSource = mock(DataSource.class);
DataSource dataSource = mock();
when(dataSource.getConnection()).thenThrow(new SQLException("my dummy exception"));
assertThatThrownBy(() -> DataSourceUtils.getConnection(dataSource))
.isInstanceOf(CannotGetJdbcConnectionException.class)

8
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DelegatingDataSourceTests.java

@ -36,20 +36,20 @@ import static org.mockito.Mockito.verify; @@ -36,20 +36,20 @@ import static org.mockito.Mockito.verify;
*/
public class DelegatingDataSourceTests {
private final DataSource delegate = mock(DataSource.class);
private final DataSource delegate = mock();
private DelegatingDataSource dataSource = new DelegatingDataSource(delegate);
@Test
public void shouldDelegateGetConnection() throws Exception {
Connection connection = mock(Connection.class);
Connection connection = mock();
given(delegate.getConnection()).willReturn(connection);
assertThat(dataSource.getConnection()).isEqualTo(connection);
}
@Test
public void shouldDelegateGetConnectionWithUsernameAndPassword() throws Exception {
Connection connection = mock(Connection.class);
Connection connection = mock();
String username = "username";
String password = "password";
given(delegate.getConnection(username, password)).willReturn(connection);
@ -86,7 +86,7 @@ public class DelegatingDataSourceTests { @@ -86,7 +86,7 @@ public class DelegatingDataSourceTests {
@Test
public void shouldDelegateUnwrapWithoutImplementing() throws Exception {
ExampleWrapper wrapper = mock(ExampleWrapper.class);
ExampleWrapper wrapper = mock();
given(delegate.unwrap(ExampleWrapper.class)).willReturn(wrapper);
assertThat(dataSource.unwrap(ExampleWrapper.class)).isEqualTo(wrapper);
}

2
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DriverManagerDataSourceTests.java

@ -30,7 +30,7 @@ import static org.mockito.Mockito.mock; @@ -30,7 +30,7 @@ import static org.mockito.Mockito.mock;
*/
public class DriverManagerDataSourceTests {
private Connection connection = mock(Connection.class);
private Connection connection = mock();
@Test
public void testStandardUsage() throws Exception {

12
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapterTests.java

@ -35,8 +35,8 @@ public class UserCredentialsDataSourceAdapterTests { @@ -35,8 +35,8 @@ public class UserCredentialsDataSourceAdapterTests {
@Test
public void testStaticCredentials() throws SQLException {
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
DataSource dataSource = mock();
Connection connection = mock();
given(dataSource.getConnection("user", "pw")).willReturn(connection);
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
@ -48,8 +48,8 @@ public class UserCredentialsDataSourceAdapterTests { @@ -48,8 +48,8 @@ public class UserCredentialsDataSourceAdapterTests {
@Test
public void testNoCredentials() throws SQLException {
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
DataSource dataSource = mock();
Connection connection = mock();
given(dataSource.getConnection()).willReturn(connection);
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
adapter.setTargetDataSource(dataSource);
@ -58,8 +58,8 @@ public class UserCredentialsDataSourceAdapterTests { @@ -58,8 +58,8 @@ public class UserCredentialsDataSourceAdapterTests {
@Test
public void testThreadBoundCredentials() throws SQLException {
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
DataSource dataSource = mock();
Connection connection = mock();
given(dataSource.getConnection("user", "pw")).willReturn(connection);
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();

2
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/AbstractDatabasePopulatorTests.java

@ -169,7 +169,7 @@ abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseInitializa @@ -169,7 +169,7 @@ abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseInitializa
void usesBoundConnectionIfAvailable() throws SQLException {
TransactionSynchronizationManager.initSynchronization();
Connection connection = DataSourceUtils.getConnection(db);
DatabasePopulator populator = mock(DatabasePopulator.class);
DatabasePopulator populator = mock();
DatabasePopulatorUtils.execute(populator, db);
verify(populator).populate(connection);
}

6
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/CompositeDatabasePopulatorTests.java

@ -36,11 +36,11 @@ import static org.mockito.Mockito.verify; @@ -36,11 +36,11 @@ import static org.mockito.Mockito.verify;
*/
class CompositeDatabasePopulatorTests {
private final Connection mockedConnection = mock(Connection.class);
private final Connection mockedConnection = mock();
private final DatabasePopulator mockedDatabasePopulator1 = mock(DatabasePopulator.class);
private final DatabasePopulator mockedDatabasePopulator1 = mock();
private final DatabasePopulator mockedDatabasePopulator2 = mock(DatabasePopulator.class);
private final DatabasePopulator mockedDatabasePopulator2 = mock();
@Test

6
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorUnitTests.java

@ -33,9 +33,9 @@ import static org.mockito.BDDMockito.mock; @@ -33,9 +33,9 @@ import static org.mockito.BDDMockito.mock;
*/
class ResourceDatabasePopulatorUnitTests {
private static final Resource script1 = mock(Resource.class);
private static final Resource script2 = mock(Resource.class);
private static final Resource script3 = mock(Resource.class);
private static final Resource script1 = mock();
private static final Resource script2 = mock();
private static final Resource script3 = mock();
@Test

4
spring-jdbc/src/test/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookupTests.java

@ -41,7 +41,7 @@ public class BeanFactoryDataSourceLookupTests { @@ -41,7 +41,7 @@ public class BeanFactoryDataSourceLookupTests {
@Test
public void testLookupSunnyDay() {
BeanFactory beanFactory = mock(BeanFactory.class);
BeanFactory beanFactory = mock();
StubDataSource expectedDataSource = new StubDataSource();
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willReturn(expectedDataSource);
@ -56,7 +56,7 @@ public class BeanFactoryDataSourceLookupTests { @@ -56,7 +56,7 @@ public class BeanFactoryDataSourceLookupTests {
@Test
public void testLookupWhereBeanFactoryYieldsNonDataSourceType() throws Exception {
final BeanFactory beanFactory = mock(BeanFactory.class);
final BeanFactory beanFactory = mock();
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willThrow(
new BeanNotOfRequiredTypeException(DATASOURCE_BEAN_NAME,

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save