From 7e7504f5eaeae70a2d67fa1536bf1fc487fb9ef9 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 3 Nov 2016 23:20:33 +0100 Subject: [PATCH] Polishing --- .../DefaultListableBeanFactoryTests.java | 4 +- .../springframework/tests/MockitoUtils.java | 23 ++++---- .../xml/AbstractStaxXMLReaderTestCase.java | 52 +++++++++++-------- .../util/xml/StaxEventXMLReaderTests.java | 9 ++-- .../util/xml/StaxStreamXMLReaderTests.java | 9 ++-- ...mpAnnotationMethodMessageHandlerTests.java | 22 +++----- .../simp/stomp/DefaultStompSessionTests.java | 5 +- .../support/TestPropertySourceUtilsTests.java | 1 - .../DelegatingWebConnectionTests.java | 16 +++--- .../WebConnectionHtmlUnitDriverTests.java | 2 +- .../AsyncControllerJavaConfigTests.java | 9 ++-- .../ResourceHttpMessageConverterTests.java | 14 +++-- .../web/servlet/DispatcherServletTests.java | 1 - .../StompSubProtocolHandlerTests.java | 23 +++----- .../HttpSendingTransportHandlerTests.java | 12 ++--- .../transport/session/SockJsSessionTests.java | 25 +++------ 16 files changed, 98 insertions(+), 129 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java index 71689a6a8a6..17f35614c1b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java @@ -2200,7 +2200,7 @@ public class DefaultListableBeanFactoryTests { @Test public void testPrototypeWithArrayConversionForConstructor() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); - List list = new ManagedList(); + List list = new ManagedList<>(); list.add("myName"); list.add("myBeanName"); RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class); @@ -2219,7 +2219,7 @@ public class DefaultListableBeanFactoryTests { @Test public void testPrototypeWithArrayConversionForFactoryMethod() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); - List list = new ManagedList(); + List list = new ManagedList<>(); list.add("myName"); list.add("myBeanName"); RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class); diff --git a/spring-core/src/test/java/org/springframework/tests/MockitoUtils.java b/spring-core/src/test/java/org/springframework/tests/MockitoUtils.java index 9266f92e354..7f0d52c07ad 100644 --- a/spring-core/src/test/java/org/springframework/tests/MockitoUtils.java +++ b/spring-core/src/test/java/org/springframework/tests/MockitoUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 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. @@ -30,9 +30,10 @@ import static org.junit.Assert.*; * * @author Phillip Webb */ -public class MockitoUtils { +public abstract class MockitoUtils { + + private static final MockUtil mockUtil = new MockUtil(); - private static MockUtil mockUtil = new MockUtil(); /** * Verify the same invocations have been applied to two mocks. This is generally not @@ -48,16 +49,18 @@ public class MockitoUtils { verifySameInvocations(expectedInvocations, actualInvocations, argumentAdapters); } - private static void verifySameInvocations(List expectedInvocations, List actualInvocations, InvocationArgumentsAdapter... argumentAdapters) { + private static void verifySameInvocations(List expectedInvocations, List actualInvocations, + InvocationArgumentsAdapter... argumentAdapters) { + assertThat(expectedInvocations.size(), is(equalTo(actualInvocations.size()))); for (int i = 0; i < expectedInvocations.size(); i++) { verifySameInvocation(expectedInvocations.get(i), actualInvocations.get(i), argumentAdapters); } } - private static void verifySameInvocation(Invocation expectedInvocation, Invocation actualInvocation, InvocationArgumentsAdapter... argumentAdapters) { - System.out.println(expectedInvocation); - System.out.println(actualInvocation); + private static void verifySameInvocation(Invocation expectedInvocation, Invocation actualInvocation, + InvocationArgumentsAdapter... argumentAdapters) { + assertThat(expectedInvocation.getMethod(), is(equalTo(actualInvocation.getMethod()))); Object[] expectedArguments = getInvocationArguments(expectedInvocation, argumentAdapters); Object[] actualArguments = getInvocationArguments(actualInvocation, argumentAdapters); @@ -72,16 +75,18 @@ public class MockitoUtils { return arguments; } + /** * Adapter strategy that can be used to change invocation arguments. */ - public static interface InvocationArgumentsAdapter { + public interface InvocationArgumentsAdapter { /** - * Change the arguments if required + * Change the arguments if required. * @param arguments the source arguments * @return updated or original arguments (never {@code null}) */ Object[] adaptArguments(Object[] arguments); } + } diff --git a/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.java b/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.java index 41aa5f25a5f..ace21512ae0 100644 --- a/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.java +++ b/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -18,7 +18,6 @@ package org.springframework.util.xml; import java.io.ByteArrayInputStream; import java.io.InputStream; - import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.transform.Transformer; @@ -28,15 +27,8 @@ import javax.xml.transform.sax.SAXSource; import org.junit.Before; import org.junit.Test; - import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; - -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.tests.MockitoUtils; -import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter; - import org.w3c.dom.Node; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; @@ -47,6 +39,11 @@ import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.XMLReaderFactory; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.tests.MockitoUtils; +import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter; + import static org.junit.Assert.*; import static org.mockito.BDDMockito.*; @@ -58,6 +55,7 @@ public abstract class AbstractStaxXMLReaderTestCase { private ContentHandler standardContentHandler; + @Before public void setUp() throws Exception { inputFactory = XMLInputFactory.newInstance(); @@ -66,6 +64,7 @@ public abstract class AbstractStaxXMLReaderTestCase { standardReader.setContentHandler(standardContentHandler); } + @Test public void contentHandlerNamespacesNoPrefixes() throws Exception { standardReader.setFeature("http://xml.org/sax/features/namespaces", true); @@ -147,12 +146,8 @@ public abstract class AbstractStaxXMLReaderTestCase { inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE); LexicalHandler actualLexicalHandler = mockLexicalHandler(); - willAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - return invocation.getArguments()[0] = "element"; - } - }).given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString()); + willAnswer(invocation -> invocation.getArguments()[0] = "element"). + given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString()); AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(testLexicalHandlerXml.getInputStream()); staxXmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", actualLexicalHandler); staxXmlReader.parse(new InputSource()); @@ -160,6 +155,7 @@ public abstract class AbstractStaxXMLReaderTestCase { verifyIdenticalInvocations(expectedLexicalHandler, actualLexicalHandler); } + private LexicalHandler mockLexicalHandler() throws Exception { LexicalHandler lexicalHandler = mock(LexicalHandler.class); willAnswer(new CopyCharsAnswer()).given(lexicalHandler).comment(any(char[].class), anyInt(), anyInt()); @@ -170,8 +166,6 @@ public abstract class AbstractStaxXMLReaderTestCase { return getClass().getResourceAsStream("testContentHandler.xml"); } - protected abstract AbstractStaxXMLReader createStaxXmlReader(InputStream inputStream) throws XMLStreamException; - protected final ContentHandler mockContentHandler() throws Exception { ContentHandler contentHandler = mock(ContentHandler.class); willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt()); @@ -191,7 +185,11 @@ public abstract class AbstractStaxXMLReaderTestCase { new SkipLocatorArgumentsAdapter(), new CharArrayToStringAdapter(), new PartialAttributesAdapter()); } + protected abstract AbstractStaxXMLReader createStaxXmlReader(InputStream inputStream) throws XMLStreamException; + + private static class SkipLocatorArgumentsAdapter implements InvocationArgumentsAdapter { + @Override public Object[] adaptArguments(Object[] arguments) { for (int i = 0; i < arguments.length; i++) { @@ -203,7 +201,9 @@ public abstract class AbstractStaxXMLReaderTestCase { } } + private static class CharArrayToStringAdapter implements InvocationArgumentsAdapter { + @Override public Object[] adaptArguments(Object[] arguments) { if (arguments.length == 3 && arguments[0] instanceof char[] @@ -214,7 +214,9 @@ public abstract class AbstractStaxXMLReaderTestCase { } } + private static class PartialAttributesAdapter implements InvocationArgumentsAdapter { + @Override public Object[] adaptArguments(Object[] arguments) { for (int i = 0; i < arguments.length; i++) { @@ -226,7 +228,9 @@ public abstract class AbstractStaxXMLReaderTestCase { } } + private static class CopyCharsAnswer implements Answer { + @Override public Object answer(InvocationOnMock invocation) throws Throwable { char[] chars = (char[]) invocation.getArguments()[0]; @@ -237,19 +241,15 @@ public abstract class AbstractStaxXMLReaderTestCase { } } + private static class PartialAttributes { - private Attributes attributes; + private final Attributes attributes; public PartialAttributes(Attributes attributes) { this.attributes = attributes; } - @Override - public int hashCode() { - return 1; - } - @Override public boolean equals(Object obj) { Attributes other = ((PartialAttributes) obj).attributes; @@ -273,5 +273,11 @@ public abstract class AbstractStaxXMLReaderTestCase { } return true; } + + @Override + public int hashCode() { + return 1; + } } + } diff --git a/spring-core/src/test/java/org/springframework/util/xml/StaxEventXMLReaderTests.java b/spring-core/src/test/java/org/springframework/util/xml/StaxEventXMLReaderTests.java index 7db65b8ae4b..d33a6496bb5 100644 --- a/spring-core/src/test/java/org/springframework/util/xml/StaxEventXMLReaderTests.java +++ b/spring-core/src/test/java/org/springframework/util/xml/StaxEventXMLReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -18,18 +18,15 @@ package org.springframework.util.xml; import java.io.InputStream; import java.io.StringReader; - import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import org.junit.Test; - import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase { @@ -45,7 +42,7 @@ public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase { public void partial() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT)); - eventReader.nextTag(); // skip to root + eventReader.nextTag(); // skip to root StaxEventXMLReader xmlReader = new StaxEventXMLReader(eventReader); ContentHandler contentHandler = mock(ContentHandler.class); xmlReader.setContentHandler(contentHandler); @@ -55,5 +52,5 @@ public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase { verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child"); verify(contentHandler).endDocument(); } -} +} diff --git a/spring-core/src/test/java/org/springframework/util/xml/StaxStreamXMLReaderTests.java b/spring-core/src/test/java/org/springframework/util/xml/StaxStreamXMLReaderTests.java index b276a0eb6d2..af10b14e90f 100644 --- a/spring-core/src/test/java/org/springframework/util/xml/StaxStreamXMLReaderTests.java +++ b/spring-core/src/test/java/org/springframework/util/xml/StaxStreamXMLReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -18,21 +18,18 @@ package org.springframework.util.xml; import java.io.InputStream; import java.io.StringReader; - import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.junit.Test; - import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.Locator; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase { @@ -48,10 +45,10 @@ public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase { public void partial() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT)); - streamReader.nextTag(); // skip to root + streamReader.nextTag(); // skip to root assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "root"), streamReader.getName()); - streamReader.nextTag(); // skip to child + streamReader.nextTag(); // skip to child assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "child"), streamReader.getName()); StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java index ac5bca021ae..73a1d9be197 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -60,16 +60,10 @@ import org.springframework.validation.Errors; import org.springframework.validation.Validator; import org.springframework.validation.annotation.Validated; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.BDDMockito.given; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.verify; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.*; /** * Test fixture for @@ -367,7 +361,7 @@ public class SimpAnnotationMethodMessageHandlerTests { private String method; - private Map arguments = new LinkedHashMap(); + private Map arguments = new LinkedHashMap<>(); @MessageMapping("/headers") public void headers(@Header String foo, @Headers Map headers) { @@ -462,13 +456,13 @@ public class SimpAnnotationMethodMessageHandlerTests { @MessageMapping("success") public ListenableFutureTask handleListenableFuture() { - this.future = new ListenableFutureTask(() -> "foo"); + this.future = new ListenableFutureTask<>(() -> "foo"); return this.future; } @MessageMapping("failure") public ListenableFutureTask handleListenableFutureException() { - this.future = new ListenableFutureTask(() -> { + this.future = new ListenableFutureTask<>(() -> { throw new IllegalStateException(); }); return this.future; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/DefaultStompSessionTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/DefaultStompSessionTests.java index eb838dcf8b7..28b9ff044e5 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/DefaultStompSessionTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/DefaultStompSessionTests.java @@ -48,11 +48,8 @@ import org.springframework.util.concurrent.SettableListenableFuture; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.any; import static org.mockito.Mockito.*; -import static org.mockito.Mockito.notNull; -import static org.mockito.Mockito.same; /** * Unit tests for {@link DefaultStompSession}. diff --git a/spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java index b1d7ddfdbb1..08436aa3359 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java @@ -35,7 +35,6 @@ import org.springframework.test.context.TestPropertySource; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.startsWith; import static org.junit.Assert.*; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.*; import static org.springframework.test.context.support.TestPropertySourceUtils.*; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java index bf347eed50f..f9a7c777ca8 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java @@ -58,17 +58,24 @@ public class DelegatingWebConnectionTests { @Mock private WebRequestMatcher matcher1; + @Mock private WebRequestMatcher matcher2; + @Mock private WebConnection defaultConnection; + @Mock private WebConnection connection1; + @Mock private WebConnection connection2; + private DelegatingWebConnection webConnection; + private WebRequest request; + private WebResponse expectedResponse; @@ -78,13 +85,12 @@ public class DelegatingWebConnectionTests { WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections. emptyList()); expectedResponse = new WebResponse(data, request, 100L); webConnection = new DelegatingWebConnection(defaultConnection, - new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2)); + new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2)); } @Test public void getResponseDefault() throws Exception { when(defaultConnection.getResponse(request)).thenReturn(expectedResponse); - WebResponse response = webConnection.getResponse(request); assertThat(response, sameInstance(expectedResponse)); @@ -97,9 +103,7 @@ public class DelegatingWebConnectionTests { @Test public void getResponseAllMatches() throws Exception { when(matcher1.matches(request)).thenReturn(true); - when(matcher2.matches(request)).thenReturn(true); when(connection1.getResponse(request)).thenReturn(expectedResponse); - WebResponse response = webConnection.getResponse(request); assertThat(response, sameInstance(expectedResponse)); @@ -112,7 +116,6 @@ public class DelegatingWebConnectionTests { public void getResponseSecondMatches() throws Exception { when(matcher2.matches(request)).thenReturn(true); when(connection2.getResponse(request)).thenReturn(expectedResponse); - WebResponse response = webConnection.getResponse(request); assertThat(response, sameInstance(expectedResponse)); @@ -144,6 +147,7 @@ public class DelegatingWebConnectionTests { @Controller - static class TestController {} + static class TestController { + } } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/WebConnectionHtmlUnitDriverTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/WebConnectionHtmlUnitDriverTests.java index 5bed444fea3..bab8102a332 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/WebConnectionHtmlUnitDriverTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/WebConnectionHtmlUnitDriverTests.java @@ -29,7 +29,7 @@ import org.mockito.runners.MockitoJUnitRunner; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Matchers.any; +import static org.mockito.Mockito.any; import static org.mockito.Mockito.*; /** diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/AsyncControllerJavaConfigTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/AsyncControllerJavaConfigTests.java index 0613048d6c7..0fbc2fbec84 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/AsyncControllerJavaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/AsyncControllerJavaConfigTests.java @@ -23,7 +23,6 @@ import java.util.concurrent.Callable; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; - import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -45,12 +44,10 @@ import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; -import static org.mockito.Matchers.any; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.mockito.Matchers.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** * Tests with Java configuration. diff --git a/spring-web/src/test/java/org/springframework/http/converter/ResourceHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/ResourceHttpMessageConverterTests.java index d3a3d96fa6b..573744deff3 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/ResourceHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/ResourceHttpMessageConverterTests.java @@ -16,14 +16,6 @@ package org.springframework.http.converter; -import static org.hamcrest.core.Is.*; -import static org.hamcrest.core.IsInstanceOf.*; -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; - import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -40,6 +32,12 @@ import org.springframework.http.MockHttpInputMessage; import org.springframework.http.MockHttpOutputMessage; import org.springframework.util.FileCopyUtils; +import static org.hamcrest.core.Is.*; +import static org.hamcrest.core.IsInstanceOf.*; +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.any; +import static org.mockito.BDDMockito.*; + /** * @author Arjen Poutsma * @author Kazuki Shimizu diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java index 3c5f9632010..409d61cc73b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java @@ -61,7 +61,6 @@ import org.springframework.web.util.WebUtils; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; /** diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolHandlerTests.java index 1c388c08d0e..221bfb3f95b 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolHandlerTests.java @@ -56,21 +56,10 @@ import org.springframework.web.socket.WebSocketMessage; import org.springframework.web.socket.handler.TestWebSocketSession; import org.springframework.web.socket.sockjs.transport.SockJsSession; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.*; /** * Test fixture for {@link StompSubProtocolHandler} tests. @@ -502,7 +491,7 @@ public class StompSubProtocolHandlerTests { private static class TestPublisher implements ApplicationEventPublisher { - private final List events = new ArrayList(); + private final List events = new ArrayList<>(); @Override public void publishEvent(ApplicationEvent event) { @@ -511,7 +500,7 @@ public class StompSubProtocolHandlerTests { @Override public void publishEvent(Object event) { - publishEvent(new PayloadApplicationEvent(this, event)); + publishEvent(new PayloadApplicationEvent<>(this, event)); } } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java index 4191142998b..3b2501001e0 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java @@ -16,10 +16,11 @@ package org.springframework.web.socket.sockjs.transport.handler; -import java.sql.Date; +import java.util.Date; import org.junit.Before; import org.junit.Test; + import org.springframework.scheduling.TaskScheduler; import org.springframework.web.socket.AbstractHttpRequestTests; import org.springframework.web.socket.WebSocketHandler; @@ -32,13 +33,8 @@ import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSe import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig; import org.springframework.web.util.UriUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; /** * Test fixture for {@link AbstractHttpSendingTransportHandler} and sub-classes. diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/SockJsSessionTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/SockJsSessionTests.java index e09ff565c82..46433ce7715 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/SockJsSessionTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/SockJsSessionTests.java @@ -17,9 +17,8 @@ package org.springframework.web.socket.sockjs.transport.session; import java.io.IOException; -import java.sql.Date; -import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.concurrent.ScheduledFuture; import org.junit.Test; @@ -42,15 +41,14 @@ import static org.mockito.BDDMockito.*; */ public class SockJsSessionTests extends AbstractSockJsSessionTests { - @Override protected TestSockJsSession initSockJsSession() { return new TestSockJsSession("1", this.sockJsConfig, this.webSocketHandler, Collections.emptyMap()); } + @Test public void getTimeSinceLastActive() throws Exception { - Thread.sleep(1); long time1 = this.session.getTimeSinceLastActive(); @@ -91,7 +89,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTestsemptyMap()); + TestSockJsSession sockJsSession = new TestSockJsSession( + "1", this.sockJsConfig, wsHandler, Collections.emptyMap()); String msg1 = "message 1"; String msg2 = "message 2"; @@ -113,11 +110,11 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests task = mock(ScheduledFuture.class); willReturn(task).given(this.taskScheduler).schedule(any(Runnable.class), any(Date.class));