Skip to content

Commit 996d747

Browse files
committed
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
1 parent a37fce8 commit 996d747

File tree

8 files changed

+27
-24
lines changed

8 files changed

+27
-24
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ configure(allprojects) { project ->
4242
version = qualifyVersionIfNecessary(version)
4343

4444
ext.aspectjVersion = "1.8.12"
45-
ext.freemarkerVersion = "2.3.26-incubating"
45+
ext.freemarkerVersion = "2.3.27-incubating"
4646
ext.groovyVersion = "2.4.12"
4747
ext.hsqldbVersion = "2.4.0"
4848
ext.jackson2Version = "2.9.2"
@@ -132,7 +132,7 @@ configure(allprojects) { project ->
132132
testCompile("junit:junit:4.12") {
133133
exclude group:'org.hamcrest', module:'hamcrest-core'
134134
}
135-
testCompile("org.mockito:mockito-core:2.6.1") {
135+
testCompile("org.mockito:mockito-core:2.11.0") {
136136
exclude group:'org.hamcrest', module:'hamcrest-core'
137137
}
138138
testCompile("com.nhaarman:mockito-kotlin:1.5.0") {

spring-aop/spring-aop.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ dependencies {
44
compile(project(":spring-beans"))
55
compile(project(':spring-core'))
66
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
7-
optional("org.apache.commons:commons-pool2:2.4.2")
7+
optional("org.apache.commons:commons-pool2:2.4.3")
88
optional("com.jamonapi:jamon:2.81")
99
}

spring-context/spring-context.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies {
2323
optional("org.hibernate:hibernate-validator:5.4.2.Final")
2424
optional("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
2525
optional("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}")
26-
testCompile("org.apache.commons:commons-pool2:2.4.2")
26+
testCompile("org.apache.commons:commons-pool2:2.4.3")
2727
testCompile("org.slf4j:slf4j-api:${slf4jVersion}")
2828
testCompile("javax.inject:javax.inject-tck:1")
2929
testRuntime("javax.xml.bind:jaxb-api:2.3.0")

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public class ByteArrayResource extends AbstractResource {
4848

4949

5050
/**
51-
* Create a new ByteArrayResource.
51+
* Create a new {@code ByteArrayResource}.
5252
* @param byteArray the byte array to wrap
5353
*/
5454
public ByteArrayResource(byte[] byteArray) {
5555
this(byteArray, "resource loaded from byte array");
5656
}
5757

5858
/**
59-
* Create a new ByteArrayResource.
59+
* Create a new {@code ByteArrayResource} with a description.
6060
* @param byteArray the byte array to wrap
6161
* @param description where the byte array comes from
6262
*/
@@ -66,14 +66,14 @@ public ByteArrayResource(byte[] byteArray, @Nullable String description) {
6666
this.description = (description != null ? description : "");
6767
}
6868

69+
6970
/**
7071
* Return the underlying byte array.
7172
*/
7273
public final byte[] getByteArray() {
7374
return this.byteArray;
7475
}
7576

76-
7777
/**
7878
* This implementation always returns {@code true}.
7979
*/

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020

2121
import org.mockito.Mockito;
22+
import org.mockito.internal.stubbing.InvocationContainerImpl;
2223
import org.mockito.internal.util.MockUtil;
2324
import org.mockito.invocation.Invocation;
2425

@@ -40,8 +41,10 @@ public abstract class MockitoUtils {
4041
* @param argumentAdapters adapters that can be used to change argument values before they are compared
4142
*/
4243
public static <T> void verifySameInvocations(T expected, T actual, InvocationArgumentsAdapter... argumentAdapters) {
43-
List<Invocation> expectedInvocations = MockUtil.getMockHandler(expected).getInvocationContainer().getInvocations();
44-
List<Invocation> actualInvocations = MockUtil.getMockHandler(actual).getInvocationContainer().getInvocations();
44+
List<Invocation> expectedInvocations =
45+
((InvocationContainerImpl) MockUtil.getMockHandler(expected).getInvocationContainer()).getInvocations();
46+
List<Invocation> actualInvocations =
47+
((InvocationContainerImpl) MockUtil.getMockHandler(actual).getInvocationContainer()).getInvocations();
4548
verifySameInvocations(expectedInvocations, actualInvocations, argumentAdapters);
4649
}
4750

spring-web/spring-web.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ dependencies {
8787
testRuntime("com.sun.mail:javax.mail:1.6.0")
8888
testRuntime("com.sun.xml.bind:jaxb-core:2.3.0")
8989
testRuntime("com.sun.xml.bind:jaxb-impl:2.3.0")
90-
testRuntime("javax.json:javax.json-api:1.1")
90+
testRuntime("javax.json:javax.json-api:1.1.2")
9191
testRuntime("org.apache.johnzon:johnzon-jsonb:1.1.4")
9292
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,57 +39,57 @@
3939
public class HttpRangeTests {
4040

4141
@Test(expected = IllegalArgumentException.class)
42-
public void invalidFirstPosition() throws Exception {
42+
public void invalidFirstPosition() {
4343
HttpRange.createByteRange(-1);
4444
}
4545

4646
@Test(expected = IllegalArgumentException.class)
47-
public void invalidLastLessThanFirst() throws Exception {
47+
public void invalidLastLessThanFirst() {
4848
HttpRange.createByteRange(10, 9);
4949
}
5050

5151
@Test(expected = IllegalArgumentException.class)
52-
public void invalidSuffixLength() throws Exception {
52+
public void invalidSuffixLength() {
5353
HttpRange.createSuffixRange(-1);
5454
}
5555

5656
@Test
57-
public void byteRange() throws Exception {
57+
public void byteRange() {
5858
HttpRange range = HttpRange.createByteRange(0, 499);
5959
assertEquals(0, range.getRangeStart(1000));
6060
assertEquals(499, range.getRangeEnd(1000));
6161
}
6262

6363
@Test
64-
public void byteRangeWithoutLastPosition() throws Exception {
64+
public void byteRangeWithoutLastPosition() {
6565
HttpRange range = HttpRange.createByteRange(9500);
6666
assertEquals(9500, range.getRangeStart(10000));
6767
assertEquals(9999, range.getRangeEnd(10000));
6868
}
6969

7070
@Test
71-
public void byteRangeOfZeroLength() throws Exception {
71+
public void byteRangeOfZeroLength() {
7272
HttpRange range = HttpRange.createByteRange(9500, 9500);
7373
assertEquals(9500, range.getRangeStart(10000));
7474
assertEquals(9500, range.getRangeEnd(10000));
7575
}
7676

7777
@Test
78-
public void suffixRange() throws Exception {
78+
public void suffixRange() {
7979
HttpRange range = HttpRange.createSuffixRange(500);
8080
assertEquals(500, range.getRangeStart(1000));
8181
assertEquals(999, range.getRangeEnd(1000));
8282
}
8383

8484
@Test
85-
public void suffixRangeShorterThanRepresentation() throws Exception {
85+
public void suffixRangeShorterThanRepresentation() {
8686
HttpRange range = HttpRange.createSuffixRange(500);
8787
assertEquals(0, range.getRangeStart(350));
8888
assertEquals(349, range.getRangeEnd(350));
8989
}
9090

9191
@Test
92-
public void parseRanges() throws Exception {
92+
public void parseRanges() {
9393
List<HttpRange> ranges = HttpRange.parseRanges("bytes=0-0,500-,-1");
9494
assertEquals(3, ranges.size());
9595
assertEquals(0, ranges.get(0).getRangeStart(1000));
@@ -137,8 +137,8 @@ public void toResourceRegionIllegalLength() {
137137

138138
@Test(expected = IllegalArgumentException.class)
139139
@SuppressWarnings("unchecked")
140-
public void toResourceRegionExceptionLength() {
141-
ByteArrayResource resource = mock(ByteArrayResource.class);
140+
public void toResourceRegionExceptionLength() throws IOException {
141+
InputStreamResource resource = mock(InputStreamResource.class);
142142
given(resource.contentLength()).willThrow(IOException.class);
143143
HttpRange range = HttpRange.createByteRange(0, 9);
144144
range.toResourceRegion(resource);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ public void generics() throws IOException {
167167
given(converter.read(eq(type), eq(null), any(HttpInputMessage.class))).willReturn(expected);
168168

169169
Object result = extractor.extractData(response);
170-
171170
assertEquals(expected, result);
172171
}
173172

@@ -182,7 +181,8 @@ public void converterThrowsIOException() throws IOException {
182181
given(response.getRawStatusCode()).willReturn(HttpStatus.OK.value());
183182
given(response.getHeaders()).willReturn(responseHeaders);
184183
given(response.getBody()).willReturn(new ByteArrayInputStream("Foobar".getBytes()));
185-
given(converter.canRead(String.class, contentType)).willThrow(IOException.class);
184+
given(converter.canRead(String.class, contentType)).willReturn(true);
185+
given(converter.read(eq(String.class), any(HttpInputMessage.class))).willThrow(IOException.class);
186186
exception.expect(RestClientException.class);
187187
exception.expectMessage("Error while extracting response for type " +
188188
"[class java.lang.String] and content type [text/plain]");

0 commit comments

Comments
 (0)