Migrate to Mockito.mock(T...) where feasible
This commit is contained in:
parent
c3d123fef7
commit
c4c786596f
|
@ -151,7 +151,7 @@ class ScheduledAndTransactionalAnnotationIntegrationTests {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
PersistenceExceptionTranslator peTranslator() {
|
PersistenceExceptionTranslator peTranslator() {
|
||||||
return mock(PersistenceExceptionTranslator.class);
|
return mock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class ThrowsAdviceInterceptorTests {
|
||||||
MyThrowsHandler th = new MyThrowsHandler();
|
MyThrowsHandler th = new MyThrowsHandler();
|
||||||
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
||||||
Object ret = new Object();
|
Object ret = new Object();
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock();
|
||||||
given(mi.proceed()).willReturn(ret);
|
given(mi.proceed()).willReturn(ret);
|
||||||
assertThat(ti.invoke(mi)).isEqualTo(ret);
|
assertThat(ti.invoke(mi)).isEqualTo(ret);
|
||||||
assertThat(th.getCalls()).isEqualTo(0);
|
assertThat(th.getCalls()).isEqualTo(0);
|
||||||
|
@ -62,7 +62,7 @@ public class ThrowsAdviceInterceptorTests {
|
||||||
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
||||||
assertThat(ti.getHandlerMethodCount()).isEqualTo(2);
|
assertThat(ti.getHandlerMethodCount()).isEqualTo(2);
|
||||||
Exception ex = new Exception();
|
Exception ex = new Exception();
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock();
|
||||||
given(mi.proceed()).willThrow(ex);
|
given(mi.proceed()).willThrow(ex);
|
||||||
assertThatException().isThrownBy(() -> ti.invoke(mi)).isSameAs(ex);
|
assertThatException().isThrownBy(() -> ti.invoke(mi)).isSameAs(ex);
|
||||||
assertThat(th.getCalls()).isEqualTo(0);
|
assertThat(th.getCalls()).isEqualTo(0);
|
||||||
|
@ -73,7 +73,7 @@ public class ThrowsAdviceInterceptorTests {
|
||||||
MyThrowsHandler th = new MyThrowsHandler();
|
MyThrowsHandler th = new MyThrowsHandler();
|
||||||
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
||||||
FileNotFoundException ex = new FileNotFoundException();
|
FileNotFoundException ex = new FileNotFoundException();
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock();
|
||||||
given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode"));
|
given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode"));
|
||||||
given(mi.getThis()).willReturn(new Object());
|
given(mi.getThis()).willReturn(new Object());
|
||||||
given(mi.proceed()).willThrow(ex);
|
given(mi.proceed()).willThrow(ex);
|
||||||
|
@ -90,7 +90,7 @@ public class ThrowsAdviceInterceptorTests {
|
||||||
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
||||||
// Extends RemoteException
|
// Extends RemoteException
|
||||||
ConnectException ex = new ConnectException("");
|
ConnectException ex = new ConnectException("");
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock();
|
||||||
given(mi.proceed()).willThrow(ex);
|
given(mi.proceed()).willThrow(ex);
|
||||||
assertThatExceptionOfType(ConnectException.class).isThrownBy(() ->
|
assertThatExceptionOfType(ConnectException.class).isThrownBy(() ->
|
||||||
ti.invoke(mi))
|
ti.invoke(mi))
|
||||||
|
@ -115,7 +115,7 @@ public class ThrowsAdviceInterceptorTests {
|
||||||
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
||||||
// Extends RemoteException
|
// Extends RemoteException
|
||||||
ConnectException ex = new ConnectException("");
|
ConnectException ex = new ConnectException("");
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock();
|
||||||
given(mi.proceed()).willThrow(ex);
|
given(mi.proceed()).willThrow(ex);
|
||||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||||
ti.invoke(mi))
|
ti.invoke(mi))
|
||||||
|
|
|
@ -94,12 +94,11 @@ public class CustomizableTraceInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSunnyDayPathLogsCorrectly() throws Throwable {
|
public void testSunnyDayPathLogsCorrectly() throws Throwable {
|
||||||
|
MethodInvocation methodInvocation = mock();
|
||||||
MethodInvocation methodInvocation = mock(MethodInvocation.class);
|
|
||||||
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
|
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
|
||||||
given(methodInvocation.getThis()).willReturn(this);
|
given(methodInvocation.getThis()).willReturn(this);
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
given(log.isTraceEnabled()).willReturn(true);
|
given(log.isTraceEnabled()).willReturn(true);
|
||||||
|
|
||||||
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
|
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
|
||||||
|
@ -110,15 +109,14 @@ public class CustomizableTraceInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionPathLogsCorrectly() throws Throwable {
|
public void testExceptionPathLogsCorrectly() throws Throwable {
|
||||||
|
MethodInvocation methodInvocation = mock();
|
||||||
MethodInvocation methodInvocation = mock(MethodInvocation.class);
|
|
||||||
|
|
||||||
IllegalArgumentException exception = new IllegalArgumentException();
|
IllegalArgumentException exception = new IllegalArgumentException();
|
||||||
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
|
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
|
||||||
given(methodInvocation.getThis()).willReturn(this);
|
given(methodInvocation.getThis()).willReturn(this);
|
||||||
given(methodInvocation.proceed()).willThrow(exception);
|
given(methodInvocation.proceed()).willThrow(exception);
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
given(log.isTraceEnabled()).willReturn(true);
|
given(log.isTraceEnabled()).willReturn(true);
|
||||||
|
|
||||||
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
|
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
|
||||||
|
@ -131,15 +129,14 @@ public class CustomizableTraceInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Throwable {
|
public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Throwable {
|
||||||
|
MethodInvocation methodInvocation = mock();
|
||||||
MethodInvocation methodInvocation = mock(MethodInvocation.class);
|
|
||||||
|
|
||||||
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
|
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
|
||||||
given(methodInvocation.getThis()).willReturn(this);
|
given(methodInvocation.getThis()).willReturn(this);
|
||||||
given(methodInvocation.getArguments()).willReturn(new Object[]{"$ One \\$", 2L});
|
given(methodInvocation.getArguments()).willReturn(new Object[]{"$ One \\$", 2L});
|
||||||
given(methodInvocation.proceed()).willReturn("Hello!");
|
given(methodInvocation.proceed()).willReturn("Hello!");
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
given(log.isTraceEnabled()).willReturn(true);
|
given(log.isTraceEnabled()).willReturn(true);
|
||||||
|
|
||||||
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
|
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
|
||||||
|
|
|
@ -39,10 +39,9 @@ public class DebugInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSunnyDayPathLogsCorrectly() throws Throwable {
|
public void testSunnyDayPathLogsCorrectly() throws Throwable {
|
||||||
|
MethodInvocation methodInvocation = mock();
|
||||||
|
|
||||||
MethodInvocation methodInvocation = mock(MethodInvocation.class);
|
Log log = mock();
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
|
||||||
given(log.isTraceEnabled()).willReturn(true);
|
given(log.isTraceEnabled()).willReturn(true);
|
||||||
|
|
||||||
DebugInterceptor interceptor = new StubDebugInterceptor(log);
|
DebugInterceptor interceptor = new StubDebugInterceptor(log);
|
||||||
|
@ -54,13 +53,12 @@ public class DebugInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionPathStillLogsCorrectly() throws Throwable {
|
public void testExceptionPathStillLogsCorrectly() throws Throwable {
|
||||||
|
MethodInvocation methodInvocation = mock();
|
||||||
MethodInvocation methodInvocation = mock(MethodInvocation.class);
|
|
||||||
|
|
||||||
IllegalArgumentException exception = new IllegalArgumentException();
|
IllegalArgumentException exception = new IllegalArgumentException();
|
||||||
given(methodInvocation.proceed()).willThrow(exception);
|
given(methodInvocation.proceed()).willThrow(exception);
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
given(log.isTraceEnabled()).willReturn(true);
|
given(log.isTraceEnabled()).willReturn(true);
|
||||||
|
|
||||||
DebugInterceptor interceptor = new StubDebugInterceptor(log);
|
DebugInterceptor interceptor = new StubDebugInterceptor(log);
|
||||||
|
|
|
@ -50,10 +50,10 @@ public class PerformanceMonitorInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSunnyDayPathLogsPerformanceMetricsCorrectly() throws Throwable {
|
public void testSunnyDayPathLogsPerformanceMetricsCorrectly() throws Throwable {
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock();
|
||||||
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
|
given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
|
|
||||||
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
|
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
|
||||||
interceptor.invokeUnderTrace(mi, log);
|
interceptor.invokeUnderTrace(mi, log);
|
||||||
|
@ -63,11 +63,11 @@ public class PerformanceMonitorInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionPathStillLogsPerformanceMetricsCorrectly() throws Throwable {
|
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.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
|
||||||
given(mi.proceed()).willThrow(new IllegalArgumentException());
|
given(mi.proceed()).willThrow(new IllegalArgumentException());
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
|
|
||||||
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
|
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
|
|
|
@ -38,11 +38,11 @@ public class SimpleTraceInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSunnyDayPathLogsCorrectly() throws Throwable {
|
public void testSunnyDayPathLogsCorrectly() throws Throwable {
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock();
|
||||||
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
|
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
|
||||||
given(mi.getThis()).willReturn(this);
|
given(mi.getThis()).willReturn(this);
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
|
|
||||||
SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
|
SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
|
||||||
interceptor.invokeUnderTrace(mi, log);
|
interceptor.invokeUnderTrace(mi, log);
|
||||||
|
@ -52,13 +52,13 @@ public class SimpleTraceInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptionPathStillLogsCorrectly() throws Throwable {
|
public void testExceptionPathStillLogsCorrectly() throws Throwable {
|
||||||
MethodInvocation mi = mock(MethodInvocation.class);
|
MethodInvocation mi = mock();
|
||||||
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
|
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
|
||||||
given(mi.getThis()).willReturn(this);
|
given(mi.getThis()).willReturn(this);
|
||||||
IllegalArgumentException exception = new IllegalArgumentException();
|
IllegalArgumentException exception = new IllegalArgumentException();
|
||||||
given(mi.proceed()).willThrow(exception);
|
given(mi.proceed()).willThrow(exception);
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
|
|
||||||
final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
|
final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class DefaultScopedObjectTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testBadTargetBeanName(final String badTargetBeanName) {
|
private static void testBadTargetBeanName(final String badTargetBeanName) {
|
||||||
ConfigurableBeanFactory factory = mock(ConfigurableBeanFactory.class);
|
ConfigurableBeanFactory factory = mock();
|
||||||
new DefaultScopedObject(factory, badTargetBeanName);
|
new DefaultScopedObject(factory, badTargetBeanName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,22 +44,22 @@ import static org.mockito.Mockito.mock;
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @since 13.05.2003
|
* @since 13.05.2003
|
||||||
*/
|
*/
|
||||||
public class DelegatingIntroductionInterceptorTests {
|
class DelegatingIntroductionInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullTarget() throws Exception {
|
void testNullTarget() throws Exception {
|
||||||
// Shouldn't accept null target
|
// Shouldn't accept null target
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
new DelegatingIntroductionInterceptor(null));
|
new DelegatingIntroductionInterceptor(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntroductionInterceptorWithDelegation() throws Exception {
|
void testIntroductionInterceptorWithDelegation() throws Exception {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
||||||
ProxyFactory factory = new ProxyFactory(raw);
|
ProxyFactory factory = new ProxyFactory(raw);
|
||||||
|
|
||||||
TimeStamped ts = mock(TimeStamped.class);
|
TimeStamped ts = mock();
|
||||||
long timestamp = 111L;
|
long timestamp = 111L;
|
||||||
given(ts.getTimeStamp()).willReturn(timestamp);
|
given(ts.getTimeStamp()).willReturn(timestamp);
|
||||||
|
|
||||||
|
@ -70,12 +70,12 @@ public class DelegatingIntroductionInterceptorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
|
void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
assertThat(! (raw instanceof SubTimeStamped)).isTrue();
|
assertThat(! (raw instanceof SubTimeStamped)).isTrue();
|
||||||
ProxyFactory factory = new ProxyFactory(raw);
|
ProxyFactory factory = new ProxyFactory(raw);
|
||||||
|
|
||||||
TimeStamped ts = mock(SubTimeStamped.class);
|
SubTimeStamped ts = mock();
|
||||||
long timestamp = 111L;
|
long timestamp = 111L;
|
||||||
given(ts.getTimeStamp()).willReturn(timestamp);
|
given(ts.getTimeStamp()).willReturn(timestamp);
|
||||||
|
|
||||||
|
@ -86,12 +86,12 @@ public class DelegatingIntroductionInterceptorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
|
void testIntroductionInterceptorWithSuperInterface() throws Exception {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
||||||
ProxyFactory factory = new ProxyFactory(raw);
|
ProxyFactory factory = new ProxyFactory(raw);
|
||||||
|
|
||||||
TimeStamped ts = mock(SubTimeStamped.class);
|
SubTimeStamped ts = mock();
|
||||||
long timestamp = 111L;
|
long timestamp = 111L;
|
||||||
given(ts.getTimeStamp()).willReturn(timestamp);
|
given(ts.getTimeStamp()).willReturn(timestamp);
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public class DelegatingIntroductionInterceptorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAutomaticInterfaceRecognitionInDelegate() throws Exception {
|
void testAutomaticInterfaceRecognitionInDelegate() throws Exception {
|
||||||
final long t = 1001L;
|
final long t = 1001L;
|
||||||
class Tester implements TimeStamped, ITester {
|
class Tester implements TimeStamped, ITester {
|
||||||
@Override
|
@Override
|
||||||
|
@ -133,7 +133,7 @@ public class DelegatingIntroductionInterceptorTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAutomaticInterfaceRecognitionInSubclass() throws Exception {
|
void testAutomaticInterfaceRecognitionInSubclass() throws Exception {
|
||||||
final long t = 1001L;
|
final long t = 1001L;
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester {
|
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped, ITester {
|
||||||
|
@ -179,7 +179,7 @@ public class DelegatingIntroductionInterceptorTests {
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@Test
|
@Test
|
||||||
public void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
|
void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
|
||||||
TestBean raw = new TestBean();
|
TestBean raw = new TestBean();
|
||||||
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
||||||
ProxyFactory factory = new ProxyFactory(raw);
|
ProxyFactory factory = new ProxyFactory(raw);
|
||||||
|
@ -200,7 +200,7 @@ public class DelegatingIntroductionInterceptorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelegateReturnsThisIsMassagedToReturnProxy() {
|
void testDelegateReturnsThisIsMassagedToReturnProxy() {
|
||||||
NestedTestBean target = new NestedTestBean();
|
NestedTestBean target = new NestedTestBean();
|
||||||
String company = "Interface21";
|
String company = "Interface21";
|
||||||
target.setCompany(company);
|
target.setCompany(company);
|
||||||
|
@ -221,7 +221,7 @@ public class DelegatingIntroductionInterceptorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception {
|
void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception {
|
||||||
SerializablePerson serializableTarget = new SerializablePerson();
|
SerializablePerson serializableTarget = new SerializablePerson();
|
||||||
String name = "Tony";
|
String name = "Tony";
|
||||||
serializableTarget.setName("Tony");
|
serializableTarget.setName("Tony");
|
||||||
|
@ -246,7 +246,7 @@ public class DelegatingIntroductionInterceptorTests {
|
||||||
|
|
||||||
// Test when target implements the interface: should get interceptor by preference.
|
// Test when target implements the interface: should get interceptor by preference.
|
||||||
@Test
|
@Test
|
||||||
public void testIntroductionMasksTargetImplementation() throws Exception {
|
void testIntroductionMasksTargetImplementation() throws Exception {
|
||||||
final long t = 1001L;
|
final long t = 1001L;
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped {
|
class TestII extends DelegatingIntroductionInterceptor implements TimeStamped {
|
||||||
|
|
|
@ -1255,7 +1255,7 @@ class DefaultListableBeanFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void expressionInStringArray() {
|
void expressionInStringArray() {
|
||||||
BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
|
BeanExpressionResolver beanExpressionResolver = mock();
|
||||||
given(beanExpressionResolver.evaluate(eq("#{foo}"), any(BeanExpressionContext.class)))
|
given(beanExpressionResolver.evaluate(eq("#{foo}"), any(BeanExpressionContext.class)))
|
||||||
.willReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
|
.willReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
|
||||||
lbf.setBeanExpressionResolver(beanExpressionResolver);
|
lbf.setBeanExpressionResolver(beanExpressionResolver);
|
||||||
|
@ -2618,9 +2618,9 @@ class DefaultListableBeanFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resolveEmbeddedValue() {
|
void resolveEmbeddedValue() {
|
||||||
StringValueResolver r1 = mock(StringValueResolver.class);
|
StringValueResolver r1 = mock();
|
||||||
StringValueResolver r2 = mock(StringValueResolver.class);
|
StringValueResolver r2 = mock();
|
||||||
StringValueResolver r3 = mock(StringValueResolver.class);
|
StringValueResolver r3 = mock();
|
||||||
lbf.addEmbeddedValueResolver(r1);
|
lbf.addEmbeddedValueResolver(r1);
|
||||||
lbf.addEmbeddedValueResolver(r2);
|
lbf.addEmbeddedValueResolver(r2);
|
||||||
lbf.addEmbeddedValueResolver(r3);
|
lbf.addEmbeddedValueResolver(r3);
|
||||||
|
|
|
@ -93,8 +93,8 @@ public class ParameterResolutionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveDependencyPreconditionsForParameter() {
|
public void resolveDependencyPreconditionsForParameter() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
ParameterResolutionDelegate.resolveDependency(null, 0, null, mock(AutowireCapableBeanFactory.class)))
|
.isThrownBy(() -> ParameterResolutionDelegate.resolveDependency(null, 0, null, mock()))
|
||||||
.withMessageContaining("Parameter must not be null");
|
.withMessageContaining("Parameter must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public class ParameterResolutionTests {
|
||||||
public void resolveDependencyForAnnotatedParametersInTopLevelClassConstructor() throws Exception {
|
public void resolveDependencyForAnnotatedParametersInTopLevelClassConstructor() throws Exception {
|
||||||
Constructor<?> constructor = AutowirableClass.class.getConstructor(String.class, String.class, String.class, String.class);
|
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
|
// Configure the mocked BeanFactory to return the DependencyDescriptor for convenience and
|
||||||
// to avoid using an ArgumentCaptor.
|
// to avoid using an ArgumentCaptor.
|
||||||
given(beanFactory.resolveDependency(any(), isNull())).willAnswer(invocation -> invocation.getArgument(0));
|
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);
|
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(0))).isEqualTo(Source.SPRING_FACTORIES_LOADER);
|
||||||
assertThat(loaded.getSource(loaded.asList().get(1))).isEqualTo(Source.BEAN_FACTORY);
|
assertThat(loaded.getSource(loaded.asList().get(1))).isEqualTo(Source.BEAN_FACTORY);
|
||||||
TestService missing = mock(TestService.class);
|
TestService missing = mock();
|
||||||
assertThatIllegalStateException().isThrownBy(()->loaded.getSource(missing));
|
assertThatIllegalStateException().isThrownBy(()->loaded.getSource(missing));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getSourceWhenMissingThrowsException() {
|
void getSourceWhenMissingThrowsException() {
|
||||||
AotServices<TestService> loaded = AotServices.factories().load(TestService.class);
|
AotServices<TestService> loaded = AotServices.factories().load(TestService.class);
|
||||||
TestService missing = mock(TestService.class);
|
TestService missing = mock();
|
||||||
assertThatIllegalStateException().isThrownBy(()->loaded.getSource(missing));
|
assertThatIllegalStateException().isThrownBy(()->loaded.getSource(missing));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ class AutowiredMethodArgumentsResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resolveRequiredWithMultipleDependenciesReturnsValue() {
|
void resolveRequiredWithMultipleDependenciesReturnsValue() {
|
||||||
Environment environment = mock(Environment.class);
|
Environment environment = mock();
|
||||||
this.beanFactory.registerSingleton("test", "testValue");
|
this.beanFactory.registerSingleton("test", "testValue");
|
||||||
this.beanFactory.registerSingleton("environment", environment);
|
this.beanFactory.registerSingleton("environment", environment);
|
||||||
RegisteredBean registeredBean = registerTestBean(this.beanFactory);
|
RegisteredBean registeredBean = registerTestBean(this.beanFactory);
|
||||||
|
|
|
@ -110,13 +110,11 @@ class BeanDefinitionMethodGeneratorFactoryTests {
|
||||||
@Test
|
@Test
|
||||||
void getBeanDefinitionMethodGeneratorAddsContributionsFromProcessors() {
|
void getBeanDefinitionMethodGeneratorAddsContributionsFromProcessors() {
|
||||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
BeanRegistrationAotContribution beanContribution = mock(
|
BeanRegistrationAotContribution beanContribution = mock();
|
||||||
BeanRegistrationAotContribution.class);
|
|
||||||
BeanRegistrationAotProcessor processorBean = registeredBean -> beanContribution;
|
BeanRegistrationAotProcessor processorBean = registeredBean -> beanContribution;
|
||||||
beanFactory.registerSingleton("processorBean", processorBean);
|
beanFactory.registerSingleton("processorBean", processorBean);
|
||||||
MockSpringFactoriesLoader springFactoriesLoader = new MockSpringFactoriesLoader();
|
MockSpringFactoriesLoader springFactoriesLoader = new MockSpringFactoriesLoader();
|
||||||
BeanRegistrationAotContribution loaderContribution = mock(
|
BeanRegistrationAotContribution loaderContribution = mock();
|
||||||
BeanRegistrationAotContribution.class);
|
|
||||||
BeanRegistrationAotProcessor loaderProcessor = registeredBean -> loaderContribution;
|
BeanRegistrationAotProcessor loaderProcessor = registeredBean -> loaderContribution;
|
||||||
springFactoriesLoader.addInstance(BeanRegistrationAotProcessor.class,
|
springFactoriesLoader.addInstance(BeanRegistrationAotProcessor.class,
|
||||||
loaderProcessor);
|
loaderProcessor);
|
||||||
|
|
|
@ -425,7 +425,7 @@ class BeanInstanceSupplierTests {
|
||||||
@ParameterizedResolverTest(Sources.MULTI_ARGS)
|
@ParameterizedResolverTest(Sources.MULTI_ARGS)
|
||||||
void resolveArgumentsWithMultiArgsConstructor(Source source) {
|
void resolveArgumentsWithMultiArgsConstructor(Source source) {
|
||||||
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||||
Environment environment = mock(Environment.class);
|
Environment environment = mock();
|
||||||
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
|
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
|
||||||
resourceLoader);
|
resourceLoader);
|
||||||
this.beanFactory.registerSingleton("environment", environment);
|
this.beanFactory.registerSingleton("environment", environment);
|
||||||
|
@ -442,7 +442,7 @@ class BeanInstanceSupplierTests {
|
||||||
@ParameterizedResolverTest(Sources.MIXED_ARGS)
|
@ParameterizedResolverTest(Sources.MIXED_ARGS)
|
||||||
void resolveArgumentsWithMixedArgsConstructorWithUserValue(Source source) {
|
void resolveArgumentsWithMixedArgsConstructorWithUserValue(Source source) {
|
||||||
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||||
Environment environment = mock(Environment.class);
|
Environment environment = mock();
|
||||||
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
|
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
|
||||||
resourceLoader);
|
resourceLoader);
|
||||||
this.beanFactory.registerSingleton("environment", environment);
|
this.beanFactory.registerSingleton("environment", environment);
|
||||||
|
@ -463,7 +463,7 @@ class BeanInstanceSupplierTests {
|
||||||
@ParameterizedResolverTest(Sources.MIXED_ARGS)
|
@ParameterizedResolverTest(Sources.MIXED_ARGS)
|
||||||
void resolveArgumentsWithMixedArgsConstructorWithUserBeanReference(Source source) {
|
void resolveArgumentsWithMixedArgsConstructorWithUserBeanReference(Source source) {
|
||||||
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||||
Environment environment = mock(Environment.class);
|
Environment environment = mock();
|
||||||
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
|
this.beanFactory.registerResolvableDependency(ResourceLoader.class,
|
||||||
resourceLoader);
|
resourceLoader);
|
||||||
this.beanFactory.registerSingleton("environment", environment);
|
this.beanFactory.registerSingleton("environment", environment);
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class CustomScopeConfigurerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSunnyDayWithBonaFideScopeInstance() {
|
public void testSunnyDayWithBonaFideScopeInstance() {
|
||||||
Scope scope = mock(Scope.class);
|
Scope scope = mock();
|
||||||
factory.registerScope(FOO_SCOPE, scope);
|
factory.registerScope(FOO_SCOPE, scope);
|
||||||
Map<String, Object> scopes = new HashMap<>();
|
Map<String, Object> scopes = new HashMap<>();
|
||||||
scopes.put(FOO_SCOPE, scope);
|
scopes.put(FOO_SCOPE, scope);
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
|
||||||
final String targetBeanName = "singleton";
|
final String targetBeanName = "singleton";
|
||||||
final String expectedSingleton = "Alicia Keys";
|
final String expectedSingleton = "Alicia Keys";
|
||||||
|
|
||||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
BeanFactory beanFactory = mock();
|
||||||
given(beanFactory.getBean(targetBeanName)).willReturn(expectedSingleton);
|
given(beanFactory.getBean(targetBeanName)).willReturn(expectedSingleton);
|
||||||
|
|
||||||
ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean();
|
ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean();
|
||||||
|
|
|
@ -252,7 +252,7 @@ public class ServiceLocatorFactoryBeanTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception {
|
public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception {
|
||||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
BeanFactory beanFactory = mock();
|
||||||
try {
|
try {
|
||||||
ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
|
ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
|
||||||
factory.setBeanFactory(beanFactory);
|
factory.setBeanFactory(beanFactory);
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class FailFastProblemReporterTests {
|
||||||
Problem problem = new Problem("VGER", new Location(new DescriptiveResource("here")),
|
Problem problem = new Problem("VGER", new Location(new DescriptiveResource("here")),
|
||||||
null, new IllegalArgumentException());
|
null, new IllegalArgumentException());
|
||||||
|
|
||||||
Log log = mock(Log.class);
|
Log log = mock();
|
||||||
|
|
||||||
FailFastProblemReporter reporter = new FailFastProblemReporter();
|
FailFastProblemReporter reporter = new FailFastProblemReporter();
|
||||||
reporter.setLogger(log);
|
reporter.setLogger(log);
|
||||||
|
|
|
@ -36,7 +36,7 @@ class RootBeanDefinitionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setInstanceSetResolvedFactoryMethod() {
|
void setInstanceSetResolvedFactoryMethod() {
|
||||||
InstanceSupplier<?> instanceSupplier = mock(InstanceSupplier.class);
|
InstanceSupplier<?> instanceSupplier = mock();
|
||||||
Method method = ReflectionUtils.findMethod(String.class, "toString");
|
Method method = ReflectionUtils.findMethod(String.class, "toString");
|
||||||
given(instanceSupplier.getFactoryMethod()).willReturn(method);
|
given(instanceSupplier.getFactoryMethod()).willReturn(method);
|
||||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(String.class);
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(String.class);
|
||||||
|
@ -47,7 +47,7 @@ class RootBeanDefinitionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setInstanceDoesNotOverrideResolvedFactoryMethodWithNull() {
|
void setInstanceDoesNotOverrideResolvedFactoryMethodWithNull() {
|
||||||
InstanceSupplier<?> instanceSupplier = mock(InstanceSupplier.class);
|
InstanceSupplier<?> instanceSupplier = mock();
|
||||||
given(instanceSupplier.getFactoryMethod()).willReturn(null);
|
given(instanceSupplier.getFactoryMethod()).willReturn(null);
|
||||||
Method method = ReflectionUtils.findMethod(String.class, "toString");
|
Method method = ReflectionUtils.findMethod(String.class, "toString");
|
||||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(String.class);
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(String.class);
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.springframework.beans.factory.wiring;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
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.BeanDefinitionBuilder;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.beans.testfixture.beans.TestBean;
|
import org.springframework.beans.testfixture.beans.TestBean;
|
||||||
|
@ -37,16 +36,16 @@ import static org.mockito.Mockito.verify;
|
||||||
public class BeanConfigurerSupportTests {
|
public class BeanConfigurerSupportTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supplyIncompatibleBeanFactoryImplementation() throws Exception {
|
public void supplyIncompatibleBeanFactoryImplementation() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
new StubBeanConfigurerSupport().setBeanFactory(mock(BeanFactory.class)));
|
new StubBeanConfigurerSupport().setBeanFactory(mock()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configureBeanDoesNothingIfBeanWiringInfoResolverResolvesToNull() throws Exception {
|
public void configureBeanDoesNothingIfBeanWiringInfoResolverResolvesToNull() throws Exception {
|
||||||
TestBean beanInstance = new TestBean();
|
TestBean beanInstance = new TestBean();
|
||||||
|
|
||||||
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
|
BeanWiringInfoResolver resolver = mock();
|
||||||
|
|
||||||
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
||||||
configurer.setBeanWiringInfoResolver(resolver);
|
configurer.setBeanWiringInfoResolver(resolver);
|
||||||
|
@ -90,7 +89,7 @@ public class BeanConfigurerSupportTests {
|
||||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||||
factory.registerBeanDefinition("spouse", builder.getBeanDefinition());
|
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));
|
given(resolver.resolveWiringInfo(beanInstance)).willReturn(new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, false));
|
||||||
|
|
||||||
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
||||||
|
@ -110,7 +109,7 @@ public class BeanConfigurerSupportTests {
|
||||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||||
factory.registerBeanDefinition("Mmm, I fancy a salad!", builder.getBeanDefinition());
|
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));
|
given(resolver.resolveWiringInfo(beanInstance)).willReturn(new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_TYPE, false));
|
||||||
|
|
||||||
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
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.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
import org.springframework.core.io.Resource;
|
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.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for ResourceEntityResolver.
|
* Unit tests for ResourceEntityResolver.
|
||||||
|
@ -68,7 +68,7 @@ class ResourceEntityResolverTests {
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(strings = { "https://example.org/schema.dtd", "https://example.org/schema.xsd" })
|
@ValueSource(strings = { "https://example.org/schema.dtd", "https://example.org/schema.xsd" })
|
||||||
void resolveEntityCallsFallbackThatReturnsInputSource(String systemId) throws Exception {
|
void resolveEntityCallsFallbackThatReturnsInputSource(String systemId) throws Exception {
|
||||||
InputSource expected = Mockito.mock(InputSource.class);
|
InputSource expected = mock();
|
||||||
ConfigurableFallbackEntityResolver resolver = new ConfigurableFallbackEntityResolver(expected);
|
ConfigurableFallbackEntityResolver resolver = new ConfigurableFallbackEntityResolver(expected);
|
||||||
|
|
||||||
assertThat(resolver.resolveEntity("testPublicId", systemId)).isSameAs(expected);
|
assertThat(resolver.resolveEntity("testPublicId", systemId)).isSameAs(expected);
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class CaffeineCacheManagerTests {
|
||||||
Cache cache1 = cm.getCache("c1");
|
Cache cache1 = cm.getCache("c1");
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
CacheLoader<Object, Object> loader = mock(CacheLoader.class);
|
CacheLoader<Object, Object> loader = mock();
|
||||||
|
|
||||||
cm.setCacheLoader(loader);
|
cm.setCacheLoader(loader);
|
||||||
Cache cache1x = cm.getCache("c1");
|
Cache cache1x = cm.getCache("c1");
|
||||||
|
|
|
@ -86,11 +86,10 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
|
||||||
|
|
||||||
private final List<String> cacheNames;
|
private final List<String> cacheNames;
|
||||||
|
|
||||||
private final CacheManager cacheManager;
|
private final CacheManager cacheManager = mock();
|
||||||
|
|
||||||
private CacheManagerMock() {
|
private CacheManagerMock() {
|
||||||
this.cacheNames = new ArrayList<>();
|
this.cacheNames = new ArrayList<>();
|
||||||
this.cacheManager = mock(CacheManager.class);
|
|
||||||
given(cacheManager.getCacheNames()).willReturn(cacheNames);
|
given(cacheManager.getCacheNames()).willReturn(cacheNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +100,7 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void addCache(String name) {
|
public void addCache(String name) {
|
||||||
cacheNames.add(name);
|
cacheNames.add(name);
|
||||||
Cache cache = mock(Cache.class);
|
Cache cache = mock();
|
||||||
given(cache.getName()).willReturn(name);
|
given(cache.getName()).willReturn(name);
|
||||||
given(cacheManager.getCache(name)).willReturn(cache);
|
given(cacheManager.getCache(name)).willReturn(cache);
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
|
||||||
@Test
|
@Test
|
||||||
public void defaultCacheNameWithDefaults() {
|
public void defaultCacheNameWithDefaults() {
|
||||||
Method method = ReflectionUtils.findMethod(Object.class, "toString");
|
Method method = ReflectionUtils.findMethod(Object.class, "toString");
|
||||||
CacheDefaults mock = mock(CacheDefaults.class);
|
CacheDefaults mock = mock();
|
||||||
given(mock.cacheName()).willReturn("");
|
given(mock.cacheName()).willReturn("");
|
||||||
assertThat(source.determineCacheName(method, mock, "")).isEqualTo("java.lang.Object.toString()");
|
assertThat(source.determineCacheName(method, mock, "")).isEqualTo("java.lang.Object.toString()");
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,13 +61,13 @@ public class CacheResolverAdapterTests extends AbstractJCacheTests {
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
protected CacheResolver getCacheResolver(CacheInvocationContext<? extends Annotation> context, String cacheName) {
|
protected CacheResolver getCacheResolver(CacheInvocationContext<? extends Annotation> context, String cacheName) {
|
||||||
CacheResolver cacheResolver = mock(CacheResolver.class);
|
CacheResolver cacheResolver = mock();
|
||||||
javax.cache.Cache cache;
|
javax.cache.Cache cache;
|
||||||
if (cacheName == null) {
|
if (cacheName == null) {
|
||||||
cache = null;
|
cache = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cache = mock(javax.cache.Cache.class);
|
cache = mock();
|
||||||
given(cache.getName()).willReturn(cacheName);
|
given(cache.getName()).willReturn(cacheName);
|
||||||
}
|
}
|
||||||
given(cacheResolver.resolveCache(context)).willReturn(cache);
|
given(cacheResolver.resolveCache(context)).willReturn(cache);
|
||||||
|
|
|
@ -154,7 +154,7 @@ public class JCacheErrorHandlerTests {
|
||||||
@Bean
|
@Bean
|
||||||
@Override
|
@Override
|
||||||
public CacheErrorHandler errorHandler() {
|
public CacheErrorHandler errorHandler() {
|
||||||
return mock(CacheErrorHandler.class);
|
return mock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -164,14 +164,14 @@ public class JCacheErrorHandlerTests {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Cache mockCache() {
|
public Cache mockCache() {
|
||||||
Cache cache = mock(Cache.class);
|
Cache cache = mock();
|
||||||
given(cache.getName()).willReturn("test");
|
given(cache.getName()).willReturn("test");
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Cache mockErrorCache() {
|
public Cache mockErrorCache() {
|
||||||
Cache cache = mock(Cache.class);
|
Cache cache = mock();
|
||||||
given(cache.getName()).willReturn("error");
|
given(cache.getName()).willReturn("error");
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ class QuartzSupportTests {
|
||||||
TestBean tb = new TestBean("tb", 99);
|
TestBean tb = new TestBean("tb", 99);
|
||||||
StaticApplicationContext ac = new StaticApplicationContext();
|
StaticApplicationContext ac = new StaticApplicationContext();
|
||||||
|
|
||||||
final Scheduler scheduler = mock(Scheduler.class);
|
final Scheduler scheduler = mock();
|
||||||
SchedulerContext schedulerContext = new SchedulerContext();
|
SchedulerContext schedulerContext = new SchedulerContext();
|
||||||
given(scheduler.getContext()).willReturn(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) {
|
public <K, V> Cache<K, V> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext) {
|
||||||
String cacheName = cacheInvocationContext.getCacheName();
|
String cacheName = cacheInvocationContext.getCacheName();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Cache<K, V> mock = mock(Cache.class);
|
Cache<K, V> mock = mock();
|
||||||
given(mock.getName()).willReturn(cacheName);
|
given(mock.getName()).willReturn(cacheName);
|
||||||
return mock;
|
return mock;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ class AfterAdviceBindingTests {
|
||||||
|
|
||||||
private ClassPathXmlApplicationContext ctx;
|
private ClassPathXmlApplicationContext ctx;
|
||||||
|
|
||||||
private AdviceBindingCollaborator mockCollaborator;
|
private AdviceBindingCollaborator mockCollaborator = mock();
|
||||||
|
|
||||||
private ITestBean testBeanProxy;
|
private ITestBean testBeanProxy;
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ class AfterAdviceBindingTests {
|
||||||
// we need the real target too, not just the proxy...
|
// we need the real target too, not just the proxy...
|
||||||
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
||||||
|
|
||||||
mockCollaborator = mock(AdviceBindingCollaborator.class);
|
|
||||||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ class AfterReturningAdviceBindingTests {
|
||||||
|
|
||||||
private TestBean testBeanTarget;
|
private TestBean testBeanTarget;
|
||||||
|
|
||||||
private AfterReturningAdviceBindingCollaborator mockCollaborator;
|
private AfterReturningAdviceBindingCollaborator mockCollaborator = mock();
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
@ -59,7 +59,6 @@ class AfterReturningAdviceBindingTests {
|
||||||
|
|
||||||
afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");
|
afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||||
|
|
||||||
mockCollaborator = mock(AfterReturningAdviceBindingCollaborator.class);
|
|
||||||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
|
|
||||||
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||||
|
|
|
@ -42,7 +42,7 @@ class AfterThrowingAdviceBindingTests {
|
||||||
|
|
||||||
private AfterThrowingAdviceBindingTestAspect afterThrowingAdviceAspect;
|
private AfterThrowingAdviceBindingTestAspect afterThrowingAdviceAspect;
|
||||||
|
|
||||||
private AfterThrowingAdviceBindingCollaborator mockCollaborator;
|
private AfterThrowingAdviceBindingCollaborator mockCollaborator = mock();
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
@ -52,7 +52,6 @@ class AfterThrowingAdviceBindingTests {
|
||||||
testBean = (ITestBean) ctx.getBean("testBean");
|
testBean = (ITestBean) ctx.getBean("testBean");
|
||||||
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
|
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||||
|
|
||||||
mockCollaborator = mock(AfterThrowingAdviceBindingCollaborator.class);
|
|
||||||
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class AroundAdviceBindingTests {
|
public class AroundAdviceBindingTests {
|
||||||
|
|
||||||
private AroundAdviceBindingCollaborator mockCollaborator;
|
private AroundAdviceBindingCollaborator mockCollaborator = mock();
|
||||||
|
|
||||||
private ITestBean testBeanProxy;
|
private ITestBean testBeanProxy;
|
||||||
|
|
||||||
|
@ -48,11 +48,12 @@ public class AroundAdviceBindingTests {
|
||||||
|
|
||||||
protected ApplicationContext ctx;
|
protected ApplicationContext ctx;
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void onSetUp() throws Exception {
|
public void onSetUp() throws Exception {
|
||||||
ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
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");
|
ITestBean injectedTestBean = (ITestBean) ctx.getBean("testBean");
|
||||||
assertThat(AopUtils.isAopProxy(injectedTestBean)).isTrue();
|
assertThat(AopUtils.isAopProxy(injectedTestBean)).isTrue();
|
||||||
|
@ -62,7 +63,6 @@ public class AroundAdviceBindingTests {
|
||||||
|
|
||||||
this.testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
this.testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
|
||||||
|
|
||||||
mockCollaborator = mock(AroundAdviceBindingCollaborator.class);
|
|
||||||
aroundAdviceAspect.setCollaborator(mockCollaborator);
|
aroundAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ class BeforeAdviceBindingTests {
|
||||||
|
|
||||||
private ClassPathXmlApplicationContext ctx;
|
private ClassPathXmlApplicationContext ctx;
|
||||||
|
|
||||||
private AdviceBindingCollaborator mockCollaborator;
|
private AdviceBindingCollaborator mockCollaborator = mock();
|
||||||
|
|
||||||
private ITestBean testBeanProxy;
|
private ITestBean testBeanProxy;
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ class BeforeAdviceBindingTests {
|
||||||
|
|
||||||
AdviceBindingTestAspect beforeAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
|
AdviceBindingTestAspect beforeAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||||
|
|
||||||
mockCollaborator = mock(AdviceBindingCollaborator.class);
|
|
||||||
beforeAdviceAspect.setCollaborator(mockCollaborator);
|
beforeAdviceAspect.setCollaborator(mockCollaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.springframework.aop.config;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
@ -36,14 +35,9 @@ import static org.mockito.Mockito.verify;
|
||||||
public class MethodLocatingFactoryBeanTests {
|
public class MethodLocatingFactoryBeanTests {
|
||||||
|
|
||||||
private static final String BEAN_NAME = "string";
|
private static final String BEAN_NAME = "string";
|
||||||
private MethodLocatingFactoryBean factory;
|
private MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||||
private BeanFactory beanFactory;
|
private BeanFactory beanFactory = mock();
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void setUp() {
|
|
||||||
factory = new MethodLocatingFactoryBean();
|
|
||||||
beanFactory = mock(BeanFactory.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsSingleton() {
|
public void testIsSingleton() {
|
||||||
|
|
|
@ -183,7 +183,7 @@ class CacheErrorHandlerTests {
|
||||||
@Bean
|
@Bean
|
||||||
@Override
|
@Override
|
||||||
public CacheErrorHandler errorHandler() {
|
public CacheErrorHandler errorHandler() {
|
||||||
return mock(CacheErrorHandler.class);
|
return mock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -201,7 +201,7 @@ class CacheErrorHandlerTests {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Cache mockCache() {
|
public Cache mockCache() {
|
||||||
Cache cache = mock(Cache.class);
|
Cache cache = mock();
|
||||||
given(cache.getName()).willReturn("test");
|
given(cache.getName()).willReturn("test");
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ class LoggingCacheErrorHandlerTests {
|
||||||
|
|
||||||
private static final String KEY = "enigma";
|
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);
|
private LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(this.logger, false);
|
||||||
|
|
||||||
|
|
|
@ -33,25 +33,25 @@ public class DeferredImportSelectorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entryEqualsSameInstance() {
|
public void entryEqualsSameInstance() {
|
||||||
AnnotationMetadata metadata = mock(AnnotationMetadata.class);
|
AnnotationMetadata metadata = mock();
|
||||||
Group.Entry entry = new Group.Entry(metadata, "com.example.Test");
|
Group.Entry entry = new Group.Entry(metadata, "com.example.Test");
|
||||||
assertThat(entry).isEqualTo(entry);
|
assertThat(entry).isEqualTo(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entryEqualsSameMetadataAndClassName() {
|
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"));
|
assertThat(new Group.Entry(metadata, "com.example.Test")).isEqualTo(new Group.Entry(metadata, "com.example.Test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entryEqualDifferentMetadataAndSameClassName() {
|
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
|
@Test
|
||||||
public void entryEqualSameMetadataAnDifferentClassName() {
|
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"));
|
assertThat(new Group.Entry(metadata, "com.example.AnotherTest")).isNotEqualTo(new Group.Entry(metadata, "com.example.Test"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ class EnableLoadTimeWeavingTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoadTimeWeaver getLoadTimeWeaver() {
|
public LoadTimeWeaver getLoadTimeWeaver() {
|
||||||
return mock(LoadTimeWeaver.class);
|
return mock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class EnableLoadTimeWeavingTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoadTimeWeaver getLoadTimeWeaver() {
|
public LoadTimeWeaver getLoadTimeWeaver() {
|
||||||
return mock(LoadTimeWeaver.class);
|
return mock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class EnableLoadTimeWeavingTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoadTimeWeaver getLoadTimeWeaver() {
|
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.AotServices;
|
||||||
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
|
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
|
||||||
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
|
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.DefaultListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
|
|
||||||
|
@ -76,7 +75,7 @@ class ReflectiveProcessorBeanFactoryInitializationAotProcessorTests {
|
||||||
}
|
}
|
||||||
BeanFactoryInitializationAotContribution contribution = this.processor.processAheadOfTime(beanFactory);
|
BeanFactoryInitializationAotContribution contribution = this.processor.processAheadOfTime(beanFactory);
|
||||||
assertThat(contribution).isNotNull();
|
assertThat(contribution).isNotNull();
|
||||||
contribution.applyTo(this.generationContext, mock(BeanFactoryInitializationCode.class));
|
contribution.applyTo(this.generationContext, mock());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Reflective
|
@Reflective
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||||
@Test
|
@Test
|
||||||
public void simpleApplicationEventMulticasterWithTaskExecutor() {
|
public void simpleApplicationEventMulticasterWithTaskExecutor() {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
|
ApplicationListener<ApplicationEvent> listener = mock();
|
||||||
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
||||||
|
|
||||||
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
||||||
|
@ -153,7 +153,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||||
@Test
|
@Test
|
||||||
public void simpleApplicationEventMulticasterWithException() {
|
public void simpleApplicationEventMulticasterWithException() {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
|
ApplicationListener<ApplicationEvent> listener = mock();
|
||||||
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
||||||
|
|
||||||
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
||||||
|
@ -169,7 +169,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||||
@Test
|
@Test
|
||||||
public void simpleApplicationEventMulticasterWithErrorHandler() {
|
public void simpleApplicationEventMulticasterWithErrorHandler() {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
|
ApplicationListener<ApplicationEvent> listener = mock();
|
||||||
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
||||||
|
|
||||||
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
||||||
|
@ -246,8 +246,8 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEventPublicationInterceptor() throws Throwable {
|
public void testEventPublicationInterceptor() throws Throwable {
|
||||||
MethodInvocation invocation = mock(MethodInvocation.class);
|
MethodInvocation invocation = mock();
|
||||||
ApplicationContext ctx = mock(ApplicationContext.class);
|
ApplicationContext ctx = mock();
|
||||||
|
|
||||||
EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
|
EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
|
||||||
interceptor.setApplicationEventClass(MyEvent.class);
|
interceptor.setApplicationEventClass(MyEvent.class);
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
|
||||||
|
|
||||||
private final SampleEvents sampleEvents = spy(new SampleEvents());
|
private final SampleEvents sampleEvents = spy(new SampleEvents());
|
||||||
|
|
||||||
private final ApplicationContext context = mock(ApplicationContext.class);
|
private final ApplicationContext context = mock();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -47,7 +47,7 @@ class EventPublicationInterceptorTests {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() {
|
void setup() {
|
||||||
ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
|
ApplicationEventPublisher publisher = mock();
|
||||||
this.interceptor.setApplicationEventPublisher(publisher);
|
this.interceptor.setApplicationEventPublisher(publisher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsEventTypeWithSmartApplicationListener() {
|
public void supportsEventTypeWithSmartApplicationListener() {
|
||||||
SmartApplicationListener smartListener = mock(SmartApplicationListener.class);
|
SmartApplicationListener smartListener = mock();
|
||||||
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
|
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
|
||||||
ResolvableType type = ResolvableType.forClass(ApplicationEvent.class);
|
ResolvableType type = ResolvableType.forClass(ApplicationEvent.class);
|
||||||
listener.supportsEventType(type);
|
listener.supportsEventType(type);
|
||||||
|
@ -45,7 +45,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsSourceTypeWithSmartApplicationListener() {
|
public void supportsSourceTypeWithSmartApplicationListener() {
|
||||||
SmartApplicationListener smartListener = mock(SmartApplicationListener.class);
|
SmartApplicationListener smartListener = mock();
|
||||||
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
|
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
|
||||||
listener.supportsSourceType(Object.class);
|
listener.supportsSourceType(Object.class);
|
||||||
verify(smartListener, times(1)).supportsSourceType(Object.class);
|
verify(smartListener, times(1)).supportsSourceType(Object.class);
|
||||||
|
|
|
@ -310,7 +310,7 @@ class GenericApplicationContextTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void refreshForAotRegistersEnvironment() {
|
void refreshForAotRegistersEnvironment() {
|
||||||
ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
|
ConfigurableEnvironment environment = mock();
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
context.setEnvironment(environment);
|
context.setEnvironment(environment);
|
||||||
context.refreshForAotProcessing(new RuntimeHints());
|
context.refreshForAotProcessing(new RuntimeHints());
|
||||||
|
@ -363,7 +363,7 @@ class GenericApplicationContextTests {
|
||||||
@Test
|
@Test
|
||||||
void refreshForAotInvokesBeanFactoryPostProcessors() {
|
void refreshForAotInvokesBeanFactoryPostProcessors() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
BeanFactoryPostProcessor bfpp = mock(BeanFactoryPostProcessor.class);
|
BeanFactoryPostProcessor bfpp = mock();
|
||||||
context.addBeanFactoryPostProcessor(bfpp);
|
context.addBeanFactoryPostProcessor(bfpp);
|
||||||
context.refreshForAotProcessing(new RuntimeHints());
|
context.refreshForAotProcessing(new RuntimeHints());
|
||||||
verify(bfpp).postProcessBeanFactory(context.getBeanFactory());
|
verify(bfpp).postProcessBeanFactory(context.getBeanFactory());
|
||||||
|
@ -510,7 +510,7 @@ class GenericApplicationContextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MergedBeanDefinitionPostProcessor registerMockMergedBeanDefinitionPostProcessor(GenericApplicationContext context) {
|
private MergedBeanDefinitionPostProcessor registerMockMergedBeanDefinitionPostProcessor(GenericApplicationContext context) {
|
||||||
MergedBeanDefinitionPostProcessor bpp = mock(MergedBeanDefinitionPostProcessor.class);
|
MergedBeanDefinitionPostProcessor bpp = mock();
|
||||||
context.registerBeanDefinition("bpp", BeanDefinitionBuilder.rootBeanDefinition(
|
context.registerBeanDefinition("bpp", BeanDefinitionBuilder.rootBeanDefinition(
|
||||||
MergedBeanDefinitionPostProcessor.class, () -> bpp)
|
MergedBeanDefinitionPostProcessor.class, () -> bpp)
|
||||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE).getBeanDefinition());
|
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE).getBeanDefinition());
|
||||||
|
|
|
@ -372,7 +372,7 @@ public class JndiObjectFactoryBeanTests {
|
||||||
public void testLookupWithExposeAccessContext() throws Exception {
|
public void testLookupWithExposeAccessContext() throws Exception {
|
||||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||||
TestBean tb = new TestBean();
|
TestBean tb = new TestBean();
|
||||||
final Context mockCtx = mock(Context.class);
|
final Context mockCtx = mock();
|
||||||
given(mockCtx.lookup("foo")).willReturn(tb);
|
given(mockCtx.lookup("foo")).willReturn(tb);
|
||||||
jof.setJndiTemplate(new JndiTemplate() {
|
jof.setJndiTemplate(new JndiTemplate() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class JndiTemplateTests {
|
||||||
public void testLookupSucceeds() throws Exception {
|
public void testLookupSucceeds() throws Exception {
|
||||||
Object o = new Object();
|
Object o = new Object();
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
final Context context = mock(Context.class);
|
final Context context = mock();
|
||||||
given(context.lookup(name)).willReturn(o);
|
given(context.lookup(name)).willReturn(o);
|
||||||
|
|
||||||
JndiTemplate jt = new JndiTemplate() {
|
JndiTemplate jt = new JndiTemplate() {
|
||||||
|
@ -58,7 +58,7 @@ public class JndiTemplateTests {
|
||||||
public void testLookupFails() throws Exception {
|
public void testLookupFails() throws Exception {
|
||||||
NameNotFoundException ne = new NameNotFoundException();
|
NameNotFoundException ne = new NameNotFoundException();
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
final Context context = mock(Context.class);
|
final Context context = mock();
|
||||||
given(context.lookup(name)).willThrow(ne);
|
given(context.lookup(name)).willThrow(ne);
|
||||||
|
|
||||||
JndiTemplate jt = new JndiTemplate() {
|
JndiTemplate jt = new JndiTemplate() {
|
||||||
|
@ -76,7 +76,7 @@ public class JndiTemplateTests {
|
||||||
@Test
|
@Test
|
||||||
public void testLookupReturnsNull() throws Exception {
|
public void testLookupReturnsNull() throws Exception {
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
final Context context = mock(Context.class);
|
final Context context = mock();
|
||||||
given(context.lookup(name)).willReturn(null);
|
given(context.lookup(name)).willReturn(null);
|
||||||
|
|
||||||
JndiTemplate jt = new JndiTemplate() {
|
JndiTemplate jt = new JndiTemplate() {
|
||||||
|
@ -95,7 +95,7 @@ public class JndiTemplateTests {
|
||||||
public void testLookupFailsWithTypeMismatch() throws Exception {
|
public void testLookupFailsWithTypeMismatch() throws Exception {
|
||||||
Object o = new Object();
|
Object o = new Object();
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
final Context context = mock(Context.class);
|
final Context context = mock();
|
||||||
given(context.lookup(name)).willReturn(o);
|
given(context.lookup(name)).willReturn(o);
|
||||||
|
|
||||||
JndiTemplate jt = new JndiTemplate() {
|
JndiTemplate jt = new JndiTemplate() {
|
||||||
|
@ -114,7 +114,7 @@ public class JndiTemplateTests {
|
||||||
public void testBind() throws Exception {
|
public void testBind() throws Exception {
|
||||||
Object o = new Object();
|
Object o = new Object();
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
final Context context = mock(Context.class);
|
final Context context = mock();
|
||||||
|
|
||||||
JndiTemplate jt = new JndiTemplate() {
|
JndiTemplate jt = new JndiTemplate() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -132,7 +132,7 @@ public class JndiTemplateTests {
|
||||||
public void testRebind() throws Exception {
|
public void testRebind() throws Exception {
|
||||||
Object o = new Object();
|
Object o = new Object();
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
final Context context = mock(Context.class);
|
final Context context = mock();
|
||||||
|
|
||||||
JndiTemplate jt = new JndiTemplate() {
|
JndiTemplate jt = new JndiTemplate() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,7 +149,7 @@ public class JndiTemplateTests {
|
||||||
@Test
|
@Test
|
||||||
public void testUnbind() throws Exception {
|
public void testUnbind() throws Exception {
|
||||||
String name = "something";
|
String name = "something";
|
||||||
final Context context = mock(Context.class);
|
final Context context = mock();
|
||||||
|
|
||||||
JndiTemplate jt = new JndiTemplate() {
|
JndiTemplate jt = new JndiTemplate() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.springframework.aop.Advisor;
|
||||||
import org.springframework.aop.framework.Advised;
|
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.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests use of @EnableAsync on @Configuration classes.
|
* Tests use of @EnableAsync on @Configuration classes.
|
||||||
|
@ -495,7 +495,7 @@ public class EnableAsyncTests {
|
||||||
@Bean
|
@Bean
|
||||||
@Lazy
|
@Lazy
|
||||||
public AsyncBean asyncBean() {
|
public AsyncBean asyncBean() {
|
||||||
return Mockito.mock(AsyncBean.class);
|
return mock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class ScheduledExecutorFactoryBeanTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
void shutdownNowIsPropagatedToTheExecutorOnDestroy() throws Exception {
|
void shutdownNowIsPropagatedToTheExecutorOnDestroy() throws Exception {
|
||||||
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
|
final ScheduledExecutorService executor = mock();
|
||||||
|
|
||||||
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
|
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,7 +67,7 @@ class ScheduledExecutorFactoryBeanTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
void shutdownIsPropagatedToTheExecutorOnDestroy() throws Exception {
|
void shutdownIsPropagatedToTheExecutorOnDestroy() throws Exception {
|
||||||
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
|
final ScheduledExecutorService executor = mock();
|
||||||
|
|
||||||
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
|
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,7 +86,7 @@ class ScheduledExecutorFactoryBeanTests {
|
||||||
@Test
|
@Test
|
||||||
@EnabledForTestGroups(LONG_RUNNING)
|
@EnabledForTestGroups(LONG_RUNNING)
|
||||||
void oneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception {
|
void oneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception {
|
||||||
Runnable runnable = mock(Runnable.class);
|
Runnable runnable = mock();
|
||||||
|
|
||||||
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
|
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
|
||||||
factory.setScheduledExecutorTasks(new ScheduledExecutorTask(runnable));
|
factory.setScheduledExecutorTasks(new ScheduledExecutorTask(runnable));
|
||||||
|
@ -100,7 +100,7 @@ class ScheduledExecutorFactoryBeanTests {
|
||||||
@Test
|
@Test
|
||||||
@EnabledForTestGroups(LONG_RUNNING)
|
@EnabledForTestGroups(LONG_RUNNING)
|
||||||
void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
|
void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
|
||||||
Runnable runnable = mock(Runnable.class);
|
Runnable runnable = mock();
|
||||||
|
|
||||||
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
|
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
|
||||||
task.setPeriod(500);
|
task.setPeriod(500);
|
||||||
|
@ -118,7 +118,7 @@ class ScheduledExecutorFactoryBeanTests {
|
||||||
@Test
|
@Test
|
||||||
@EnabledForTestGroups(LONG_RUNNING)
|
@EnabledForTestGroups(LONG_RUNNING)
|
||||||
void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
|
void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
|
||||||
Runnable runnable = mock(Runnable.class);
|
Runnable runnable = mock();
|
||||||
willThrow(new IllegalStateException()).given(runnable).run();
|
willThrow(new IllegalStateException()).given(runnable).run();
|
||||||
|
|
||||||
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
|
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
|
||||||
|
@ -138,7 +138,7 @@ class ScheduledExecutorFactoryBeanTests {
|
||||||
@Test
|
@Test
|
||||||
@EnabledForTestGroups(LONG_RUNNING)
|
@EnabledForTestGroups(LONG_RUNNING)
|
||||||
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
|
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
|
||||||
Runnable runnable = mock(Runnable.class);
|
Runnable runnable = mock();
|
||||||
|
|
||||||
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
|
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
|
||||||
task.setPeriod(500);
|
task.setPeriod(500);
|
||||||
|
@ -158,7 +158,7 @@ class ScheduledExecutorFactoryBeanTests {
|
||||||
@Test
|
@Test
|
||||||
@EnabledForTestGroups(LONG_RUNNING)
|
@EnabledForTestGroups(LONG_RUNNING)
|
||||||
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
|
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
|
||||||
Runnable runnable = mock(Runnable.class);
|
Runnable runnable = mock();
|
||||||
willThrow(new IllegalStateException()).given(runnable).run();
|
willThrow(new IllegalStateException()).given(runnable).run();
|
||||||
|
|
||||||
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
|
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
|
||||||
|
|
|
@ -97,7 +97,7 @@ class ThreadPoolExecutorFactoryBeanTests {
|
||||||
int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue,
|
int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue,
|
||||||
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
|
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
|
||||||
|
|
||||||
return mock(ThreadPoolExecutor.class);
|
return mock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,28 +50,28 @@ class ScheduledTaskRegistrarTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getTriggerTasks() {
|
void getTriggerTasks() {
|
||||||
TriggerTask mockTriggerTask = mock(TriggerTask.class);
|
TriggerTask mockTriggerTask = mock();
|
||||||
this.taskRegistrar.setTriggerTasksList(Collections.singletonList(mockTriggerTask));
|
this.taskRegistrar.setTriggerTasksList(Collections.singletonList(mockTriggerTask));
|
||||||
assertThat(this.taskRegistrar.getTriggerTaskList()).containsExactly(mockTriggerTask);
|
assertThat(this.taskRegistrar.getTriggerTaskList()).containsExactly(mockTriggerTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getCronTasks() {
|
void getCronTasks() {
|
||||||
CronTask mockCronTask = mock(CronTask.class);
|
CronTask mockCronTask = mock();
|
||||||
this.taskRegistrar.setCronTasksList(Collections.singletonList(mockCronTask));
|
this.taskRegistrar.setCronTasksList(Collections.singletonList(mockCronTask));
|
||||||
assertThat(this.taskRegistrar.getCronTaskList()).containsExactly(mockCronTask);
|
assertThat(this.taskRegistrar.getCronTaskList()).containsExactly(mockCronTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getFixedRateTasks() {
|
void getFixedRateTasks() {
|
||||||
IntervalTask mockFixedRateTask = mock(IntervalTask.class);
|
IntervalTask mockFixedRateTask = mock();
|
||||||
this.taskRegistrar.setFixedRateTasksList(Collections.singletonList(mockFixedRateTask));
|
this.taskRegistrar.setFixedRateTasksList(Collections.singletonList(mockFixedRateTask));
|
||||||
assertThat(this.taskRegistrar.getFixedRateTaskList()).containsExactly(mockFixedRateTask);
|
assertThat(this.taskRegistrar.getFixedRateTaskList()).containsExactly(mockFixedRateTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getFixedDelayTasks() {
|
void getFixedDelayTasks() {
|
||||||
IntervalTask mockFixedDelayTask = mock(IntervalTask.class);
|
IntervalTask mockFixedDelayTask = mock();
|
||||||
this.taskRegistrar.setFixedDelayTasksList(Collections.singletonList(mockFixedDelayTask));
|
this.taskRegistrar.setFixedDelayTasksList(Collections.singletonList(mockFixedDelayTask));
|
||||||
assertThat(this.taskRegistrar.getFixedDelayTaskList()).containsExactly(mockFixedDelayTask);
|
assertThat(this.taskRegistrar.getFixedDelayTaskList()).containsExactly(mockFixedDelayTask);
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ class BshScriptFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void scriptThatCompilesButIsJustPlainBad() throws IOException {
|
void scriptThatCompilesButIsJustPlainBad() throws IOException {
|
||||||
ScriptSource script = mock(ScriptSource.class);
|
ScriptSource script = mock();
|
||||||
final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
|
final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
|
||||||
given(script.getScriptAsString()).willReturn(badScript);
|
given(script.getScriptAsString()).willReturn(badScript);
|
||||||
given(script.isModified()).willReturn(true);
|
given(script.isModified()).willReturn(true);
|
||||||
|
|
|
@ -284,7 +284,7 @@ public class GroovyScriptFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
|
public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
|
||||||
ScriptSource script = mock(ScriptSource.class);
|
ScriptSource script = mock();
|
||||||
String badScript = "class Foo { public Foo(String foo) {}}";
|
String badScript = "class Foo { public Foo(String foo) {}}";
|
||||||
given(script.getScriptAsString()).willReturn(badScript);
|
given(script.getScriptAsString()).willReturn(badScript);
|
||||||
given(script.suggestedClassName()).willReturn("someName");
|
given(script.suggestedClassName()).willReturn("someName");
|
||||||
|
@ -297,7 +297,7 @@ public class GroovyScriptFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
|
public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
|
||||||
ScriptSource script = mock(ScriptSource.class);
|
ScriptSource script = mock();
|
||||||
String badScript = "class Foo { protected Foo() {} \n String toString() { 'X' }}";
|
String badScript = "class Foo { protected Foo() {} \n String toString() { 'X' }}";
|
||||||
given(script.getScriptAsString()).willReturn(badScript);
|
given(script.getScriptAsString()).willReturn(badScript);
|
||||||
given(script.suggestedClassName()).willReturn("someName");
|
given(script.suggestedClassName()).willReturn("someName");
|
||||||
|
@ -352,7 +352,7 @@ public class GroovyScriptFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPassedIn() throws Exception {
|
public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPassedIn() throws Exception {
|
||||||
ScriptSource script = mock(ScriptSource.class);
|
ScriptSource script = mock();
|
||||||
given(script.getScriptAsString()).willReturn("class Bar {}");
|
given(script.getScriptAsString()).willReturn("class Bar {}");
|
||||||
given(script.suggestedClassName()).willReturn("someName");
|
given(script.suggestedClassName()).willReturn("someName");
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ package org.springframework.scripting.support;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -31,7 +29,7 @@ public class RefreshableScriptTargetSourceTests {
|
||||||
@Test
|
@Test
|
||||||
public void createWithNullScriptSource() throws Exception {
|
public void createWithNullScriptSource() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
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
|
@Test
|
||||||
public void doesNotPropagateFatalExceptionOnResourceThatCannotBeResolvedToAFile() throws Exception {
|
public void doesNotPropagateFatalExceptionOnResourceThatCannotBeResolvedToAFile() throws Exception {
|
||||||
Resource resource = mock(Resource.class);
|
Resource resource = mock();
|
||||||
given(resource.lastModified()).willThrow(new IOException());
|
given(resource.lastModified()).willThrow(new IOException());
|
||||||
|
|
||||||
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
||||||
|
@ -46,14 +46,14 @@ public class ResourceScriptSourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void beginsInModifiedState() throws Exception {
|
public void beginsInModifiedState() throws Exception {
|
||||||
Resource resource = mock(Resource.class);
|
Resource resource = mock();
|
||||||
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
||||||
assertThat(scriptSource.isModified()).isTrue();
|
assertThat(scriptSource.isModified()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lastModifiedWorksWithResourceThatDoesNotSupportFileBasedReading() throws Exception {
|
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...
|
// 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
|
// And then mock the file changing; i.e. the File says it has been modified
|
||||||
given(resource.lastModified()).willReturn(100L, 100L, 200L);
|
given(resource.lastModified()).willReturn(100L, 100L, 200L);
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.springframework.scripting.support;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.FatalBeanException;
|
import org.springframework.beans.FatalBeanException;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
@ -88,7 +87,7 @@ class ScriptFactoryPostProcessorTests {
|
||||||
@Test
|
@Test
|
||||||
void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() {
|
void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() {
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(() ->
|
||||||
new ScriptFactoryPostProcessor().setBeanFactory(mock(BeanFactory.class)));
|
new ScriptFactoryPostProcessor().setBeanFactory(mock()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -160,7 +160,7 @@ class GeneratedClassesTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void writeToInvokeTypeSpecCustomizer() throws IOException {
|
void writeToInvokeTypeSpecCustomizer() throws IOException {
|
||||||
Consumer<TypeSpec.Builder> typeSpecCustomizer = mock(Consumer.class);
|
Consumer<TypeSpec.Builder> typeSpecCustomizer = mock();
|
||||||
this.generatedClasses.addForFeatureComponent("one", TestComponent.class, typeSpecCustomizer);
|
this.generatedClasses.addForFeatureComponent("one", TestComponent.class, typeSpecCustomizer);
|
||||||
verifyNoInteractions(typeSpecCustomizer);
|
verifyNoInteractions(typeSpecCustomizer);
|
||||||
InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles();
|
InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles();
|
||||||
|
|
|
@ -57,7 +57,7 @@ class ReflectionHintsTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void registerTypeIfPresentIgnoresMissingClass() {
|
void registerTypeIfPresentIgnoresMissingClass() {
|
||||||
Consumer<TypeHint.Builder> hintBuilder = mock(Consumer.class);
|
Consumer<TypeHint.Builder> hintBuilder = mock();
|
||||||
this.reflectionHints.registerTypeIfPresent(null, "com.example.DoesNotExist", hintBuilder);
|
this.reflectionHints.registerTypeIfPresent(null, "com.example.DoesNotExist", hintBuilder);
|
||||||
assertThat(this.reflectionHints.typeHints()).isEmpty();
|
assertThat(this.reflectionHints.typeHints()).isEmpty();
|
||||||
verifyNoInteractions(hintBuilder);
|
verifyNoInteractions(hintBuilder);
|
||||||
|
|
|
@ -134,7 +134,7 @@ class ResourceHintsTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void registerIfPresentIgnoreMissingLocation() {
|
void registerIfPresentIgnoreMissingLocation() {
|
||||||
Consumer<ResourcePatternHints.Builder> hintBuilder = mock(Consumer.class);
|
Consumer<ResourcePatternHints.Builder> hintBuilder = mock();
|
||||||
this.resourceHints.registerPatternIfPresent(null, "location/does-not-exist/", hintBuilder);
|
this.resourceHints.registerPatternIfPresent(null, "location/does-not-exist/", hintBuilder);
|
||||||
assertThat(this.resourceHints.resourcePatternHints()).isEmpty();
|
assertThat(this.resourceHints.resourcePatternHints()).isEmpty();
|
||||||
verifyNoInteractions(hintBuilder);
|
verifyNoInteractions(hintBuilder);
|
||||||
|
|
|
@ -51,7 +51,7 @@ class ReflectiveRuntimeHintsRegistrarTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldIgnoreNonAnnotatedType() {
|
void shouldIgnoreNonAnnotatedType() {
|
||||||
RuntimeHints mock = mock(RuntimeHints.class);
|
RuntimeHints mock = mock();
|
||||||
this.registrar.registerRuntimeHints(mock, String.class);
|
this.registrar.registerRuntimeHints(mock, String.class);
|
||||||
verifyNoInteractions(mock);
|
verifyNoInteractions(mock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -869,7 +869,7 @@ class ResolvableTypeTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resolveTypeWithCustomVariableResolver() throws Exception {
|
void resolveTypeWithCustomVariableResolver() throws Exception {
|
||||||
VariableResolver variableResolver = mock(VariableResolver.class);
|
VariableResolver variableResolver = mock();
|
||||||
given(variableResolver.getSource()).willReturn(this);
|
given(variableResolver.getSource()).willReturn(this);
|
||||||
ResolvableType longType = ResolvableType.forClass(Long.class);
|
ResolvableType longType = ResolvableType.forClass(Long.class);
|
||||||
given(variableResolver.resolveVariable(any())).willReturn(longType);
|
given(variableResolver.resolveVariable(any())).willReturn(longType);
|
||||||
|
|
|
@ -118,7 +118,7 @@ class AttributeMethodsTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
void isValidWhenDoesNotHaveTypeNotPresentExceptionReturnsTrue() {
|
void isValidWhenDoesNotHaveTypeNotPresentExceptionReturnsTrue() {
|
||||||
ClassValue annotation = mock(ClassValue.class);
|
ClassValue annotation = mock();
|
||||||
given(annotation.value()).willReturn((Class) InputStream.class);
|
given(annotation.value()).willReturn((Class) InputStream.class);
|
||||||
AttributeMethods attributes = AttributeMethods.forAnnotationType(annotation.annotationType());
|
AttributeMethods attributes = AttributeMethods.forAnnotationType(annotation.annotationType());
|
||||||
assertThat(attributes.isValid(annotation)).isTrue();
|
assertThat(attributes.isValid(annotation)).isTrue();
|
||||||
|
|
|
@ -53,7 +53,7 @@ class MergedAnnotationsCollectionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createWhenAnnotationIsNotDirectlyPresentThrowsException() {
|
void createWhenAnnotationIsNotDirectlyPresentThrowsException() {
|
||||||
MergedAnnotation<?> annotation = mock(MergedAnnotation.class);
|
MergedAnnotation<?> annotation = mock();
|
||||||
given(annotation.isDirectlyPresent()).willReturn(false);
|
given(annotation.isDirectlyPresent()).willReturn(false);
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
MergedAnnotationsCollection.of(Collections.singleton(annotation)))
|
MergedAnnotationsCollection.of(Collections.singleton(annotation)))
|
||||||
|
@ -62,7 +62,7 @@ class MergedAnnotationsCollectionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createWhenAnnotationAggregateIndexIsNotZeroThrowsException() {
|
void createWhenAnnotationAggregateIndexIsNotZeroThrowsException() {
|
||||||
MergedAnnotation<?> annotation = mock(MergedAnnotation.class);
|
MergedAnnotation<?> annotation = mock();
|
||||||
given(annotation.isDirectlyPresent()).willReturn(true);
|
given(annotation.isDirectlyPresent()).willReturn(true);
|
||||||
given(annotation.getAggregateIndex()).willReturn(1);
|
given(annotation.getAggregateIndex()).willReturn(1);
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||||
|
|
|
@ -193,7 +193,7 @@ class PathResourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getFileUnsupported() throws IOException {
|
void getFileUnsupported() throws IOException {
|
||||||
Path path = mock(Path.class);
|
Path path = mock();
|
||||||
given(path.normalize()).willReturn(path);
|
given(path.normalize()).willReturn(path);
|
||||||
given(path.toFile()).willThrow(new UnsupportedOperationException());
|
given(path.toFile()).willThrow(new UnsupportedOperationException());
|
||||||
PathResource resource = new PathResource(path);
|
PathResource resource = new PathResource(path);
|
||||||
|
|
|
@ -101,7 +101,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
|
||||||
void readByteChannelError(DataBufferFactory bufferFactory) throws Exception {
|
void readByteChannelError(DataBufferFactory bufferFactory) throws Exception {
|
||||||
super.bufferFactory = bufferFactory;
|
super.bufferFactory = bufferFactory;
|
||||||
|
|
||||||
ReadableByteChannel channel = mock(ReadableByteChannel.class);
|
ReadableByteChannel channel = mock();
|
||||||
given(channel.read(any()))
|
given(channel.read(any()))
|
||||||
.willAnswer(invocation -> {
|
.willAnswer(invocation -> {
|
||||||
ByteBuffer buffer = invocation.getArgument(0);
|
ByteBuffer buffer = invocation.getArgument(0);
|
||||||
|
@ -166,7 +166,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
|
||||||
void readAsynchronousFileChannelError(DataBufferFactory bufferFactory) throws Exception {
|
void readAsynchronousFileChannelError(DataBufferFactory bufferFactory) throws Exception {
|
||||||
super.bufferFactory = bufferFactory;
|
super.bufferFactory = bufferFactory;
|
||||||
|
|
||||||
AsynchronousFileChannel channel = mock(AsynchronousFileChannel.class);
|
AsynchronousFileChannel channel = mock();
|
||||||
willAnswer(invocation -> {
|
willAnswer(invocation -> {
|
||||||
ByteBuffer byteBuffer = invocation.getArgument(0);
|
ByteBuffer byteBuffer = invocation.getArgument(0);
|
||||||
byteBuffer.put("foo".getBytes(StandardCharsets.UTF_8));
|
byteBuffer.put("foo".getBytes(StandardCharsets.UTF_8));
|
||||||
|
@ -360,7 +360,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
|
||||||
DataBuffer bar = stringBuffer("bar");
|
DataBuffer bar = stringBuffer("bar");
|
||||||
Flux<DataBuffer> flux = Flux.just(foo, bar);
|
Flux<DataBuffer> flux = Flux.just(foo, bar);
|
||||||
|
|
||||||
WritableByteChannel channel = mock(WritableByteChannel.class);
|
WritableByteChannel channel = mock();
|
||||||
given(channel.write(any()))
|
given(channel.write(any()))
|
||||||
.willAnswer(invocation -> {
|
.willAnswer(invocation -> {
|
||||||
ByteBuffer buffer = invocation.getArgument(0);
|
ByteBuffer buffer = invocation.getArgument(0);
|
||||||
|
@ -470,7 +470,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
|
||||||
DataBuffer bar = stringBuffer("bar");
|
DataBuffer bar = stringBuffer("bar");
|
||||||
Flux<DataBuffer> flux = Flux.just(foo, bar);
|
Flux<DataBuffer> flux = Flux.just(foo, bar);
|
||||||
|
|
||||||
AsynchronousFileChannel channel = mock(AsynchronousFileChannel.class);
|
AsynchronousFileChannel channel = mock();
|
||||||
willAnswer(invocation -> {
|
willAnswer(invocation -> {
|
||||||
ByteBuffer buffer = invocation.getArgument(0);
|
ByteBuffer buffer = invocation.getArgument(0);
|
||||||
long pos = invocation.getArgument(1);
|
long pos = invocation.getArgument(1);
|
||||||
|
@ -777,7 +777,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
|
||||||
void SPR16070(DataBufferFactory bufferFactory) throws Exception {
|
void SPR16070(DataBufferFactory bufferFactory) throws Exception {
|
||||||
super.bufferFactory = bufferFactory;
|
super.bufferFactory = bufferFactory;
|
||||||
|
|
||||||
ReadableByteChannel channel = mock(ReadableByteChannel.class);
|
ReadableByteChannel channel = mock();
|
||||||
given(channel.read(any()))
|
given(channel.read(any()))
|
||||||
.willAnswer(putByte('a'))
|
.willAnswer(putByte('a'))
|
||||||
.willAnswer(putByte('b'))
|
.willAnswer(putByte('b'))
|
||||||
|
|
|
@ -18,8 +18,6 @@ package org.springframework.core.io.support;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -32,20 +30,20 @@ class ResourceRegionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldThrowExceptionWithNullResource() {
|
void shouldThrowExceptionWithNullResource() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
new ResourceRegion(null, 0, 1));
|
.isThrownBy(() -> new ResourceRegion(null, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldThrowExceptionForNegativePosition() {
|
void shouldThrowExceptionForNegativePosition() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
new ResourceRegion(mock(Resource.class), -1, 1));
|
.isThrownBy(() -> new ResourceRegion(mock(), -1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldThrowExceptionForNegativeCount() {
|
void shouldThrowExceptionForNegativeCount() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
new ResourceRegion(mock(Resource.class), 0, -1));
|
.isThrownBy(() -> new ResourceRegion(mock(), 0, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ class SpringFactoriesLoaderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loadWithLoggingFailureHandlerWhenIncompatibleTypeReturnsEmptyList() {
|
void loadWithLoggingFailureHandlerWhenIncompatibleTypeReturnsEmptyList() {
|
||||||
Log logger = mock(Log.class);
|
Log logger = mock();
|
||||||
FailureHandler failureHandler = FailureHandler.logging(logger);
|
FailureHandler failureHandler = FailureHandler.logging(logger);
|
||||||
List<String> factories = SpringFactoriesLoader.forDefaultResourceLocation().load(String.class, failureHandler);
|
List<String> factories = SpringFactoriesLoader.forDefaultResourceLocation().load(String.class, failureHandler);
|
||||||
assertThat(factories).isEmpty();
|
assertThat(factories).isEmpty();
|
||||||
|
@ -138,7 +138,7 @@ class SpringFactoriesLoaderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loadWithLoggingFailureHandlerWhenMissingArgumentDropsItem() {
|
void loadWithLoggingFailureHandlerWhenMissingArgumentDropsItem() {
|
||||||
Log logger = mock(Log.class);
|
Log logger = mock();
|
||||||
FailureHandler failureHandler = FailureHandler.logging(logger);
|
FailureHandler failureHandler = FailureHandler.logging(logger);
|
||||||
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation(LimitedClassLoader.multipleArgumentFactories)
|
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation(LimitedClassLoader.multipleArgumentFactories)
|
||||||
.load(DummyFactory.class, failureHandler);
|
.load(DummyFactory.class, failureHandler);
|
||||||
|
@ -202,7 +202,7 @@ class SpringFactoriesLoaderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loggingReturnsHandlerThatLogs() {
|
void loggingReturnsHandlerThatLogs() {
|
||||||
Log logger = mock(Log.class);
|
Log logger = mock();
|
||||||
FailureHandler handler = FailureHandler.logging(logger);
|
FailureHandler handler = FailureHandler.logging(logger);
|
||||||
RuntimeException cause = new RuntimeException();
|
RuntimeException cause = new RuntimeException();
|
||||||
handler.handleFailure(DummyFactory.class, MyDummyFactory1.class.getName(), cause);
|
handler.handleFailure(DummyFactory.class, MyDummyFactory1.class.getName(), cause);
|
||||||
|
|
|
@ -33,9 +33,9 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
*/
|
*/
|
||||||
public class CompositeLogTests {
|
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));
|
private final CompositeLog compositeLog = new CompositeLog(Arrays.asList(logger1, logger2));
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ class StreamUtilsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nonClosingInputStream() throws Exception {
|
void nonClosingInputStream() throws Exception {
|
||||||
InputStream source = mock(InputStream.class);
|
InputStream source = mock();
|
||||||
InputStream nonClosing = StreamUtils.nonClosing(source);
|
InputStream nonClosing = StreamUtils.nonClosing(source);
|
||||||
nonClosing.read();
|
nonClosing.read();
|
||||||
nonClosing.read(bytes);
|
nonClosing.read(bytes);
|
||||||
|
@ -115,7 +115,7 @@ class StreamUtilsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nonClosingOutputStream() throws Exception {
|
void nonClosingOutputStream() throws Exception {
|
||||||
OutputStream source = mock(OutputStream.class);
|
OutputStream source = mock();
|
||||||
OutputStream nonClosing = StreamUtils.nonClosing(source);
|
OutputStream nonClosing = StreamUtils.nonClosing(source);
|
||||||
nonClosing.write(1);
|
nonClosing.write(1);
|
||||||
nonClosing.write(bytes);
|
nonClosing.write(bytes);
|
||||||
|
|
|
@ -43,7 +43,7 @@ class UnmodifiableMultiValueMapTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void delegation() {
|
void delegation() {
|
||||||
MultiValueMap<String, String> mock = mock(MultiValueMap.class);
|
MultiValueMap<String, String> mock = mock();
|
||||||
UnmodifiableMultiValueMap<String, String> map = new UnmodifiableMultiValueMap<>(mock);
|
UnmodifiableMultiValueMap<String, String> map = new UnmodifiableMultiValueMap<>(mock);
|
||||||
|
|
||||||
given(mock.size()).willReturn(1);
|
given(mock.size()).willReturn(1);
|
||||||
|
@ -101,8 +101,8 @@ class UnmodifiableMultiValueMapTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void entrySetDelegation() {
|
void entrySetDelegation() {
|
||||||
MultiValueMap<String, String> mockMap = mock(MultiValueMap.class);
|
MultiValueMap<String, String> mockMap = mock();
|
||||||
Set<Map.Entry<String, List<String>>> mockSet = mock(Set.class);
|
Set<Map.Entry<String, List<String>>> mockSet = mock();
|
||||||
given(mockMap.entrySet()).willReturn(mockSet);
|
given(mockMap.entrySet()).willReturn(mockSet);
|
||||||
Set<Map.Entry<String, List<String>>> set = new UnmodifiableMultiValueMap<>(mockMap).entrySet();
|
Set<Map.Entry<String, List<String>>> set = new UnmodifiableMultiValueMap<>(mockMap).entrySet();
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ class UnmodifiableMultiValueMapTests {
|
||||||
given(mockSet.isEmpty()).willReturn(false);
|
given(mockSet.isEmpty()).willReturn(false);
|
||||||
assertThat(set.isEmpty()).isFalse();
|
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);
|
given(mockSet.contains(mockedEntry)).willReturn(true);
|
||||||
assertThat(set.contains(mockedEntry)).isTrue();
|
assertThat(set.contains(mockedEntry)).isTrue();
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ class UnmodifiableMultiValueMapTests {
|
||||||
given(mockSet.containsAll(mockEntries)).willReturn(true);
|
given(mockSet.containsAll(mockEntries)).willReturn(true);
|
||||||
assertThat(set.containsAll(mockEntries)).isTrue();
|
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(mockSet.iterator()).willReturn(mockIterator);
|
||||||
given(mockIterator.hasNext()).willReturn(false);
|
given(mockIterator.hasNext()).willReturn(false);
|
||||||
assertThat(set.iterator()).isExhausted();
|
assertThat(set.iterator()).isExhausted();
|
||||||
|
@ -143,8 +143,8 @@ class UnmodifiableMultiValueMapTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void valuesDelegation() {
|
void valuesDelegation() {
|
||||||
MultiValueMap<String, String> mockMap = mock(MultiValueMap.class);
|
MultiValueMap<String, String> mockMap = mock();
|
||||||
Collection<List<String>> mockValues = mock(Collection.class);
|
Collection<List<String>> mockValues = mock();
|
||||||
given(mockMap.values()).willReturn(mockValues);
|
given(mockMap.values()).willReturn(mockValues);
|
||||||
Collection<List<String>> values = new UnmodifiableMultiValueMap<>(mockMap).values();
|
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.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -33,22 +32,17 @@ import static org.mockito.Mockito.mock;
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
class FutureAdapterTests {
|
class FutureAdapterTests {
|
||||||
|
|
||||||
private FutureAdapter<String, Integer> adapter;
|
|
||||||
|
|
||||||
private Future<Integer> adaptee;
|
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void setUp() {
|
private Future<Integer> adaptee = mock();
|
||||||
adaptee = mock(Future.class);
|
|
||||||
adapter = new FutureAdapter<>(adaptee) {
|
private FutureAdapter<String, Integer> adapter = new FutureAdapter<>(adaptee) {
|
||||||
@Override
|
@Override
|
||||||
protected String adapt(Integer adapteeResult) throws ExecutionException {
|
protected String adapt(Integer adapteeResult) throws ExecutionException {
|
||||||
return adapteeResult.toString();
|
return adapteeResult.toString();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void cancel() {
|
void cancel() {
|
||||||
|
|
|
@ -94,8 +94,8 @@ class ListenableFutureTaskTests {
|
||||||
final String s = "Hello World";
|
final String s = "Hello World";
|
||||||
Callable<String> callable = () -> s;
|
Callable<String> callable = () -> s;
|
||||||
|
|
||||||
SuccessCallback<String> successCallback = mock(SuccessCallback.class);
|
SuccessCallback<String> successCallback = mock();
|
||||||
FailureCallback failureCallback = mock(FailureCallback.class);
|
FailureCallback failureCallback = mock();
|
||||||
ListenableFutureTask<String> task = new ListenableFutureTask<>(callable);
|
ListenableFutureTask<String> task = new ListenableFutureTask<>(callable);
|
||||||
task.addCallback(successCallback, failureCallback);
|
task.addCallback(successCallback, failureCallback);
|
||||||
task.run();
|
task.run();
|
||||||
|
@ -115,20 +115,22 @@ class ListenableFutureTaskTests {
|
||||||
throw ex;
|
throw ex;
|
||||||
};
|
};
|
||||||
|
|
||||||
SuccessCallback<String> successCallback = mock(SuccessCallback.class);
|
SuccessCallback<String> successCallback = mock();
|
||||||
FailureCallback failureCallback = mock(FailureCallback.class);
|
FailureCallback failureCallback = mock();
|
||||||
ListenableFutureTask<String> task = new ListenableFutureTask<>(callable);
|
ListenableFutureTask<String> task = new ListenableFutureTask<>(callable);
|
||||||
task.addCallback(successCallback, failureCallback);
|
task.addCallback(successCallback, failureCallback);
|
||||||
task.run();
|
task.run();
|
||||||
verify(failureCallback).onFailure(ex);
|
verify(failureCallback).onFailure(ex);
|
||||||
verifyNoInteractions(successCallback);
|
verifyNoInteractions(successCallback);
|
||||||
|
|
||||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
|
assertThatExceptionOfType(ExecutionException.class)
|
||||||
task::get)
|
.isThrownBy(task::get)
|
||||||
.satisfies(e -> assertThat(e.getCause().getMessage()).isEqualTo(s));
|
.havingCause()
|
||||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
|
.withMessage(s);
|
||||||
task.completable()::get)
|
assertThatExceptionOfType(ExecutionException.class)
|
||||||
.satisfies(e -> assertThat(e.getCause().getMessage()).isEqualTo(s));
|
.isThrownBy(task.completable()::get)
|
||||||
|
.havingCause()
|
||||||
|
.withMessage(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -361,7 +361,7 @@ class SettableListenableFutureTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public void cancelDoesNotNotifyCallbacksOnSet() {
|
public void cancelDoesNotNotifyCallbacksOnSet() {
|
||||||
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
|
ListenableFutureCallback callback = mock();
|
||||||
settableListenableFuture.addCallback(callback);
|
settableListenableFuture.addCallback(callback);
|
||||||
settableListenableFuture.cancel(true);
|
settableListenableFuture.cancel(true);
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ class SettableListenableFutureTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public void cancelDoesNotNotifyCallbacksOnSetException() {
|
public void cancelDoesNotNotifyCallbacksOnSetException() {
|
||||||
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
|
ListenableFutureCallback callback = mock();
|
||||||
settableListenableFuture.addCallback(callback);
|
settableListenableFuture.addCallback(callback);
|
||||||
settableListenableFuture.cancel(true);
|
settableListenableFuture.cancel(true);
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ abstract class AbstractStaxXMLReaderTests {
|
||||||
|
|
||||||
|
|
||||||
private LexicalHandler mockLexicalHandler() throws Exception {
|
private LexicalHandler mockLexicalHandler() throws Exception {
|
||||||
LexicalHandler lexicalHandler = mock(LexicalHandler.class);
|
LexicalHandler lexicalHandler = mock();
|
||||||
willAnswer(new CopyCharsAnswer()).given(lexicalHandler).comment(any(char[].class), anyInt(), anyInt());
|
willAnswer(new CopyCharsAnswer()).given(lexicalHandler).comment(any(char[].class), anyInt(), anyInt());
|
||||||
return lexicalHandler;
|
return lexicalHandler;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ abstract class AbstractStaxXMLReaderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final ContentHandler mockContentHandler() throws Exception {
|
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).characters(any(char[].class), anyInt(), anyInt());
|
||||||
willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
|
willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
|
||||||
willAnswer(invocation -> {
|
willAnswer(invocation -> {
|
||||||
|
|
|
@ -48,7 +48,7 @@ class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTests {
|
||||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
|
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
|
||||||
eventReader.nextTag(); // skip to root
|
eventReader.nextTag(); // skip to root
|
||||||
StaxEventXMLReader xmlReader = new StaxEventXMLReader(eventReader);
|
StaxEventXMLReader xmlReader = new StaxEventXMLReader(eventReader);
|
||||||
ContentHandler contentHandler = mock(ContentHandler.class);
|
ContentHandler contentHandler = mock();
|
||||||
xmlReader.setContentHandler(contentHandler);
|
xmlReader.setContentHandler(contentHandler);
|
||||||
xmlReader.parse(new InputSource());
|
xmlReader.parse(new InputSource());
|
||||||
verify(contentHandler).startDocument();
|
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"));
|
assertThat(streamReader.getName()).as("Invalid element").isEqualTo(new QName("http://springframework.org/spring-ws", "child"));
|
||||||
StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader);
|
StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader);
|
||||||
|
|
||||||
ContentHandler contentHandler = mock(ContentHandler.class);
|
ContentHandler contentHandler = mock();
|
||||||
xmlReader.setContentHandler(contentHandler);
|
xmlReader.setContentHandler(contentHandler);
|
||||||
xmlReader.parse(new InputSource());
|
xmlReader.parse(new InputSource());
|
||||||
|
|
||||||
|
|
|
@ -120,27 +120,23 @@ public abstract class AbstractRowMapperTests {
|
||||||
|
|
||||||
protected static class Mock {
|
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;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
|
||||||
public Mock() throws Exception {
|
public Mock() throws Exception {
|
||||||
this(MockType.ONE);
|
this(MockType.ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Mock(MockType type) throws Exception {
|
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(connection.createStatement()).willReturn(statement);
|
||||||
given(statement.executeQuery(anyString())).willReturn(resultSet);
|
given(statement.executeQuery(anyString())).willReturn(resultSet);
|
||||||
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
||||||
|
|
|
@ -50,30 +50,23 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class JdbcTemplateQueryTests {
|
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
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
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.dataSource.getConnection()).willReturn(this.connection);
|
||||||
given(this.resultSet.getMetaData()).willReturn(this.resultSetMetaData);
|
given(this.resultSet.getMetaData()).willReturn(this.resultSetMetaData);
|
||||||
given(this.resultSetMetaData.getColumnCount()).willReturn(1);
|
given(this.resultSetMetaData.getColumnCount()).willReturn(1);
|
||||||
|
|
|
@ -75,30 +75,23 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class JdbcTemplateTests {
|
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
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
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.dataSource.getConnection()).willReturn(this.connection);
|
||||||
given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement);
|
given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement);
|
||||||
given(this.preparedStatement.executeQuery()).willReturn(this.resultSet);
|
given(this.preparedStatement.executeQuery()).willReturn(this.resultSet);
|
||||||
|
@ -779,7 +772,6 @@ public class JdbcTemplateTests {
|
||||||
@Test
|
@Test
|
||||||
public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws SQLException {
|
public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws SQLException {
|
||||||
SQLException sqlException = new SQLException("foo", "07xxx");
|
SQLException sqlException = new SQLException("foo", "07xxx");
|
||||||
this.dataSource = mock(DataSource.class);
|
|
||||||
given(this.dataSource.getConnection()).willThrow(sqlException);
|
given(this.dataSource.getConnection()).willThrow(sqlException);
|
||||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||||
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
|
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
|
||||||
|
@ -792,7 +784,6 @@ public class JdbcTemplateTests {
|
||||||
@Test
|
@Test
|
||||||
public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() throws SQLException {
|
public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() throws SQLException {
|
||||||
SQLException sqlException = new SQLException("foo", "07xxx");
|
SQLException sqlException = new SQLException("foo", "07xxx");
|
||||||
this.dataSource = mock(DataSource.class);
|
|
||||||
given(this.dataSource.getConnection()).willThrow(sqlException);
|
given(this.dataSource.getConnection()).willThrow(sqlException);
|
||||||
this.template = new JdbcTemplate();
|
this.template = new JdbcTemplate();
|
||||||
this.template.setDataSource(this.dataSource);
|
this.template.setDataSource(this.dataSource);
|
||||||
|
@ -826,7 +817,6 @@ public class JdbcTemplateTests {
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
|
|
||||||
SQLException sqlException = new SQLException("foo", "07xxx");
|
SQLException sqlException = new SQLException("foo", "07xxx");
|
||||||
this.dataSource = mock(DataSource.class);
|
|
||||||
given(this.dataSource.getConnection()).willThrow(sqlException);
|
given(this.dataSource.getConnection()).willThrow(sqlException);
|
||||||
this.template = new JdbcTemplate();
|
this.template = new JdbcTemplate();
|
||||||
this.template.setDataSource(this.dataSource);
|
this.template.setDataSource(this.dataSource);
|
||||||
|
@ -1008,7 +998,7 @@ public class JdbcTemplateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaticResultSetClosed() throws Exception {
|
public void testStaticResultSetClosed() throws Exception {
|
||||||
ResultSet resultSet2 = mock(ResultSet.class);
|
ResultSet resultSet2 = mock();
|
||||||
reset(this.preparedStatement);
|
reset(this.preparedStatement);
|
||||||
given(this.preparedStatement.executeQuery()).willReturn(resultSet2);
|
given(this.preparedStatement.executeQuery()).willReturn(resultSet2);
|
||||||
given(this.connection.createStatement()).willReturn(this.statement);
|
given(this.connection.createStatement()).willReturn(this.statement);
|
||||||
|
@ -1071,7 +1061,7 @@ public class JdbcTemplateTests {
|
||||||
public void testEquallyNamedColumn() throws SQLException {
|
public void testEquallyNamedColumn() throws SQLException {
|
||||||
given(this.connection.createStatement()).willReturn(this.statement);
|
given(this.connection.createStatement()).willReturn(this.statement);
|
||||||
|
|
||||||
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
ResultSetMetaData metaData = mock();
|
||||||
given(metaData.getColumnCount()).willReturn(2);
|
given(metaData.getColumnCount()).willReturn(2);
|
||||||
given(metaData.getColumnLabel(1)).willReturn("x");
|
given(metaData.getColumnLabel(1)).willReturn("x");
|
||||||
given(metaData.getColumnLabel(2)).willReturn("X");
|
given(metaData.getColumnLabel(2)).willReturn("X");
|
||||||
|
@ -1088,7 +1078,7 @@ public class JdbcTemplateTests {
|
||||||
|
|
||||||
|
|
||||||
private void mockDatabaseMetaData(boolean supportsBatchUpdates) throws SQLException {
|
private void mockDatabaseMetaData(boolean supportsBatchUpdates) throws SQLException {
|
||||||
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
|
DatabaseMetaData databaseMetaData = mock();
|
||||||
given(databaseMetaData.getDatabaseProductName()).willReturn("MySQL");
|
given(databaseMetaData.getDatabaseProductName()).willReturn("MySQL");
|
||||||
given(databaseMetaData.supportsBatchUpdates()).willReturn(supportsBatchUpdates);
|
given(databaseMetaData.supportsBatchUpdates()).willReturn(supportsBatchUpdates);
|
||||||
given(this.connection.getMetaData()).willReturn(databaseMetaData);
|
given(this.connection.getMetaData()).willReturn(databaseMetaData);
|
||||||
|
|
|
@ -45,13 +45,13 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class RowMapperTests {
|
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();
|
private final JdbcTemplate template = new JdbcTemplate();
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class SingleColumnRowMapperTests {
|
||||||
|
|
||||||
SingleColumnRowMapper<LocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(LocalDateTime.class);
|
SingleColumnRowMapper<LocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(LocalDateTime.class);
|
||||||
|
|
||||||
ResultSet resultSet = mock(ResultSet.class);
|
ResultSet resultSet = mock();
|
||||||
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
ResultSetMetaData metaData = mock();
|
||||||
given(metaData.getColumnCount()).willReturn(1);
|
given(metaData.getColumnCount()).willReturn(1);
|
||||||
given(resultSet.getMetaData()).willReturn(metaData);
|
given(resultSet.getMetaData()).willReturn(metaData);
|
||||||
given(resultSet.getObject(1, LocalDateTime.class))
|
given(resultSet.getObject(1, LocalDateTime.class))
|
||||||
|
@ -70,8 +70,8 @@ public class SingleColumnRowMapperTests {
|
||||||
SingleColumnRowMapper<MyLocalDateTime> rowMapper =
|
SingleColumnRowMapper<MyLocalDateTime> rowMapper =
|
||||||
SingleColumnRowMapper.newInstance(MyLocalDateTime.class, myConversionService);
|
SingleColumnRowMapper.newInstance(MyLocalDateTime.class, myConversionService);
|
||||||
|
|
||||||
ResultSet resultSet = mock(ResultSet.class);
|
ResultSet resultSet = mock();
|
||||||
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
ResultSetMetaData metaData = mock();
|
||||||
given(metaData.getColumnCount()).willReturn(1);
|
given(metaData.getColumnCount()).willReturn(1);
|
||||||
given(resultSet.getMetaData()).willReturn(metaData);
|
given(resultSet.getMetaData()).willReturn(metaData);
|
||||||
given(resultSet.getObject(1, MyLocalDateTime.class))
|
given(resultSet.getObject(1, MyLocalDateTime.class))
|
||||||
|
@ -89,8 +89,8 @@ public class SingleColumnRowMapperTests {
|
||||||
SingleColumnRowMapper<LocalDateTime> rowMapper =
|
SingleColumnRowMapper<LocalDateTime> rowMapper =
|
||||||
SingleColumnRowMapper.newInstance(LocalDateTime.class, null);
|
SingleColumnRowMapper.newInstance(LocalDateTime.class, null);
|
||||||
|
|
||||||
ResultSet resultSet = mock(ResultSet.class);
|
ResultSet resultSet = mock();
|
||||||
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
ResultSetMetaData metaData = mock();
|
||||||
given(metaData.getColumnCount()).willReturn(1);
|
given(metaData.getColumnCount()).willReturn(1);
|
||||||
given(resultSet.getMetaData()).willReturn(metaData);
|
given(resultSet.getMetaData()).willReturn(metaData);
|
||||||
given(resultSet.getObject(1, LocalDateTime.class))
|
given(resultSet.getObject(1, LocalDateTime.class))
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
@ -38,13 +37,7 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class StatementCreatorUtilsTests {
|
public class StatementCreatorUtilsTests {
|
||||||
|
|
||||||
private PreparedStatement preparedStatement;
|
private PreparedStatement preparedStatement = mock();
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void setUp() {
|
|
||||||
preparedStatement = mock(PreparedStatement.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -62,8 +55,8 @@ public class StatementCreatorUtilsTests {
|
||||||
@Test
|
@Test
|
||||||
public void testSetParameterValueWithNullAndUnknownType() throws SQLException {
|
public void testSetParameterValueWithNullAndUnknownType() throws SQLException {
|
||||||
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
||||||
Connection con = mock(Connection.class);
|
Connection con = mock();
|
||||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
DatabaseMetaData dbmd = mock();
|
||||||
given(preparedStatement.getConnection()).willReturn(con);
|
given(preparedStatement.getConnection()).willReturn(con);
|
||||||
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
||||||
given(dbmd.getDriverName()).willReturn("Oracle Driver");
|
given(dbmd.getDriverName()).willReturn("Oracle Driver");
|
||||||
|
@ -76,8 +69,8 @@ public class StatementCreatorUtilsTests {
|
||||||
@Test
|
@Test
|
||||||
public void testSetParameterValueWithNullAndUnknownTypeOnInformix() throws SQLException {
|
public void testSetParameterValueWithNullAndUnknownTypeOnInformix() throws SQLException {
|
||||||
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
||||||
Connection con = mock(Connection.class);
|
Connection con = mock();
|
||||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
DatabaseMetaData dbmd = mock();
|
||||||
given(preparedStatement.getConnection()).willReturn(con);
|
given(preparedStatement.getConnection()).willReturn(con);
|
||||||
given(con.getMetaData()).willReturn(dbmd);
|
given(con.getMetaData()).willReturn(dbmd);
|
||||||
given(dbmd.getDatabaseProductName()).willReturn("Informix Dynamic Server");
|
given(dbmd.getDatabaseProductName()).willReturn("Informix Dynamic Server");
|
||||||
|
@ -92,8 +85,8 @@ public class StatementCreatorUtilsTests {
|
||||||
@Test
|
@Test
|
||||||
public void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded() throws SQLException {
|
public void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded() throws SQLException {
|
||||||
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
||||||
Connection con = mock(Connection.class);
|
Connection con = mock();
|
||||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
DatabaseMetaData dbmd = mock();
|
||||||
given(preparedStatement.getConnection()).willReturn(con);
|
given(preparedStatement.getConnection()).willReturn(con);
|
||||||
given(con.getMetaData()).willReturn(dbmd);
|
given(con.getMetaData()).willReturn(dbmd);
|
||||||
given(dbmd.getDatabaseProductName()).willReturn("Apache Derby");
|
given(dbmd.getDatabaseProductName()).willReturn("Apache Derby");
|
||||||
|
@ -107,7 +100,7 @@ public class StatementCreatorUtilsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetParameterValueWithNullAndGetParameterTypeWorking() throws SQLException {
|
public void testSetParameterValueWithNullAndGetParameterTypeWorking() throws SQLException {
|
||||||
ParameterMetaData pmd = mock(ParameterMetaData.class);
|
ParameterMetaData pmd = mock();
|
||||||
given(preparedStatement.getParameterMetaData()).willReturn(pmd);
|
given(preparedStatement.getParameterMetaData()).willReturn(pmd);
|
||||||
given(pmd.getParameterType(1)).willReturn(Types.SMALLINT);
|
given(pmd.getParameterType(1)).willReturn(Types.SMALLINT);
|
||||||
StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, null);
|
StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, null);
|
||||||
|
@ -212,8 +205,8 @@ public class StatementCreatorUtilsTests {
|
||||||
|
|
||||||
@Test // SPR-8571
|
@Test // SPR-8571
|
||||||
public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLException {
|
public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLException {
|
||||||
Connection con = mock(Connection.class);
|
Connection con = mock();
|
||||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
DatabaseMetaData dbmd = mock();
|
||||||
given(preparedStatement.getConnection()).willReturn(con);
|
given(preparedStatement.getConnection()).willReturn(con);
|
||||||
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
||||||
given(con.getMetaData()).willReturn(dbmd);
|
given(con.getMetaData()).willReturn(dbmd);
|
||||||
|
@ -224,8 +217,8 @@ public class StatementCreatorUtilsTests {
|
||||||
@Test // SPR-8571
|
@Test // SPR-8571
|
||||||
public void testSetParameterValueWithNullAndVendorSpecificType() throws SQLException {
|
public void testSetParameterValueWithNullAndVendorSpecificType() throws SQLException {
|
||||||
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
||||||
Connection con = mock(Connection.class);
|
Connection con = mock();
|
||||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
DatabaseMetaData dbmd = mock();
|
||||||
given(preparedStatement.getConnection()).willReturn(con);
|
given(preparedStatement.getConnection()).willReturn(con);
|
||||||
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
||||||
given(dbmd.getDriverName()).willReturn("Oracle Driver");
|
given(dbmd.getDriverName()).willReturn("Oracle Driver");
|
||||||
|
|
|
@ -83,29 +83,23 @@ public class NamedParameterJdbcTemplateTests {
|
||||||
private static final String[] COLUMN_NAMES = new String[] {"id", "forename"};
|
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 Map<String, Object> params = new HashMap<>();
|
||||||
|
|
||||||
private NamedParameterJdbcTemplate namedParameterTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
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(dataSource.getConnection()).willReturn(connection);
|
||||||
given(connection.prepareStatement(anyString())).willReturn(preparedStatement);
|
given(connection.prepareStatement(anyString())).willReturn(preparedStatement);
|
||||||
given(preparedStatement.getConnection()).willReturn(connection);
|
given(preparedStatement.getConnection()).willReturn(connection);
|
||||||
|
|
|
@ -48,27 +48,21 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class NamedParameterQueryTests {
|
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
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
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(dataSource.getConnection()).willReturn(connection);
|
||||||
given(resultSetMetaData.getColumnCount()).willReturn(1);
|
given(resultSetMetaData.getColumnCount()).willReturn(1);
|
||||||
given(resultSetMetaData.getColumnLabel(1)).willReturn("age");
|
given(resultSetMetaData.getColumnLabel(1)).willReturn("age");
|
||||||
|
|
|
@ -47,21 +47,18 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class CallMetaDataContextTests {
|
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();
|
private CallMetaDataContext context = new CallMetaDataContext();
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
connection = mock(Connection.class);
|
|
||||||
databaseMetaData = mock(DatabaseMetaData.class);
|
|
||||||
given(connection.getMetaData()).willReturn(databaseMetaData);
|
given(connection.getMetaData()).willReturn(databaseMetaData);
|
||||||
dataSource = mock(DataSource.class);
|
|
||||||
given(dataSource.getConnection()).willReturn(connection);
|
given(dataSource.getConnection()).willReturn(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,13 +50,13 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
class SimpleJdbcCallTests {
|
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
|
@BeforeEach
|
||||||
|
@ -233,8 +233,8 @@ class SimpleJdbcCallTests {
|
||||||
*/
|
*/
|
||||||
@Test // gh-26486
|
@Test // gh-26486
|
||||||
void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
|
void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
|
||||||
ResultSet proceduresResultSet = mock(ResultSet.class);
|
ResultSet proceduresResultSet = mock();
|
||||||
ResultSet procedureColumnsResultSet = mock(ResultSet.class);
|
ResultSet procedureColumnsResultSet = mock();
|
||||||
|
|
||||||
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
|
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
|
||||||
given(databaseMetaData.getUserName()).willReturn("ME");
|
given(databaseMetaData.getUserName()).willReturn("ME");
|
||||||
|
@ -301,8 +301,8 @@ class SimpleJdbcCallTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeAddInvoiceWithMetaData(boolean isFunction) throws SQLException {
|
private void initializeAddInvoiceWithMetaData(boolean isFunction) throws SQLException {
|
||||||
ResultSet proceduresResultSet = mock(ResultSet.class);
|
ResultSet proceduresResultSet = mock();
|
||||||
ResultSet procedureColumnsResultSet = mock(ResultSet.class);
|
ResultSet procedureColumnsResultSet = mock();
|
||||||
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
|
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
|
||||||
given(databaseMetaData.getUserName()).willReturn("ME");
|
given(databaseMetaData.getUserName()).willReturn("ME");
|
||||||
given(databaseMetaData.storesUpperCaseIdentifiers()).willReturn(true);
|
given(databaseMetaData.storesUpperCaseIdentifiers()).willReturn(true);
|
||||||
|
|
|
@ -45,11 +45,11 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
class SimpleJdbcInsertTests {
|
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
|
@BeforeEach
|
||||||
|
@ -66,7 +66,7 @@ class SimpleJdbcInsertTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noSuchTable() throws Exception {
|
void noSuchTable() throws Exception {
|
||||||
ResultSet resultSet = mock(ResultSet.class);
|
ResultSet resultSet = mock();
|
||||||
given(resultSet.next()).willReturn(false);
|
given(resultSet.next()).willReturn(false);
|
||||||
|
|
||||||
given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB");
|
given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB");
|
||||||
|
@ -86,13 +86,13 @@ class SimpleJdbcInsertTests {
|
||||||
|
|
||||||
@Test // gh-26486
|
@Test // gh-26486
|
||||||
void retrieveColumnNamesFromMetadata() throws Exception {
|
void retrieveColumnNamesFromMetadata() throws Exception {
|
||||||
ResultSet tableResultSet = mock(ResultSet.class);
|
ResultSet tableResultSet = mock();
|
||||||
given(tableResultSet.next()).willReturn(true, false);
|
given(tableResultSet.next()).willReturn(true, false);
|
||||||
|
|
||||||
given(databaseMetaData.getUserName()).willReturn("me");
|
given(databaseMetaData.getUserName()).willReturn("me");
|
||||||
given(databaseMetaData.getTables(null, null, "me", null)).willReturn(tableResultSet);
|
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(databaseMetaData.getColumns(null, "me", null, null)).willReturn(columnResultSet);
|
||||||
given(columnResultSet.next()).willReturn(true, true, false);
|
given(columnResultSet.next()).willReturn(true, true, false);
|
||||||
given(columnResultSet.getString("COLUMN_NAME")).willReturn("col1", "col2");
|
given(columnResultSet.getString("COLUMN_NAME")).willReturn("col1", "col2");
|
||||||
|
@ -109,13 +109,13 @@ class SimpleJdbcInsertTests {
|
||||||
|
|
||||||
@Test // gh-26486
|
@Test // gh-26486
|
||||||
void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
|
void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
|
||||||
ResultSet tableResultSet = mock(ResultSet.class);
|
ResultSet tableResultSet = mock();
|
||||||
given(tableResultSet.next()).willReturn(true, false);
|
given(tableResultSet.next()).willReturn(true, false);
|
||||||
|
|
||||||
given(databaseMetaData.getUserName()).willReturn("me");
|
given(databaseMetaData.getUserName()).willReturn("me");
|
||||||
given(databaseMetaData.getTables(null, null, "me", null)).willReturn(tableResultSet);
|
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(databaseMetaData.getColumns(null, "me", null, null)).willReturn(columnResultSet);
|
||||||
// true, true, false --> simulates processing of two columns
|
// true, true, false --> simulates processing of two columns
|
||||||
given(columnResultSet.next()).willReturn(true, true, false);
|
given(columnResultSet.next()).willReturn(true, true, false);
|
||||||
|
|
|
@ -44,22 +44,19 @@ import static org.mockito.Mockito.verify;
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @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();
|
private TableMetaDataContext context = new TableMetaDataContext();
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
connection = mock(Connection.class);
|
|
||||||
dataSource = mock(DataSource.class);
|
|
||||||
databaseMetaData = mock(DatabaseMetaData.class);
|
|
||||||
given(connection.getMetaData()).willReturn(databaseMetaData);
|
given(connection.getMetaData()).willReturn(databaseMetaData);
|
||||||
given(dataSource.getConnection()).willReturn(connection);
|
given(dataSource.getConnection()).willReturn(connection);
|
||||||
}
|
}
|
||||||
|
@ -70,13 +67,13 @@ public class TableMetaDataContextTests {
|
||||||
final String TABLE = "customers";
|
final String TABLE = "customers";
|
||||||
final String USER = "me";
|
final String USER = "me";
|
||||||
|
|
||||||
ResultSet metaDataResultSet = mock(ResultSet.class);
|
ResultSet metaDataResultSet = mock();
|
||||||
given(metaDataResultSet.next()).willReturn(true, false);
|
given(metaDataResultSet.next()).willReturn(true, false);
|
||||||
given(metaDataResultSet.getString("TABLE_SCHEM")).willReturn(USER);
|
given(metaDataResultSet.getString("TABLE_SCHEM")).willReturn(USER);
|
||||||
given(metaDataResultSet.getString("TABLE_NAME")).willReturn(TABLE);
|
given(metaDataResultSet.getString("TABLE_NAME")).willReturn(TABLE);
|
||||||
given(metaDataResultSet.getString("TABLE_TYPE")).willReturn("TABLE");
|
given(metaDataResultSet.getString("TABLE_TYPE")).willReturn("TABLE");
|
||||||
|
|
||||||
ResultSet columnsResultSet = mock(ResultSet.class);
|
ResultSet columnsResultSet = mock();
|
||||||
given(columnsResultSet.next()).willReturn(
|
given(columnsResultSet.next()).willReturn(
|
||||||
true, true, true, true, false);
|
true, true, true, true, false);
|
||||||
given(columnsResultSet.getString("COLUMN_NAME")).willReturn(
|
given(columnsResultSet.getString("COLUMN_NAME")).willReturn(
|
||||||
|
@ -126,13 +123,13 @@ public class TableMetaDataContextTests {
|
||||||
final String TABLE = "customers";
|
final String TABLE = "customers";
|
||||||
final String USER = "me";
|
final String USER = "me";
|
||||||
|
|
||||||
ResultSet metaDataResultSet = mock(ResultSet.class);
|
ResultSet metaDataResultSet = mock();
|
||||||
given(metaDataResultSet.next()).willReturn(true, false);
|
given(metaDataResultSet.next()).willReturn(true, false);
|
||||||
given(metaDataResultSet.getString("TABLE_SCHEM")).willReturn(USER);
|
given(metaDataResultSet.getString("TABLE_SCHEM")).willReturn(USER);
|
||||||
given(metaDataResultSet.getString("TABLE_NAME")).willReturn(TABLE);
|
given(metaDataResultSet.getString("TABLE_NAME")).willReturn(TABLE);
|
||||||
given(metaDataResultSet.getString("TABLE_TYPE")).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.next()).willReturn(true, false);
|
||||||
given(columnsResultSet.getString("COLUMN_NAME")).willReturn("id");
|
given(columnsResultSet.getString("COLUMN_NAME")).willReturn("id");
|
||||||
given(columnsResultSet.getInt("DATA_TYPE")).willReturn(Types.INTEGER);
|
given(columnsResultSet.getInt("DATA_TYPE")).willReturn(Types.INTEGER);
|
||||||
|
|
|
@ -42,17 +42,17 @@ class JdbcBeanDefinitionReaderTests {
|
||||||
void readBeanDefinitionFromMockedDataSource() throws Exception {
|
void readBeanDefinitionFromMockedDataSource() throws Exception {
|
||||||
String sql = "SELECT NAME AS NAME, PROPERTY AS PROPERTY, VALUE AS VALUE FROM T";
|
String sql = "SELECT NAME AS NAME, PROPERTY AS PROPERTY, VALUE AS VALUE FROM T";
|
||||||
|
|
||||||
Connection connection = mock(Connection.class);
|
Connection connection = mock();
|
||||||
DataSource dataSource = mock(DataSource.class);
|
DataSource dataSource = mock();
|
||||||
given(dataSource.getConnection()).willReturn(connection);
|
given(dataSource.getConnection()).willReturn(connection);
|
||||||
|
|
||||||
ResultSet resultSet = mock(ResultSet.class);
|
ResultSet resultSet = mock();
|
||||||
given(resultSet.next()).willReturn(true, true, false);
|
given(resultSet.next()).willReturn(true, true, false);
|
||||||
given(resultSet.getString(1)).willReturn("one", "one");
|
given(resultSet.getString(1)).willReturn("one", "one");
|
||||||
given(resultSet.getString(2)).willReturn("(class)", "age");
|
given(resultSet.getString(2)).willReturn("(class)", "age");
|
||||||
given(resultSet.getString(3)).willReturn("org.springframework.beans.testfixture.beans.TestBean", "53");
|
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(statement.executeQuery(sql)).willReturn(resultSet);
|
||||||
given(connection.createStatement()).willReturn(statement);
|
given(connection.createStatement()).willReturn(statement);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class JdbcDaoSupportTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJdbcDaoSupportWithDataSource() throws Exception {
|
public void testJdbcDaoSupportWithDataSource() throws Exception {
|
||||||
DataSource ds = mock(DataSource.class);
|
DataSource ds = mock();
|
||||||
final List<String> test = new ArrayList<>();
|
final List<String> test = new ArrayList<>();
|
||||||
JdbcDaoSupport dao = new JdbcDaoSupport() {
|
JdbcDaoSupport dao = new JdbcDaoSupport() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,9 +42,9 @@ public class LobSupportTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreatingPreparedStatementCallback() throws SQLException {
|
public void testCreatingPreparedStatementCallback() throws SQLException {
|
||||||
LobHandler handler = mock(LobHandler.class);
|
LobHandler handler = mock();
|
||||||
LobCreator creator = mock(LobCreator.class);
|
LobCreator creator = mock();
|
||||||
PreparedStatement ps = mock(PreparedStatement.class);
|
PreparedStatement ps = mock();
|
||||||
|
|
||||||
given(handler.getLobCreator()).willReturn(creator);
|
given(handler.getLobCreator()).willReturn(creator);
|
||||||
given(ps.executeUpdate()).willReturn(3);
|
given(ps.executeUpdate()).willReturn(3);
|
||||||
|
@ -73,7 +73,7 @@ public class LobSupportTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLException {
|
public void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLException {
|
||||||
ResultSet rset = mock(ResultSet.class);
|
ResultSet rset = mock();
|
||||||
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
||||||
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
|
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
|
||||||
lobRse.extractData(rset));
|
lobRse.extractData(rset));
|
||||||
|
@ -82,7 +82,7 @@ public class LobSupportTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLException {
|
public void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLException {
|
||||||
ResultSet rset = mock(ResultSet.class);
|
ResultSet rset = mock();
|
||||||
given(rset.next()).willReturn(true, false);
|
given(rset.next()).willReturn(true, false);
|
||||||
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
||||||
lobRse.extractData(rset);
|
lobRse.extractData(rset);
|
||||||
|
@ -92,7 +92,7 @@ public class LobSupportTests {
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractLobStreamingResultSetExtractorMultipleRows()
|
public void testAbstractLobStreamingResultSetExtractorMultipleRows()
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
ResultSet rset = mock(ResultSet.class);
|
ResultSet rset = mock();
|
||||||
given(rset.next()).willReturn(true, true, false);
|
given(rset.next()).willReturn(true, true, false);
|
||||||
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
||||||
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
|
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
|
||||||
|
@ -103,7 +103,7 @@ public class LobSupportTests {
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractLobStreamingResultSetExtractorCorrectException()
|
public void testAbstractLobStreamingResultSetExtractorCorrectException()
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
ResultSet rset = mock(ResultSet.class);
|
ResultSet rset = mock();
|
||||||
given(rset.next()).willReturn(true);
|
given(rset.next()).willReturn(true);
|
||||||
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(true);
|
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(true);
|
||||||
assertThatExceptionOfType(LobRetrievalFailureException.class).isThrownBy(() ->
|
assertThatExceptionOfType(LobRetrievalFailureException.class).isThrownBy(() ->
|
||||||
|
|
|
@ -63,19 +63,18 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class DataSourceJtaTransactionTests {
|
public class DataSourceJtaTransactionTests {
|
||||||
|
|
||||||
private Connection connection;
|
private DataSource dataSource = mock();
|
||||||
private DataSource dataSource;
|
|
||||||
private UserTransaction userTransaction;
|
private Connection connection = mock();
|
||||||
private TransactionManager transactionManager;
|
|
||||||
private Transaction transaction;
|
private UserTransaction userTransaction = mock();
|
||||||
|
|
||||||
|
private TransactionManager transactionManager = mock();
|
||||||
|
|
||||||
|
private Transaction transaction = mock();
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
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);
|
given(dataSource.getConnection()).willReturn(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,9 +364,9 @@ public class DataSourceJtaTransactionTests {
|
||||||
Status.STATUS_ACTIVE);
|
Status.STATUS_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
final DataSource dataSource = mock(DataSource.class);
|
final DataSource dataSource = mock();
|
||||||
final Connection connection1 = mock(Connection.class);
|
final Connection connection1 = mock();
|
||||||
final Connection connection2 = mock(Connection.class);
|
final Connection connection2 = mock();
|
||||||
given(dataSource.getConnection()).willReturn(connection1, connection2);
|
given(dataSource.getConnection()).willReturn(connection1, connection2);
|
||||||
|
|
||||||
final JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
|
final JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
|
||||||
|
@ -686,14 +685,15 @@ public class DataSourceJtaTransactionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestJtaTransactionWithIsolationLevelDataSourceRouter(boolean dataSourceLookup) throws Exception {
|
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 DataSource dataSource1 = mock();
|
||||||
final Connection connection1 = mock(Connection.class);
|
final Connection connection1 = mock();
|
||||||
given(dataSource1.getConnection()).willReturn(connection1);
|
given(dataSource1.getConnection()).willReturn(connection1);
|
||||||
|
|
||||||
final DataSource dataSource2 = mock(DataSource.class);
|
final DataSource dataSource2 = mock();
|
||||||
final Connection connection2 = mock(Connection.class);
|
final Connection connection2 = mock();
|
||||||
given(dataSource2.getConnection()).willReturn(connection2);
|
given(dataSource2.getConnection()).willReturn(connection2);
|
||||||
|
|
||||||
final IsolationLevelDataSourceRouter dsToUse = new IsolationLevelDataSourceRouter();
|
final IsolationLevelDataSourceRouter dsToUse = new IsolationLevelDataSourceRouter();
|
||||||
|
|
|
@ -67,21 +67,18 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
||||||
* @since 04.07.2003
|
* @since 04.07.2003
|
||||||
* @see org.springframework.jdbc.support.JdbcTransactionManagerTests
|
* @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
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
ds = mock(DataSource.class);
|
|
||||||
con = mock(Connection.class);
|
|
||||||
given(ds.getConnection()).willReturn(con);
|
given(ds.getConnection()).willReturn(con);
|
||||||
tm = new DataSourceTransactionManager(ds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
|
@ -515,8 +512,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParticipatingTransactionWithDifferentConnectionObtainedFromSynch() throws Exception {
|
public void testParticipatingTransactionWithDifferentConnectionObtainedFromSynch() throws Exception {
|
||||||
DataSource ds2 = mock(DataSource.class);
|
DataSource ds2 = mock();
|
||||||
final Connection con2 = mock(Connection.class);
|
final Connection con2 = mock();
|
||||||
given(ds2.getConnection()).willReturn(con2);
|
given(ds2.getConnection()).willReturn(con2);
|
||||||
|
|
||||||
boolean condition2 = !TransactionSynchronizationManager.hasResource(ds);
|
boolean condition2 = !TransactionSynchronizationManager.hasResource(ds);
|
||||||
|
@ -651,8 +648,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedDataSource() throws Exception {
|
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedDataSource() throws Exception {
|
||||||
Connection con2 = mock(Connection.class);
|
Connection con2 = mock();
|
||||||
final DataSource ds2 = mock(DataSource.class);
|
final DataSource ds2 = mock();
|
||||||
given(ds2.getConnection()).willReturn(con2);
|
given(ds2.getConnection()).willReturn(con2);
|
||||||
|
|
||||||
final TransactionTemplate tt = new TransactionTemplate(tm);
|
final TransactionTemplate tt = new TransactionTemplate(tm);
|
||||||
|
@ -705,7 +702,7 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedFailingDataSource() throws Exception {
|
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedFailingDataSource() throws Exception {
|
||||||
final DataSource ds2 = mock(DataSource.class);
|
final DataSource ds2 = mock();
|
||||||
SQLException failure = new SQLException();
|
SQLException failure = new SQLException();
|
||||||
given(ds2.getConnection()).willThrow(failure);
|
given(ds2.getConnection()).willThrow(failure);
|
||||||
|
|
||||||
|
@ -857,8 +854,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropagationSupportsAndRequiresNewWithEarlyAccess() throws Exception {
|
public void testPropagationSupportsAndRequiresNewWithEarlyAccess() throws Exception {
|
||||||
final Connection con1 = mock(Connection.class);
|
final Connection con1 = mock();
|
||||||
final Connection con2 = mock(Connection.class);
|
final Connection con2 = mock();
|
||||||
given(ds.getConnection()).willReturn(con1, con2);
|
given(ds.getConnection()).willReturn(con1, con2);
|
||||||
|
|
||||||
final
|
final
|
||||||
|
@ -936,7 +933,7 @@ public class DataSourceTransactionManagerTests {
|
||||||
tm.setEnforceReadOnly(true);
|
tm.setEnforceReadOnly(true);
|
||||||
|
|
||||||
given(con.getAutoCommit()).willReturn(true);
|
given(con.getAutoCommit()).willReturn(true);
|
||||||
Statement stmt = mock(Statement.class);
|
Statement stmt = mock();
|
||||||
given(con.createStatement()).willReturn(stmt);
|
given(con.createStatement()).willReturn(stmt);
|
||||||
|
|
||||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||||
|
@ -970,7 +967,7 @@ public class DataSourceTransactionManagerTests {
|
||||||
@ValueSource(ints = {1, 10})
|
@ValueSource(ints = {1, 10})
|
||||||
@EnabledForTestGroups(LONG_RUNNING)
|
@EnabledForTestGroups(LONG_RUNNING)
|
||||||
public void transactionWithTimeout(int timeout) throws Exception {
|
public void transactionWithTimeout(int timeout) throws Exception {
|
||||||
PreparedStatement ps = mock(PreparedStatement.class);
|
PreparedStatement ps = mock();
|
||||||
given(con.getAutoCommit()).willReturn(true);
|
given(con.getAutoCommit()).willReturn(true);
|
||||||
given(con.prepareStatement("some SQL statement")).willReturn(ps);
|
given(con.prepareStatement("some SQL statement")).willReturn(ps);
|
||||||
|
|
||||||
|
@ -1342,8 +1339,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestExistingTransactionWithPropagationNested(final int count) throws Exception {
|
private void doTestExistingTransactionWithPropagationNested(final int count) throws Exception {
|
||||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
DatabaseMetaData md = mock();
|
||||||
Savepoint sp = mock(Savepoint.class);
|
Savepoint sp = mock();
|
||||||
|
|
||||||
given(md.supportsSavepoints()).willReturn(true);
|
given(md.supportsSavepoints()).willReturn(true);
|
||||||
given(con.getMetaData()).willReturn(md);
|
given(con.getMetaData()).willReturn(md);
|
||||||
|
@ -1391,8 +1388,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExistingTransactionWithPropagationNestedAndRollback() throws Exception {
|
public void testExistingTransactionWithPropagationNestedAndRollback() throws Exception {
|
||||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
DatabaseMetaData md = mock();
|
||||||
Savepoint sp = mock(Savepoint.class);
|
Savepoint sp = mock();
|
||||||
|
|
||||||
given(md.supportsSavepoints()).willReturn(true);
|
given(md.supportsSavepoints()).willReturn(true);
|
||||||
given(con.getMetaData()).willReturn(md);
|
given(con.getMetaData()).willReturn(md);
|
||||||
|
@ -1438,8 +1435,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExistingTransactionWithPropagationNestedAndRequiredRollback() throws Exception {
|
public void testExistingTransactionWithPropagationNestedAndRequiredRollback() throws Exception {
|
||||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
DatabaseMetaData md = mock();
|
||||||
Savepoint sp = mock(Savepoint.class);
|
Savepoint sp = mock();
|
||||||
|
|
||||||
given(md.supportsSavepoints()).willReturn(true);
|
given(md.supportsSavepoints()).willReturn(true);
|
||||||
given(con.getMetaData()).willReturn(md);
|
given(con.getMetaData()).willReturn(md);
|
||||||
|
@ -1498,8 +1495,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExistingTransactionWithPropagationNestedAndRequiredRollbackOnly() throws Exception {
|
public void testExistingTransactionWithPropagationNestedAndRequiredRollbackOnly() throws Exception {
|
||||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
DatabaseMetaData md = mock();
|
||||||
Savepoint sp = mock(Savepoint.class);
|
Savepoint sp = mock();
|
||||||
|
|
||||||
given(md.supportsSavepoints()).willReturn(true);
|
given(md.supportsSavepoints()).willReturn(true);
|
||||||
given(con.getMetaData()).willReturn(md);
|
given(con.getMetaData()).willReturn(md);
|
||||||
|
@ -1558,8 +1555,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExistingTransactionWithManualSavepoint() throws Exception {
|
public void testExistingTransactionWithManualSavepoint() throws Exception {
|
||||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
DatabaseMetaData md = mock();
|
||||||
Savepoint sp = mock(Savepoint.class);
|
Savepoint sp = mock();
|
||||||
|
|
||||||
given(md.supportsSavepoints()).willReturn(true);
|
given(md.supportsSavepoints()).willReturn(true);
|
||||||
given(con.getMetaData()).willReturn(md);
|
given(con.getMetaData()).willReturn(md);
|
||||||
|
@ -1592,8 +1589,8 @@ public class DataSourceTransactionManagerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExistingTransactionWithManualSavepointAndRollback() throws Exception {
|
public void testExistingTransactionWithManualSavepointAndRollback() throws Exception {
|
||||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
DatabaseMetaData md = mock();
|
||||||
Savepoint sp = mock(Savepoint.class);
|
Savepoint sp = mock();
|
||||||
|
|
||||||
given(md.supportsSavepoints()).willReturn(true);
|
given(md.supportsSavepoints()).willReturn(true);
|
||||||
given(con.getMetaData()).willReturn(md);
|
given(con.getMetaData()).willReturn(md);
|
||||||
|
|
|
@ -38,7 +38,7 @@ class DataSourceUtilsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConnectionNotAcquiredExceptionIsPropagated() throws SQLException {
|
void testConnectionNotAcquiredExceptionIsPropagated() throws SQLException {
|
||||||
DataSource dataSource = mock(DataSource.class);
|
DataSource dataSource = mock();
|
||||||
when(dataSource.getConnection()).thenReturn(null);
|
when(dataSource.getConnection()).thenReturn(null);
|
||||||
assertThatThrownBy(() -> DataSourceUtils.getConnection(dataSource))
|
assertThatThrownBy(() -> DataSourceUtils.getConnection(dataSource))
|
||||||
.isInstanceOf(CannotGetJdbcConnectionException.class)
|
.isInstanceOf(CannotGetJdbcConnectionException.class)
|
||||||
|
@ -48,7 +48,7 @@ class DataSourceUtilsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConnectionSQLExceptionIsPropagated() throws SQLException {
|
void testConnectionSQLExceptionIsPropagated() throws SQLException {
|
||||||
DataSource dataSource = mock(DataSource.class);
|
DataSource dataSource = mock();
|
||||||
when(dataSource.getConnection()).thenThrow(new SQLException("my dummy exception"));
|
when(dataSource.getConnection()).thenThrow(new SQLException("my dummy exception"));
|
||||||
assertThatThrownBy(() -> DataSourceUtils.getConnection(dataSource))
|
assertThatThrownBy(() -> DataSourceUtils.getConnection(dataSource))
|
||||||
.isInstanceOf(CannotGetJdbcConnectionException.class)
|
.isInstanceOf(CannotGetJdbcConnectionException.class)
|
||||||
|
|
|
@ -36,20 +36,20 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class DelegatingDataSourceTests {
|
public class DelegatingDataSourceTests {
|
||||||
|
|
||||||
private final DataSource delegate = mock(DataSource.class);
|
private final DataSource delegate = mock();
|
||||||
|
|
||||||
private DelegatingDataSource dataSource = new DelegatingDataSource(delegate);
|
private DelegatingDataSource dataSource = new DelegatingDataSource(delegate);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDelegateGetConnection() throws Exception {
|
public void shouldDelegateGetConnection() throws Exception {
|
||||||
Connection connection = mock(Connection.class);
|
Connection connection = mock();
|
||||||
given(delegate.getConnection()).willReturn(connection);
|
given(delegate.getConnection()).willReturn(connection);
|
||||||
assertThat(dataSource.getConnection()).isEqualTo(connection);
|
assertThat(dataSource.getConnection()).isEqualTo(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDelegateGetConnectionWithUsernameAndPassword() throws Exception {
|
public void shouldDelegateGetConnectionWithUsernameAndPassword() throws Exception {
|
||||||
Connection connection = mock(Connection.class);
|
Connection connection = mock();
|
||||||
String username = "username";
|
String username = "username";
|
||||||
String password = "password";
|
String password = "password";
|
||||||
given(delegate.getConnection(username, password)).willReturn(connection);
|
given(delegate.getConnection(username, password)).willReturn(connection);
|
||||||
|
@ -86,7 +86,7 @@ public class DelegatingDataSourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDelegateUnwrapWithoutImplementing() throws Exception {
|
public void shouldDelegateUnwrapWithoutImplementing() throws Exception {
|
||||||
ExampleWrapper wrapper = mock(ExampleWrapper.class);
|
ExampleWrapper wrapper = mock();
|
||||||
given(delegate.unwrap(ExampleWrapper.class)).willReturn(wrapper);
|
given(delegate.unwrap(ExampleWrapper.class)).willReturn(wrapper);
|
||||||
assertThat(dataSource.unwrap(ExampleWrapper.class)).isEqualTo(wrapper);
|
assertThat(dataSource.unwrap(ExampleWrapper.class)).isEqualTo(wrapper);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class DriverManagerDataSourceTests {
|
public class DriverManagerDataSourceTests {
|
||||||
|
|
||||||
private Connection connection = mock(Connection.class);
|
private Connection connection = mock();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStandardUsage() throws Exception {
|
public void testStandardUsage() throws Exception {
|
||||||
|
|
|
@ -35,8 +35,8 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaticCredentials() throws SQLException {
|
public void testStaticCredentials() throws SQLException {
|
||||||
DataSource dataSource = mock(DataSource.class);
|
DataSource dataSource = mock();
|
||||||
Connection connection = mock(Connection.class);
|
Connection connection = mock();
|
||||||
given(dataSource.getConnection("user", "pw")).willReturn(connection);
|
given(dataSource.getConnection("user", "pw")).willReturn(connection);
|
||||||
|
|
||||||
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
||||||
|
@ -48,8 +48,8 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCredentials() throws SQLException {
|
public void testNoCredentials() throws SQLException {
|
||||||
DataSource dataSource = mock(DataSource.class);
|
DataSource dataSource = mock();
|
||||||
Connection connection = mock(Connection.class);
|
Connection connection = mock();
|
||||||
given(dataSource.getConnection()).willReturn(connection);
|
given(dataSource.getConnection()).willReturn(connection);
|
||||||
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
||||||
adapter.setTargetDataSource(dataSource);
|
adapter.setTargetDataSource(dataSource);
|
||||||
|
@ -58,8 +58,8 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThreadBoundCredentials() throws SQLException {
|
public void testThreadBoundCredentials() throws SQLException {
|
||||||
DataSource dataSource = mock(DataSource.class);
|
DataSource dataSource = mock();
|
||||||
Connection connection = mock(Connection.class);
|
Connection connection = mock();
|
||||||
given(dataSource.getConnection("user", "pw")).willReturn(connection);
|
given(dataSource.getConnection("user", "pw")).willReturn(connection);
|
||||||
|
|
||||||
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
||||||
|
|
|
@ -169,7 +169,7 @@ abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseInitializa
|
||||||
void usesBoundConnectionIfAvailable() throws SQLException {
|
void usesBoundConnectionIfAvailable() throws SQLException {
|
||||||
TransactionSynchronizationManager.initSynchronization();
|
TransactionSynchronizationManager.initSynchronization();
|
||||||
Connection connection = DataSourceUtils.getConnection(db);
|
Connection connection = DataSourceUtils.getConnection(db);
|
||||||
DatabasePopulator populator = mock(DatabasePopulator.class);
|
DatabasePopulator populator = mock();
|
||||||
DatabasePopulatorUtils.execute(populator, db);
|
DatabasePopulatorUtils.execute(populator, db);
|
||||||
verify(populator).populate(connection);
|
verify(populator).populate(connection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,11 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
class CompositeDatabasePopulatorTests {
|
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
|
@Test
|
||||||
|
|
|
@ -33,9 +33,9 @@ import static org.mockito.BDDMockito.mock;
|
||||||
*/
|
*/
|
||||||
class ResourceDatabasePopulatorUnitTests {
|
class ResourceDatabasePopulatorUnitTests {
|
||||||
|
|
||||||
private static final Resource script1 = mock(Resource.class);
|
private static final Resource script1 = mock();
|
||||||
private static final Resource script2 = mock(Resource.class);
|
private static final Resource script2 = mock();
|
||||||
private static final Resource script3 = mock(Resource.class);
|
private static final Resource script3 = mock();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class BeanFactoryDataSourceLookupTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupSunnyDay() {
|
public void testLookupSunnyDay() {
|
||||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
BeanFactory beanFactory = mock();
|
||||||
|
|
||||||
StubDataSource expectedDataSource = new StubDataSource();
|
StubDataSource expectedDataSource = new StubDataSource();
|
||||||
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willReturn(expectedDataSource);
|
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willReturn(expectedDataSource);
|
||||||
|
@ -56,7 +56,7 @@ public class BeanFactoryDataSourceLookupTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLookupWhereBeanFactoryYieldsNonDataSourceType() throws Exception {
|
public void testLookupWhereBeanFactoryYieldsNonDataSourceType() throws Exception {
|
||||||
final BeanFactory beanFactory = mock(BeanFactory.class);
|
final BeanFactory beanFactory = mock();
|
||||||
|
|
||||||
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willThrow(
|
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willThrow(
|
||||||
new BeanNotOfRequiredTypeException(DATASOURCE_BEAN_NAME,
|
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