Polish mockito usage

Consistent use of BDDMockito rather than standard Mockito.
This commit is contained in:
Phillip Webb
2014-08-11 11:17:46 -07:00
parent 4db258b9e3
commit ac8326d2df
37 changed files with 317 additions and 354 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.web.servlet.mvc.method.annotation;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -35,10 +37,8 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.ControllerAdviceBean;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* Unit tests for
@@ -80,9 +80,9 @@ public class ResponseBodyAdviceChainTests {
ResponseBodyAdviceChain chain = new ResponseBodyAdviceChain(Arrays.asList(advice));
String expected = "body++";
when(advice.supports(this.returnType, this.converterType)).thenReturn(true);
when(advice.beforeBodyWrite(eq(this.body), eq(this.returnType), eq(this.contentType),
eq(this.converterType), same(this.request), same(this.response))).thenReturn(expected);
given(advice.supports(this.returnType, this.converterType)).willReturn(true);
given(advice.beforeBodyWrite(eq(this.body), eq(this.returnType), eq(this.contentType),
eq(this.converterType), same(this.request), same(this.response))).willReturn(expected);
String actual = chain.invoke(this.body, this.returnType,
this.contentType, this.converterType, this.request, this.response);

View File

@@ -16,9 +16,6 @@
package org.springframework.web.servlet.resource;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -28,11 +25,13 @@ import javax.servlet.http.HttpServletRequest;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.FileCopyUtils;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* Unit tests for
* {@link AppCacheManifestTransfomer}.
@@ -57,8 +56,8 @@ public class AppCacheManifestTransformerTests {
@Test
public void noTransformIfExtensionNoMatch() throws Exception {
Resource resource = mock(Resource.class);
when(resource.getFilename()).thenReturn("foobar.file");
when(this.chain.transform(this.request, resource)).thenReturn(resource);
given(resource.getFilename()).willReturn("foobar.file");
given(this.chain.transform(this.request, resource)).willReturn(resource);
Resource result = this.transformer.transform(this.request, resource, this.chain);
assertEquals(resource, result);
@@ -67,7 +66,7 @@ public class AppCacheManifestTransformerTests {
@Test
public void syntaxErrorInManifest() throws Exception {
Resource resource = new ClassPathResource("test/error.manifest", getClass());
when(this.chain.transform(this.request, resource)).thenReturn(resource);
given(this.chain.transform(this.request, resource)).willReturn(resource);
Resource result = this.transformer.transform(this.request, resource, this.chain);
assertEquals(resource, result);

View File

@@ -23,12 +23,11 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.BDDMockito.*;
/**
* Unit tests for {@link VersionResourceResolver}
@@ -62,7 +61,7 @@ public class VersionResourceResolverTests {
public void resolveResourceExisting() throws Exception {
String file = "bar.css";
Resource expected = new ClassPathResource("test/" + file, getClass());
when(this.chain.resolveResource(null, file, this.locations)).thenReturn(expected);
given(this.chain.resolveResource(null, file, this.locations)).willReturn(expected);
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
Resource actual = this.resolver.resolveResourceInternal(null, file, this.locations, this.chain);
@@ -74,7 +73,7 @@ public class VersionResourceResolverTests {
@Test
public void resolveResourceNoVersionStrategy() throws Exception {
String file = "missing.css";
when(this.chain.resolveResource(null, file, this.locations)).thenReturn(null);
given(this.chain.resolveResource(null, file, this.locations)).willReturn(null);
this.resolver.setStrategyMap(Collections.emptyMap());
Resource actual = this.resolver.resolveResourceInternal(null, file, this.locations, this.chain);
@@ -85,8 +84,8 @@ public class VersionResourceResolverTests {
@Test
public void resolveResourceNoVersionInPath() throws Exception {
String file = "bar.css";
when(this.chain.resolveResource(null, file, this.locations)).thenReturn(null);
when(this.versionStrategy.extractVersion(file)).thenReturn("");
given(this.chain.resolveResource(null, file, this.locations)).willReturn(null);
given(this.versionStrategy.extractVersion(file)).willReturn("");
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
Resource actual = this.resolver.resolveResourceInternal(null, file, this.locations, this.chain);
@@ -100,10 +99,10 @@ public class VersionResourceResolverTests {
String versionFile = "bar-version.css";
String version = "version";
String file = "bar.css";
when(this.chain.resolveResource(null, versionFile, this.locations)).thenReturn(null);
when(this.chain.resolveResource(null, file, this.locations)).thenReturn(null);
when(this.versionStrategy.extractVersion(versionFile)).thenReturn(version);
when(this.versionStrategy.removeVersion(versionFile, version)).thenReturn(file);
given(this.chain.resolveResource(null, versionFile, this.locations)).willReturn(null);
given(this.chain.resolveResource(null, file, this.locations)).willReturn(null);
given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
given(this.versionStrategy.removeVersion(versionFile, version)).willReturn(file);
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
Resource actual = this.resolver.resolveResourceInternal(null, versionFile, this.locations, this.chain);
@@ -117,11 +116,11 @@ public class VersionResourceResolverTests {
String version = "version";
String file = "bar.css";
Resource expected = new ClassPathResource("test/" + file, getClass());
when(this.chain.resolveResource(null, versionFile, this.locations)).thenReturn(null);
when(this.chain.resolveResource(null, file, this.locations)).thenReturn(expected);
when(this.versionStrategy.extractVersion(versionFile)).thenReturn(version);
when(this.versionStrategy.removeVersion(versionFile, version)).thenReturn(file);
when(this.versionStrategy.getResourceVersion(expected)).thenReturn("newer-version");
given(this.chain.resolveResource(null, versionFile, this.locations)).willReturn(null);
given(this.chain.resolveResource(null, file, this.locations)).willReturn(expected);
given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
given(this.versionStrategy.removeVersion(versionFile, version)).willReturn(file);
given(this.versionStrategy.getResourceVersion(expected)).willReturn("newer-version");
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
Resource actual = this.resolver.resolveResourceInternal(null, versionFile, this.locations, this.chain);
@@ -135,11 +134,11 @@ public class VersionResourceResolverTests {
String version = "version";
String file = "bar.css";
Resource expected = new ClassPathResource("test/" + file, getClass());
when(this.chain.resolveResource(null, versionFile, this.locations)).thenReturn(null);
when(this.chain.resolveResource(null, file, this.locations)).thenReturn(expected);
when(this.versionStrategy.extractVersion(versionFile)).thenReturn(version);
when(this.versionStrategy.removeVersion(versionFile, version)).thenReturn(file);
when(this.versionStrategy.getResourceVersion(expected)).thenReturn(version);
given(this.chain.resolveResource(null, versionFile, this.locations)).willReturn(null);
given(this.chain.resolveResource(null, file, this.locations)).willReturn(expected);
given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
given(this.versionStrategy.removeVersion(versionFile, version)).willReturn(file);
given(this.versionStrategy.getResourceVersion(expected)).willReturn(version);
this.resolver
.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));