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

This commit is contained in:
Sam Brannen
2023-01-19 14:32:29 +01:00
parent c3d123fef7
commit c4c786596f
369 changed files with 2267 additions and 2707 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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