Skip to content

Commit 7e7504f

Browse files
committed
Polishing
1 parent e83c116 commit 7e7504f

File tree

16 files changed

+98
-129
lines changed

16 files changed

+98
-129
lines changed

spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ public void testPrototypeStringCreatedRepeatedly() {
22002200
@Test
22012201
public void testPrototypeWithArrayConversionForConstructor() {
22022202
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
2203-
List<String> list = new ManagedList<String>();
2203+
List<String> list = new ManagedList<>();
22042204
list.add("myName");
22052205
list.add("myBeanName");
22062206
RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
@@ -2219,7 +2219,7 @@ public void testPrototypeWithArrayConversionForConstructor() {
22192219
@Test
22202220
public void testPrototypeWithArrayConversionForFactoryMethod() {
22212221
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
2222-
List<String> list = new ManagedList<String>();
2222+
List<String> list = new ManagedList<>();
22232223
list.add("myName");
22242224
list.add("myBeanName");
22252225
RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -30,9 +30,10 @@
3030
*
3131
* @author Phillip Webb
3232
*/
33-
public class MockitoUtils {
33+
public abstract class MockitoUtils {
34+
35+
private static final MockUtil mockUtil = new MockUtil();
3436

35-
private static MockUtil mockUtil = new MockUtil();
3637

3738
/**
3839
* Verify the same invocations have been applied to two mocks. This is generally not
@@ -48,16 +49,18 @@ public static <T> void verifySameInvocations(T expected, T actual, InvocationArg
4849
verifySameInvocations(expectedInvocations, actualInvocations, argumentAdapters);
4950
}
5051

51-
private static void verifySameInvocations(List<Invocation> expectedInvocations, List<Invocation> actualInvocations, InvocationArgumentsAdapter... argumentAdapters) {
52+
private static void verifySameInvocations(List<Invocation> expectedInvocations, List<Invocation> actualInvocations,
53+
InvocationArgumentsAdapter... argumentAdapters) {
54+
5255
assertThat(expectedInvocations.size(), is(equalTo(actualInvocations.size())));
5356
for (int i = 0; i < expectedInvocations.size(); i++) {
5457
verifySameInvocation(expectedInvocations.get(i), actualInvocations.get(i), argumentAdapters);
5558
}
5659
}
5760

58-
private static void verifySameInvocation(Invocation expectedInvocation, Invocation actualInvocation, InvocationArgumentsAdapter... argumentAdapters) {
59-
System.out.println(expectedInvocation);
60-
System.out.println(actualInvocation);
61+
private static void verifySameInvocation(Invocation expectedInvocation, Invocation actualInvocation,
62+
InvocationArgumentsAdapter... argumentAdapters) {
63+
6164
assertThat(expectedInvocation.getMethod(), is(equalTo(actualInvocation.getMethod())));
6265
Object[] expectedArguments = getInvocationArguments(expectedInvocation, argumentAdapters);
6366
Object[] actualArguments = getInvocationArguments(actualInvocation, argumentAdapters);
@@ -72,16 +75,18 @@ private static Object[] getInvocationArguments(Invocation invocation, Invocation
7275
return arguments;
7376
}
7477

78+
7579
/**
7680
* Adapter strategy that can be used to change invocation arguments.
7781
*/
78-
public static interface InvocationArgumentsAdapter {
82+
public interface InvocationArgumentsAdapter {
7983

8084
/**
81-
* Change the arguments if required
85+
* Change the arguments if required.
8286
* @param arguments the source arguments
8387
* @return updated or original arguments (never {@code null})
8488
*/
8589
Object[] adaptArguments(Object[] arguments);
8690
}
91+
8792
}

spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -18,7 +18,6 @@
1818

1919
import java.io.ByteArrayInputStream;
2020
import java.io.InputStream;
21-
2221
import javax.xml.stream.XMLInputFactory;
2322
import javax.xml.stream.XMLStreamException;
2423
import javax.xml.transform.Transformer;
@@ -28,15 +27,8 @@
2827

2928
import org.junit.Before;
3029
import org.junit.Test;
31-
3230
import org.mockito.invocation.InvocationOnMock;
3331
import org.mockito.stubbing.Answer;
34-
35-
import org.springframework.core.io.ClassPathResource;
36-
import org.springframework.core.io.Resource;
37-
import org.springframework.tests.MockitoUtils;
38-
import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
39-
4032
import org.w3c.dom.Node;
4133
import org.xml.sax.Attributes;
4234
import org.xml.sax.ContentHandler;
@@ -47,6 +39,11 @@
4739
import org.xml.sax.helpers.AttributesImpl;
4840
import org.xml.sax.helpers.XMLReaderFactory;
4941

42+
import org.springframework.core.io.ClassPathResource;
43+
import org.springframework.core.io.Resource;
44+
import org.springframework.tests.MockitoUtils;
45+
import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
46+
5047
import static org.junit.Assert.*;
5148
import static org.mockito.BDDMockito.*;
5249

@@ -58,6 +55,7 @@ public abstract class AbstractStaxXMLReaderTestCase {
5855

5956
private ContentHandler standardContentHandler;
6057

58+
6159
@Before
6260
public void setUp() throws Exception {
6361
inputFactory = XMLInputFactory.newInstance();
@@ -66,6 +64,7 @@ public void setUp() throws Exception {
6664
standardReader.setContentHandler(standardContentHandler);
6765
}
6866

67+
6968
@Test
7069
public void contentHandlerNamespacesNoPrefixes() throws Exception {
7170
standardReader.setFeature("http://xml.org/sax/features/namespaces", true);
@@ -147,19 +146,16 @@ public void lexicalHandler() throws Exception {
147146
inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE);
148147

149148
LexicalHandler actualLexicalHandler = mockLexicalHandler();
150-
willAnswer(new Answer<Object>() {
151-
@Override
152-
public Object answer(InvocationOnMock invocation) throws Throwable {
153-
return invocation.getArguments()[0] = "element";
154-
}
155-
}).given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString());
149+
willAnswer(invocation -> invocation.getArguments()[0] = "element").
150+
given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString());
156151
AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(testLexicalHandlerXml.getInputStream());
157152
staxXmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", actualLexicalHandler);
158153
staxXmlReader.parse(new InputSource());
159154

160155
verifyIdenticalInvocations(expectedLexicalHandler, actualLexicalHandler);
161156
}
162157

158+
163159
private LexicalHandler mockLexicalHandler() throws Exception {
164160
LexicalHandler lexicalHandler = mock(LexicalHandler.class);
165161
willAnswer(new CopyCharsAnswer()).given(lexicalHandler).comment(any(char[].class), anyInt(), anyInt());
@@ -170,8 +166,6 @@ private InputStream createTestInputStream() {
170166
return getClass().getResourceAsStream("testContentHandler.xml");
171167
}
172168

173-
protected abstract AbstractStaxXMLReader createStaxXmlReader(InputStream inputStream) throws XMLStreamException;
174-
175169
protected final ContentHandler mockContentHandler() throws Exception {
176170
ContentHandler contentHandler = mock(ContentHandler.class);
177171
willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt());
@@ -191,7 +185,11 @@ protected <T> void verifyIdenticalInvocations(T expected, T actual) {
191185
new SkipLocatorArgumentsAdapter(), new CharArrayToStringAdapter(), new PartialAttributesAdapter());
192186
}
193187

188+
protected abstract AbstractStaxXMLReader createStaxXmlReader(InputStream inputStream) throws XMLStreamException;
189+
190+
194191
private static class SkipLocatorArgumentsAdapter implements InvocationArgumentsAdapter {
192+
195193
@Override
196194
public Object[] adaptArguments(Object[] arguments) {
197195
for (int i = 0; i < arguments.length; i++) {
@@ -203,7 +201,9 @@ public Object[] adaptArguments(Object[] arguments) {
203201
}
204202
}
205203

204+
206205
private static class CharArrayToStringAdapter implements InvocationArgumentsAdapter {
206+
207207
@Override
208208
public Object[] adaptArguments(Object[] arguments) {
209209
if (arguments.length == 3 && arguments[0] instanceof char[]
@@ -214,7 +214,9 @@ public Object[] adaptArguments(Object[] arguments) {
214214
}
215215
}
216216

217+
217218
private static class PartialAttributesAdapter implements InvocationArgumentsAdapter {
219+
218220
@Override
219221
public Object[] adaptArguments(Object[] arguments) {
220222
for (int i = 0; i < arguments.length; i++) {
@@ -226,7 +228,9 @@ public Object[] adaptArguments(Object[] arguments) {
226228
}
227229
}
228230

231+
229232
private static class CopyCharsAnswer implements Answer<Object> {
233+
230234
@Override
231235
public Object answer(InvocationOnMock invocation) throws Throwable {
232236
char[] chars = (char[]) invocation.getArguments()[0];
@@ -237,19 +241,15 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
237241
}
238242
}
239243

244+
240245
private static class PartialAttributes {
241246

242-
private Attributes attributes;
247+
private final Attributes attributes;
243248

244249
public PartialAttributes(Attributes attributes) {
245250
this.attributes = attributes;
246251
}
247252

248-
@Override
249-
public int hashCode() {
250-
return 1;
251-
}
252-
253253
@Override
254254
public boolean equals(Object obj) {
255255
Attributes other = ((PartialAttributes) obj).attributes;
@@ -273,5 +273,11 @@ public boolean equals(Object obj) {
273273
}
274274
return true;
275275
}
276+
277+
@Override
278+
public int hashCode() {
279+
return 1;
280+
}
276281
}
282+
277283
}

spring-core/src/test/java/org/springframework/util/xml/StaxEventXMLReaderTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -18,18 +18,15 @@
1818

1919
import java.io.InputStream;
2020
import java.io.StringReader;
21-
2221
import javax.xml.stream.XMLEventReader;
2322
import javax.xml.stream.XMLInputFactory;
2423
import javax.xml.stream.XMLStreamException;
2524

2625
import org.junit.Test;
27-
2826
import org.xml.sax.Attributes;
2927
import org.xml.sax.ContentHandler;
3028
import org.xml.sax.InputSource;
3129

32-
import static org.mockito.Matchers.*;
3330
import static org.mockito.Mockito.*;
3431

3532
public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {
@@ -45,7 +42,7 @@ protected AbstractStaxXMLReader createStaxXmlReader(InputStream inputStream) thr
4542
public void partial() throws Exception {
4643
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
4744
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
48-
eventReader.nextTag(); // skip to root
45+
eventReader.nextTag(); // skip to root
4946
StaxEventXMLReader xmlReader = new StaxEventXMLReader(eventReader);
5047
ContentHandler contentHandler = mock(ContentHandler.class);
5148
xmlReader.setContentHandler(contentHandler);
@@ -55,5 +52,5 @@ public void partial() throws Exception {
5552
verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child");
5653
verify(contentHandler).endDocument();
5754
}
58-
}
5955

56+
}

spring-core/src/test/java/org/springframework/util/xml/StaxStreamXMLReaderTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -18,21 +18,18 @@
1818

1919
import java.io.InputStream;
2020
import java.io.StringReader;
21-
2221
import javax.xml.namespace.QName;
2322
import javax.xml.stream.XMLInputFactory;
2423
import javax.xml.stream.XMLStreamException;
2524
import javax.xml.stream.XMLStreamReader;
2625

2726
import org.junit.Test;
28-
2927
import org.xml.sax.Attributes;
3028
import org.xml.sax.ContentHandler;
3129
import org.xml.sax.InputSource;
3230
import org.xml.sax.Locator;
3331

3432
import static org.junit.Assert.*;
35-
import static org.mockito.Matchers.*;
3633
import static org.mockito.Mockito.*;
3734

3835
public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase {
@@ -48,10 +45,10 @@ protected AbstractStaxXMLReader createStaxXmlReader(InputStream inputStream) thr
4845
public void partial() throws Exception {
4946
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
5047
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT));
51-
streamReader.nextTag(); // skip to root
48+
streamReader.nextTag(); // skip to root
5249
assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "root"),
5350
streamReader.getName());
54-
streamReader.nextTag(); // skip to child
51+
streamReader.nextTag(); // skip to child
5552
assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "child"),
5653
streamReader.getName());
5754
StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader);

spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -60,16 +60,10 @@
6060
import org.springframework.validation.Validator;
6161
import org.springframework.validation.annotation.Validated;
6262

63-
import static org.hamcrest.Matchers.is;
64-
import static org.junit.Assert.assertEquals;
65-
import static org.junit.Assert.assertNotNull;
66-
import static org.junit.Assert.assertNull;
67-
import static org.junit.Assert.assertThat;
68-
import static org.junit.Assert.assertTrue;
69-
import static org.mockito.BDDMockito.given;
70-
import static org.mockito.Matchers.any;
71-
import static org.mockito.Matchers.anyObject;
72-
import static org.mockito.Mockito.verify;
63+
import static org.hamcrest.Matchers.*;
64+
import static org.junit.Assert.*;
65+
import static org.mockito.BDDMockito.any;
66+
import static org.mockito.BDDMockito.*;
7367

7468
/**
7569
* Test fixture for
@@ -367,7 +361,7 @@ private static class TestController {
367361

368362
private String method;
369363

370-
private Map<String, Object> arguments = new LinkedHashMap<String, Object>();
364+
private Map<String, Object> arguments = new LinkedHashMap<>();
371365

372366
@MessageMapping("/headers")
373367
public void headers(@Header String foo, @Headers Map<String, Object> headers) {
@@ -462,13 +456,13 @@ private static class ListenableFutureController {
462456

463457
@MessageMapping("success")
464458
public ListenableFutureTask<String> handleListenableFuture() {
465-
this.future = new ListenableFutureTask<String>(() -> "foo");
459+
this.future = new ListenableFutureTask<>(() -> "foo");
466460
return this.future;
467461
}
468462

469463
@MessageMapping("failure")
470464
public ListenableFutureTask<String> handleListenableFutureException() {
471-
this.future = new ListenableFutureTask<String>(() -> {
465+
this.future = new ListenableFutureTask<>(() -> {
472466
throw new IllegalStateException();
473467
});
474468
return this.future;

spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/DefaultStompSessionTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@
4848

4949
import static org.hamcrest.Matchers.*;
5050
import static org.junit.Assert.*;
51-
import static org.mockito.Matchers.any;
52-
import static org.mockito.Mockito.eq;
51+
import static org.mockito.Mockito.any;
5352
import static org.mockito.Mockito.*;
54-
import static org.mockito.Mockito.notNull;
55-
import static org.mockito.Mockito.same;
5653

5754
/**
5855
* Unit tests for {@link DefaultStompSession}.

0 commit comments

Comments
 (0)