Migrate to BDD Mockito

Migrate all tests to consistently use BDD Mockito. Also add
checksyle rule to enforce going forwards.
This commit is contained in:
Phillip Webb
2019-05-08 13:45:42 -07:00
parent 816bbee8de
commit 798b51f4a3
55 changed files with 322 additions and 324 deletions

View File

@@ -45,7 +45,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
@@ -112,13 +111,13 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Tests properties population and autowire behavior.
@@ -135,8 +134,6 @@ public class DefaultListableBeanFactoryTests {
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
@Test
public void testUnreferencedSingletonWasInstantiated() {
KnowsIfInstantiated.clearInstantiationRecord();
@@ -1240,8 +1237,8 @@ public class DefaultListableBeanFactoryTests {
public void testExpressionInStringArray() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
when(beanExpressionResolver.evaluate(eq("#{foo}"), ArgumentMatchers.any(BeanExpressionContext.class)))
.thenReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
given(beanExpressionResolver.evaluate(eq("#{foo}"), any(BeanExpressionContext.class)))
.willReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
bf.setBeanExpressionResolver(beanExpressionResolver);
RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class);

View File

@@ -33,8 +33,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Unit tests for {@link ParameterResolutionDelegate}.
@@ -128,7 +128,7 @@ public class ParameterResolutionTests {
AutowireCapableBeanFactory beanFactory = mock(AutowireCapableBeanFactory.class);
// Configure the mocked BeanFactory to return the DependencyDescriptor for convenience and
// to avoid using an ArgumentCaptor.
when(beanFactory.resolveDependency(any(), isNull())).thenAnswer(invocation -> invocation.getArgument(0));
given(beanFactory.resolveDependency(any(), isNull())).willAnswer(invocation -> invocation.getArgument(0));
Parameter[] parameters = constructor.getParameters();
for (int parameterIndex = 0; parameterIndex < parameters.length; parameterIndex++) {