Migrate to Mockito.mock(T...) where feasible
This commit is contained in:
parent
c3d123fef7
commit
c4c786596f
|
@ -151,7 +151,7 @@ class ScheduledAndTransactionalAnnotationIntegrationTests {
|
|||
|
||||
@Bean
|
||||
PersistenceExceptionTranslator peTranslator() {
|
||||
return mock(PersistenceExceptionTranslator.class);
|
||||
return mock();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -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 {
|
|||
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 {
|
|||
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 {
|
|||
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 {
|
|||
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))
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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(() ->
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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(() ->
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
|
||||
@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 {
|
|||
}
|
||||
|
||||
@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 {
|
|||
}
|
||||
|
||||
@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 {
|
|||
|
||||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDelegateReturnsThisIsMassagedToReturnProxy() {
|
||||
void testDelegateReturnsThisIsMassagedToReturnProxy() {
|
||||
NestedTestBean target = new NestedTestBean();
|
||||
String company = "Interface21";
|
||||
target.setCompany(company);
|
||||
|
@ -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 {
|
|||
|
||||
// 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 {
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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 {
|
|||
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));
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
|||
@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 {
|
|||
@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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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;
|
|||
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 {
|
|||
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 {
|
|||
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();
|
||||
|
|
|
@ -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;
|
|||
|
||||
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 {
|
|||
@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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
|||
@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);
|
||||
}
|
||||
|
|
|
@ -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()");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
// we need the real target too, not just the proxy...
|
||||
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
||||
|
||||
mockCollaborator = mock(AdviceBindingCollaborator.class);
|
||||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class AfterReturningAdviceBindingTests {
|
|||
|
||||
private TestBean testBeanTarget;
|
||||
|
||||
private AfterReturningAdviceBindingCollaborator mockCollaborator;
|
||||
private AfterReturningAdviceBindingCollaborator mockCollaborator = mock();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
|
@ -59,7 +59,6 @@ class AfterReturningAdviceBindingTests {
|
|||
|
||||
afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
|
||||
mockCollaborator = mock(AfterReturningAdviceBindingCollaborator.class);
|
||||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||
|
||||
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||
|
|
|
@ -42,7 +42,7 @@ class AfterThrowingAdviceBindingTests {
|
|||
|
||||
private AfterThrowingAdviceBindingTestAspect afterThrowingAdviceAspect;
|
||||
|
||||
private AfterThrowingAdviceBindingCollaborator mockCollaborator;
|
||||
private AfterThrowingAdviceBindingCollaborator mockCollaborator = mock();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
|
@ -52,7 +52,6 @@ class AfterThrowingAdviceBindingTests {
|
|||
testBean = (ITestBean) ctx.getBean("testBean");
|
||||
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
|
||||
mockCollaborator = mock(AfterThrowingAdviceBindingCollaborator.class);
|
||||
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
|||
|
||||
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 {
|
|||
|
||||
this.testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
||||
|
||||
mockCollaborator = mock(AroundAdviceBindingCollaborator.class);
|
||||
aroundAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
|||
|
||||
AdviceBindingTestAspect beforeAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
|
||||
mockCollaborator = mock(AdviceBindingCollaborator.class);
|
||||
beforeAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
|||
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() {
|
||||
|
|
|
@ -183,7 +183,7 @@ class CacheErrorHandlerTests {
|
|||
@Bean
|
||||
@Override
|
||||
public CacheErrorHandler errorHandler() {
|
||||
return mock(CacheErrorHandler.class);
|
||||
return mock();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ class EnableLoadTimeWeavingTests {
|
|||
|
||||
@Override
|
||||
public LoadTimeWeaver getLoadTimeWeaver() {
|
||||
return mock(LoadTimeWeaver.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ class EnableLoadTimeWeavingTests {
|
|||
|
||||
@Override
|
||||
public LoadTimeWeaver getLoadTimeWeaver() {
|
||||
return mock(LoadTimeWeaver.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ class EnableLoadTimeWeavingTests {
|
|||
|
||||
@Override
|
||||
public LoadTimeWeaver getLoadTimeWeaver() {
|
||||
return mock(LoadTimeWeaver.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
BeanFactoryInitializationAotContribution contribution = this.processor.processAheadOfTime(beanFactory);
|
||||
assertThat(contribution).isNotNull();
|
||||
contribution.applyTo(this.generationContext, mock(BeanFactoryInitializationCode.class));
|
||||
contribution.applyTo(this.generationContext, mock());
|
||||
}
|
||||
|
||||
@Reflective
|
||||
|
|
|
@ -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
|
|||
@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
|
|||
@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
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,7 +47,7 @@ class EventPublicationInterceptorTests {
|
|||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
|
||||
ApplicationEventPublisher publisher = mock();
|
||||
this.interceptor.setApplicationEventPublisher(publisher);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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 {
|
|||
@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 {
|
|||
}
|
||||
|
||||
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());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
|||
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 {
|
|||
@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 {
|
|||
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 {
|
|||
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 {
|
|||
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 {
|
|||
@Test
|
||||
public void testUnbind() throws Exception {
|
||||
String name = "something";
|
||||
final Context context = mock(Context.class);
|
||||
final Context context = mock();
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
@Override
|
||||
|
|
|
@ -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;
|
|||
|
||||
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 {
|
|||
@Bean
|
||||
@Lazy
|
||||
public AsyncBean asyncBean() {
|
||||
return Mockito.mock(AsyncBean.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
|||
@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 {
|
|||
@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 {
|
|||
@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 {
|
|||
@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 {
|
|||
@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 {
|
|||
@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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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");
|
||||
|
||||
|
|
|
@ -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 {
|
|||
@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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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 {
|
|||
@Test
|
||||
void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
new ScriptFactoryPostProcessor().setBeanFactory(mock(BeanFactory.class)));
|
||||
new ScriptFactoryPostProcessor().setBeanFactory(mock()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@Test
|
||||
void createWhenAnnotationAggregateIndexIsNotZeroThrowsException() {
|
||||
MergedAnnotation<?> annotation = mock(MergedAnnotation.class);
|
||||
MergedAnnotation<?> annotation = mock();
|
||||
given(annotation.isDirectlyPresent()).willReturn(true);
|
||||
given(annotation.getAggregateIndex()).willReturn(1);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
|||
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 {
|
|||
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 {
|
|||
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 {
|
|||
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'))
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@Test
|
||||
void nonClosingOutputStream() throws Exception {
|
||||
OutputStream source = mock(OutputStream.class);
|
||||
OutputStream source = mock();
|
||||
OutputStream nonClosing = StreamUtils.nonClosing(source);
|
||||
nonClosing.write(1);
|
||||
nonClosing.write(bytes);
|
||||
|
|
|
@ -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 {
|
|||
@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 {
|
|||
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 {
|
|||
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 {
|
|||
@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();
|
||||
|
||||
|
|
|
@ -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;
|
|||
@SuppressWarnings("deprecation")
|
||||
class FutureAdapterTests {
|
||||
|
||||
private FutureAdapter<String, Integer> adapter;
|
||||
|
||||
private Future<Integer> adaptee;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
void setUp() {
|
||||
adaptee = mock(Future.class);
|
||||
adapter = new FutureAdapter<>(adaptee) {
|
||||
@Override
|
||||
protected String adapt(Integer adapteeResult) throws ExecutionException {
|
||||
return adapteeResult.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
private Future<Integer> adaptee = mock();
|
||||
|
||||
private FutureAdapter<String, Integer> adapter = new FutureAdapter<>(adaptee) {
|
||||
@Override
|
||||
protected String adapt(Integer adapteeResult) throws ExecutionException {
|
||||
return adapteeResult.toString();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
void cancel() {
|
||||
|
|
|
@ -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 {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
@Test
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public void cancelDoesNotNotifyCallbacksOnSetException() {
|
||||
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
|
||||
ListenableFutureCallback callback = mock();
|
||||
settableListenableFuture.addCallback(callback);
|
||||
settableListenableFuture.cancel(true);
|
||||
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
|
||||
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 -> {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
|||
@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 {
|
|||
@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 {
|
|||
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 {
|
|||
|
||||
@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 {
|
|||
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 {
|
|||
|
||||
|
||||
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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 {
|
|||
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 {
|
|||
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))
|
||||
|
|
|
@ -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;
|
|||
*/
|
||||
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 {
|
|||
@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 {
|
|||
@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 {
|
|||
@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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
@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");
|
||||
|
|
|
@ -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 NamedParameterJdbcTemplate namedParameterTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterTemplate;
|
||||
|
||||
|
||||
@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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
|||
*/
|
||||
@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 {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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 {
|
|||
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 {
|
|||
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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
@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 {
|
|||
@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(() ->
|
||||
|
|
|
@ -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 {
|
|||
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 {
|
|||
}
|
||||
|
||||
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();
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
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 {
|
|||
@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 {
|
|||
}
|
||||
|
||||
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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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)
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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 {
|
|||
|
||||
@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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
|||
|
||||
@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…
Reference in New Issue