Browse Source

Upgrade to Mockito 2.11

Includes fixes for invalid exception declarations in Mockito-based unit tests. Also includes FreeMarker 2.3.27, Commons Pool 2.4.3, JSON-P 1.1.2.

Issue: SPR-16157
pull/1579/merge
Juergen Hoeller 7 years ago
parent
commit
996d747aed
  1. 4
      build.gradle
  2. 2
      spring-aop/spring-aop.gradle
  3. 2
      spring-context/spring-context.gradle
  4. 6
      spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java
  5. 9
      spring-core/src/test/java/org/springframework/tests/MockitoUtils.java
  6. 2
      spring-web/spring-web.gradle
  7. 22
      spring-web/src/test/java/org/springframework/http/HttpRangeTests.java
  8. 4
      spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java

4
build.gradle

@ -42,7 +42,7 @@ configure(allprojects) { project -> @@ -42,7 +42,7 @@ configure(allprojects) { project ->
version = qualifyVersionIfNecessary(version)
ext.aspectjVersion = "1.8.12"
ext.freemarkerVersion = "2.3.26-incubating"
ext.freemarkerVersion = "2.3.27-incubating"
ext.groovyVersion = "2.4.12"
ext.hsqldbVersion = "2.4.0"
ext.jackson2Version = "2.9.2"
@ -132,7 +132,7 @@ configure(allprojects) { project -> @@ -132,7 +132,7 @@ configure(allprojects) { project ->
testCompile("junit:junit:4.12") {
exclude group:'org.hamcrest', module:'hamcrest-core'
}
testCompile("org.mockito:mockito-core:2.6.1") {
testCompile("org.mockito:mockito-core:2.11.0") {
exclude group:'org.hamcrest', module:'hamcrest-core'
}
testCompile("com.nhaarman:mockito-kotlin:1.5.0") {

2
spring-aop/spring-aop.gradle

@ -4,6 +4,6 @@ dependencies { @@ -4,6 +4,6 @@ dependencies {
compile(project(":spring-beans"))
compile(project(':spring-core'))
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
optional("org.apache.commons:commons-pool2:2.4.2")
optional("org.apache.commons:commons-pool2:2.4.3")
optional("com.jamonapi:jamon:2.81")
}

2
spring-context/spring-context.gradle

@ -23,7 +23,7 @@ dependencies { @@ -23,7 +23,7 @@ dependencies {
optional("org.hibernate:hibernate-validator:5.4.2.Final")
optional("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
optional("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}")
testCompile("org.apache.commons:commons-pool2:2.4.2")
testCompile("org.apache.commons:commons-pool2:2.4.3")
testCompile("org.slf4j:slf4j-api:${slf4jVersion}")
testCompile("javax.inject:javax.inject-tck:1")
testRuntime("javax.xml.bind:jaxb-api:2.3.0")

6
spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java

@ -48,7 +48,7 @@ public class ByteArrayResource extends AbstractResource { @@ -48,7 +48,7 @@ public class ByteArrayResource extends AbstractResource {
/**
* Create a new ByteArrayResource.
* Create a new {@code ByteArrayResource}.
* @param byteArray the byte array to wrap
*/
public ByteArrayResource(byte[] byteArray) {
@ -56,7 +56,7 @@ public class ByteArrayResource extends AbstractResource { @@ -56,7 +56,7 @@ public class ByteArrayResource extends AbstractResource {
}
/**
* Create a new ByteArrayResource.
* Create a new {@code ByteArrayResource} with a description.
* @param byteArray the byte array to wrap
* @param description where the byte array comes from
*/
@ -66,6 +66,7 @@ public class ByteArrayResource extends AbstractResource { @@ -66,6 +66,7 @@ public class ByteArrayResource extends AbstractResource {
this.description = (description != null ? description : "");
}
/**
* Return the underlying byte array.
*/
@ -73,7 +74,6 @@ public class ByteArrayResource extends AbstractResource { @@ -73,7 +74,6 @@ public class ByteArrayResource extends AbstractResource {
return this.byteArray;
}
/**
* This implementation always returns {@code true}.
*/

9
spring-core/src/test/java/org/springframework/tests/MockitoUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.tests; @@ -19,6 +19,7 @@ package org.springframework.tests;
import java.util.List;
import org.mockito.Mockito;
import org.mockito.internal.stubbing.InvocationContainerImpl;
import org.mockito.internal.util.MockUtil;
import org.mockito.invocation.Invocation;
@ -40,8 +41,10 @@ public abstract class MockitoUtils { @@ -40,8 +41,10 @@ public abstract class MockitoUtils {
* @param argumentAdapters adapters that can be used to change argument values before they are compared
*/
public static <T> void verifySameInvocations(T expected, T actual, InvocationArgumentsAdapter... argumentAdapters) {
List<Invocation> expectedInvocations = MockUtil.getMockHandler(expected).getInvocationContainer().getInvocations();
List<Invocation> actualInvocations = MockUtil.getMockHandler(actual).getInvocationContainer().getInvocations();
List<Invocation> expectedInvocations =
((InvocationContainerImpl) MockUtil.getMockHandler(expected).getInvocationContainer()).getInvocations();
List<Invocation> actualInvocations =
((InvocationContainerImpl) MockUtil.getMockHandler(actual).getInvocationContainer()).getInvocations();
verifySameInvocations(expectedInvocations, actualInvocations, argumentAdapters);
}

2
spring-web/spring-web.gradle

@ -87,6 +87,6 @@ dependencies { @@ -87,6 +87,6 @@ dependencies {
testRuntime("com.sun.mail:javax.mail:1.6.0")
testRuntime("com.sun.xml.bind:jaxb-core:2.3.0")
testRuntime("com.sun.xml.bind:jaxb-impl:2.3.0")
testRuntime("javax.json:javax.json-api:1.1")
testRuntime("javax.json:javax.json-api:1.1.2")
testRuntime("org.apache.johnzon:johnzon-jsonb:1.1.4")
}

22
spring-web/src/test/java/org/springframework/http/HttpRangeTests.java

@ -39,57 +39,57 @@ import static org.mockito.BDDMockito.*; @@ -39,57 +39,57 @@ import static org.mockito.BDDMockito.*;
public class HttpRangeTests {
@Test(expected = IllegalArgumentException.class)
public void invalidFirstPosition() throws Exception {
public void invalidFirstPosition() {
HttpRange.createByteRange(-1);
}
@Test(expected = IllegalArgumentException.class)
public void invalidLastLessThanFirst() throws Exception {
public void invalidLastLessThanFirst() {
HttpRange.createByteRange(10, 9);
}
@Test(expected = IllegalArgumentException.class)
public void invalidSuffixLength() throws Exception {
public void invalidSuffixLength() {
HttpRange.createSuffixRange(-1);
}
@Test
public void byteRange() throws Exception {
public void byteRange() {
HttpRange range = HttpRange.createByteRange(0, 499);
assertEquals(0, range.getRangeStart(1000));
assertEquals(499, range.getRangeEnd(1000));
}
@Test
public void byteRangeWithoutLastPosition() throws Exception {
public void byteRangeWithoutLastPosition() {
HttpRange range = HttpRange.createByteRange(9500);
assertEquals(9500, range.getRangeStart(10000));
assertEquals(9999, range.getRangeEnd(10000));
}
@Test
public void byteRangeOfZeroLength() throws Exception {
public void byteRangeOfZeroLength() {
HttpRange range = HttpRange.createByteRange(9500, 9500);
assertEquals(9500, range.getRangeStart(10000));
assertEquals(9500, range.getRangeEnd(10000));
}
@Test
public void suffixRange() throws Exception {
public void suffixRange() {
HttpRange range = HttpRange.createSuffixRange(500);
assertEquals(500, range.getRangeStart(1000));
assertEquals(999, range.getRangeEnd(1000));
}
@Test
public void suffixRangeShorterThanRepresentation() throws Exception {
public void suffixRangeShorterThanRepresentation() {
HttpRange range = HttpRange.createSuffixRange(500);
assertEquals(0, range.getRangeStart(350));
assertEquals(349, range.getRangeEnd(350));
}
@Test
public void parseRanges() throws Exception {
public void parseRanges() {
List<HttpRange> ranges = HttpRange.parseRanges("bytes=0-0,500-,-1");
assertEquals(3, ranges.size());
assertEquals(0, ranges.get(0).getRangeStart(1000));
@ -137,8 +137,8 @@ public class HttpRangeTests { @@ -137,8 +137,8 @@ public class HttpRangeTests {
@Test(expected = IllegalArgumentException.class)
@SuppressWarnings("unchecked")
public void toResourceRegionExceptionLength() {
ByteArrayResource resource = mock(ByteArrayResource.class);
public void toResourceRegionExceptionLength() throws IOException {
InputStreamResource resource = mock(InputStreamResource.class);
given(resource.contentLength()).willThrow(IOException.class);
HttpRange range = HttpRange.createByteRange(0, 9);
range.toResourceRegion(resource);

4
spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java

@ -167,7 +167,6 @@ public class HttpMessageConverterExtractorTests { @@ -167,7 +167,6 @@ public class HttpMessageConverterExtractorTests {
given(converter.read(eq(type), eq(null), any(HttpInputMessage.class))).willReturn(expected);
Object result = extractor.extractData(response);
assertEquals(expected, result);
}
@ -182,7 +181,8 @@ public class HttpMessageConverterExtractorTests { @@ -182,7 +181,8 @@ public class HttpMessageConverterExtractorTests {
given(response.getRawStatusCode()).willReturn(HttpStatus.OK.value());
given(response.getHeaders()).willReturn(responseHeaders);
given(response.getBody()).willReturn(new ByteArrayInputStream("Foobar".getBytes()));
given(converter.canRead(String.class, contentType)).willThrow(IOException.class);
given(converter.canRead(String.class, contentType)).willReturn(true);
given(converter.read(eq(String.class), any(HttpInputMessage.class))).willThrow(IOException.class);
exception.expect(RestClientException.class);
exception.expectMessage("Error while extracting response for type " +
"[class java.lang.String] and content type [text/plain]");

Loading…
Cancel
Save