Merge pull request #11817 from dreis2211:replace-any-with-casts

* pr/11817:
  Replace casted Mockito.any() calls
pull/11818/merge
Stephane Nicoll 7 years ago
commit fac8970366

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -68,7 +68,7 @@ public class AuthenticationAuditListenerTests {
this.listener.onApplicationEvent(new InteractiveAuthenticationSuccessEvent( this.listener.onApplicationEvent(new InteractiveAuthenticationSuccessEvent(
new UsernamePasswordAuthenticationToken("user", "password"), getClass())); new UsernamePasswordAuthenticationToken("user", "password"), getClass()));
// No need to audit this one (it shadows a regular AuthenticationSuccessEvent) // No need to audit this one (it shadows a regular AuthenticationSuccessEvent)
verify(this.publisher, never()).publishEvent((ApplicationEvent) any()); verify(this.publisher, never()).publishEvent(any(ApplicationEvent.class));
} }
@Test @Test

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -178,8 +178,8 @@ public class RemoteClientConfigurationTests {
public Dispatcher dispatcher() throws IOException { public Dispatcher dispatcher() throws IOException {
Dispatcher dispatcher = mock(Dispatcher.class); Dispatcher dispatcher = mock(Dispatcher.class);
ServerHttpRequest anyRequest = (ServerHttpRequest) any(); ServerHttpRequest anyRequest = any(ServerHttpRequest.class);
ServerHttpResponse anyResponse = (ServerHttpResponse) any(); ServerHttpResponse anyResponse = any(ServerHttpResponse.class);
given(dispatcher.handle(anyRequest, anyResponse)).willReturn(true); given(dispatcher.handle(anyRequest, anyResponse)).willReturn(true);
return dispatcher; return dispatcher;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -60,7 +60,7 @@ public class MockRestarter implements TestRule {
private void setup() { private void setup() {
Restarter.setInstance(this.mock); Restarter.setInstance(this.mock);
given(this.mock.getInitialUrls()).willReturn(new URL[] {}); given(this.mock.getInitialUrls()).willReturn(new URL[] {});
given(this.mock.getOrAddAttribute(anyString(), (ObjectFactory) any())) given(this.mock.getOrAddAttribute(anyString(), any(ObjectFactory.class)))
.willAnswer((invocation) -> { .willAnswer((invocation) -> {
String name = (String) invocation.getArguments()[0]; String name = (String) invocation.getArguments()[0];
ObjectFactory factory = (ObjectFactory) invocation.getArguments()[1]; ObjectFactory factory = (ObjectFactory) invocation.getArguments()[1];

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -78,7 +78,7 @@ public class OnInitializedRestarterConditionTests {
public static void main(String... args) { public static void main(String... args) {
RestartInitializer initializer = mock(RestartInitializer.class); RestartInitializer initializer = mock(RestartInitializer.class);
given(initializer.getInitialUrls((Thread) any())).willReturn(new URL[0]); given(initializer.getInitialUrls(any(Thread.class))).willReturn(new URL[0]);
Restarter.initialize(new String[0], false, initializer); Restarter.initialize(new String[0], false, initializer);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
Config.class); Config.class);

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -74,7 +74,7 @@ public class MockitoTestExecutionListenerTests {
WithMockBean instance = new WithMockBean(); WithMockBean instance = new WithMockBean();
this.listener.prepareTestInstance(mockTestContext(instance)); this.listener.prepareTestInstance(mockTestContext(instance));
verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance), verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance),
(MockDefinition) any()); any(MockDefinition.class));
assertThat(this.fieldCaptor.getValue().getName()).isEqualTo("mockBean"); assertThat(this.fieldCaptor.getValue().getName()).isEqualTo("mockBean");
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -118,7 +118,7 @@ public class RootUriRequestExpectationManagerTests {
throws Exception { throws Exception {
ClientHttpRequest request = mock(ClientHttpRequest.class); ClientHttpRequest request = mock(ClientHttpRequest.class);
given(request.getURI()).willReturn(new URI(this.uri + "/hello")); given(request.getURI()).willReturn(new URI(this.uri + "/hello"));
given(this.delegate.validateRequest((ClientHttpRequest) any())) given(this.delegate.validateRequest(any(ClientHttpRequest.class)))
.willThrow(new AssertionError( .willThrow(new AssertionError(
"Request URI expected:</hello> was:<http://example.com/bad>")); "Request URI expected:</hello> was:<http://example.com/bad>"));
this.thrown.expect(AssertionError.class); this.thrown.expect(AssertionError.class);

@ -336,7 +336,7 @@ public class TestRestTemplateTests {
request.setResponse(new MockClientHttpResponse(new byte[0], HttpStatus.OK)); request.setResponse(new MockClientHttpResponse(new byte[0], HttpStatus.OK));
URI absoluteUri = URI URI absoluteUri = URI
.create("http://localhost:8080/a/b/c.txt?param=%7Bsomething%7D"); .create("http://localhost:8080/a/b/c.txt?param=%7Bsomething%7D");
given(requestFactory.createRequest(eq(absoluteUri), (HttpMethod) any())) given(requestFactory.createRequest(eq(absoluteUri), any(HttpMethod.class)))
.willReturn(request); .willReturn(request);
RestTemplate delegate = new RestTemplate(); RestTemplate delegate = new RestTemplate();
TestRestTemplate template = new TestRestTemplate(delegate); TestRestTemplate template = new TestRestTemplate(delegate);
@ -346,7 +346,7 @@ public class TestRestTemplateTests {
template.setUriTemplateHandler(uriTemplateHandler); template.setUriTemplateHandler(uriTemplateHandler);
callback.doWithTestRestTemplate(template, callback.doWithTestRestTemplate(template,
URI.create("/a/b/c.txt?param=%7Bsomething%7D")); URI.create("/a/b/c.txt?param=%7Bsomething%7D"));
verify(requestFactory).createRequest(eq(absoluteUri), (HttpMethod) any()); verify(requestFactory).createRequest(eq(absoluteUri), any(HttpMethod.class));
} }
private void assertBasicAuthorizationInterceptorCredentials( private void assertBasicAuthorizationInterceptorCredentials(

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -66,7 +66,7 @@ public abstract class MockServletWebServer {
private void initialize() { private void initialize() {
try { try {
this.servletContext = mock(ServletContext.class); this.servletContext = mock(ServletContext.class);
given(this.servletContext.addServlet(anyString(), (Servlet) any())) given(this.servletContext.addServlet(anyString(), any(Servlet.class)))
.willAnswer((invocation) -> { .willAnswer((invocation) -> {
RegisteredServlet registeredServlet = new RegisteredServlet( RegisteredServlet registeredServlet = new RegisteredServlet(
(Servlet) invocation.getArguments()[1]); (Servlet) invocation.getArguments()[1]);
@ -74,7 +74,7 @@ public abstract class MockServletWebServer {
.add(registeredServlet); .add(registeredServlet);
return registeredServlet.getRegistration(); return registeredServlet.getRegistration();
}); });
given(this.servletContext.addFilter(anyString(), (Filter) any())) given(this.servletContext.addFilter(anyString(), any(Filter.class)))
.willAnswer((invocation) -> { .willAnswer((invocation) -> {
RegisteredFilter registeredFilter = new RegisteredFilter( RegisteredFilter registeredFilter = new RegisteredFilter(
(Filter) invocation.getArguments()[1]); (Filter) invocation.getArguments()[1]);

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ public class ConcurrentReferenceCachingMetadataReaderFactoryTests {
MetadataReader metadataReader1 = factory.getMetadataReader(getClass().getName()); MetadataReader metadataReader1 = factory.getMetadataReader(getClass().getName());
MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName()); MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName());
assertThat(metadataReader1).isSameAs(metadataReader2); assertThat(metadataReader1).isSameAs(metadataReader2);
verify(factory, times(1)).createMetadataReader((Resource) any()); verify(factory, times(1)).createMetadataReader(any(Resource.class));
} }
@Test @Test
@ -54,7 +54,7 @@ public class ConcurrentReferenceCachingMetadataReaderFactoryTests {
factory.clearCache(); factory.clearCache();
MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName()); MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName());
assertThat(metadataReader1).isNotEqualTo(sameInstance(metadataReader2)); assertThat(metadataReader1).isNotEqualTo(sameInstance(metadataReader2));
verify(factory, times(2)).createMetadataReader((Resource) any()); verify(factory, times(2)).createMetadataReader(any(Resource.class));
} }
private static class TestConcurrentReferenceCachingMetadataReaderFactory private static class TestConcurrentReferenceCachingMetadataReaderFactory

@ -350,7 +350,7 @@ public class RestTemplateBuilderTests {
public void customizersShouldBeAppliedLast() { public void customizersShouldBeAppliedLast() {
RestTemplate template = spy(new RestTemplate()); RestTemplate template = spy(new RestTemplate());
this.builder.additionalCustomizers((restTemplate) -> verify(restTemplate) this.builder.additionalCustomizers((restTemplate) -> verify(restTemplate)
.setRequestFactory((ClientHttpRequestFactory) any())); .setRequestFactory(any(ClientHttpRequestFactory.class)));
this.builder.configure(template); this.builder.configure(template);
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ public class RootUriTemplateHandlerTests {
this.uri = new URI("http://example.com/hello"); this.uri = new URI("http://example.com/hello");
this.handler = new RootUriTemplateHandler("http://example.com", this.delegate); this.handler = new RootUriTemplateHandler("http://example.com", this.delegate);
given(this.delegate.expand(anyString(), any(Map.class))).willReturn(this.uri); given(this.delegate.expand(anyString(), any(Map.class))).willReturn(this.uri);
given(this.delegate.expand(anyString(), (Object[]) any())).willReturn(this.uri); given(this.delegate.expand(anyString(), any(Object[].class))).willReturn(this.uri);
} }
@Test @Test

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -106,7 +106,7 @@ public class UndertowServletWebServerFactoryTests
this.webServer = factory.getWebServer(); this.webServer = factory.getWebServer();
InOrder ordered = inOrder((Object[]) customizers); InOrder ordered = inOrder((Object[]) customizers);
for (UndertowBuilderCustomizer customizer : customizers) { for (UndertowBuilderCustomizer customizer : customizers) {
ordered.verify(customizer).customize((Builder) any()); ordered.verify(customizer).customize(any(Builder.class));
} }
} }
@ -139,7 +139,7 @@ public class UndertowServletWebServerFactoryTests
this.webServer = factory.getWebServer(); this.webServer = factory.getWebServer();
InOrder ordered = inOrder((Object[]) customizers); InOrder ordered = inOrder((Object[]) customizers);
for (UndertowDeploymentInfoCustomizer customizer : customizers) { for (UndertowDeploymentInfoCustomizer customizer : customizers) {
ordered.verify(customizer).customize((DeploymentInfo) any()); ordered.verify(customizer).customize(any(DeploymentInfo.class));
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
@Before @Before
public void setupMocks() { public void setupMocks() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
given(this.servletContext.addFilter(anyString(), (Filter) any())) given(this.servletContext.addFilter(anyString(), any(Filter.class)))
.willReturn(this.registration); .willReturn(this.registration);
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -68,9 +68,9 @@ public class ServletRegistrationBeanTests {
@Before @Before
public void setupMocks() { public void setupMocks() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
given(this.servletContext.addServlet(anyString(), (Servlet) any())) given(this.servletContext.addServlet(anyString(), any(Servlet.class)))
.willReturn(this.registration); .willReturn(this.registration);
given(this.servletContext.addFilter(anyString(), (Filter) any())) given(this.servletContext.addFilter(anyString(), any(Filter.class)))
.willReturn(this.filterRegistration); .willReturn(this.filterRegistration);
} }
@ -88,7 +88,7 @@ public class ServletRegistrationBeanTests {
public void startupWithDoubleRegistration() throws Exception { public void startupWithDoubleRegistration() throws Exception {
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<>( ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<>(
this.servlet); this.servlet);
given(this.servletContext.addServlet(anyString(), (Servlet) any())) given(this.servletContext.addServlet(anyString(), any(Servlet.class)))
.willReturn(null); .willReturn(null);
bean.onStartup(this.servletContext); bean.onStartup(this.servletContext);
verify(this.servletContext).addServlet("mockServlet", this.servlet); verify(this.servletContext).addServlet("mockServlet", this.servlet);
@ -207,7 +207,7 @@ public class ServletRegistrationBeanTests {
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<>( ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<>(
this.servlet, false); this.servlet, false);
bean.onStartup(this.servletContext); bean.onStartup(this.servletContext);
verify(this.registration, never()).addMapping((String[]) any()); verify(this.registration, never()).addMapping(any(String[].class));
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -371,8 +371,8 @@ public class ServletWebServerApplicationContextTests {
this.context.refresh(); this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext(); ServletContext servletContext = getWebServerFactory().getServletContext();
verify(initializer).onStartup(servletContext); verify(initializer).onStartup(servletContext);
verify(servletContext).addServlet(anyString(), (Servlet) any()); verify(servletContext).addServlet(anyString(), any(Servlet.class));
verify(servletContext).addFilter(anyString(), (Filter) any()); verify(servletContext).addFilter(anyString(), any(Filter.class));
} }
@Test @Test
@ -388,8 +388,8 @@ public class ServletWebServerApplicationContextTests {
this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
this.context.refresh(); this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext(); ServletContext servletContext = getWebServerFactory().getServletContext();
verify(servletContext, atMost(1)).addServlet(anyString(), (Servlet) any()); verify(servletContext, atMost(1)).addServlet(anyString(), any(Servlet.class));
verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) any()); verify(servletContext, atMost(1)).addFilter(anyString(), any(Filter.class));
} }
@Test @Test
@ -402,7 +402,7 @@ public class ServletWebServerApplicationContextTests {
this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
this.context.refresh(); this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext(); ServletContext servletContext = getWebServerFactory().getServletContext();
verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) any()); verify(servletContext, atMost(1)).addFilter(anyString(), any(Filter.class));
} }
@Test @Test

@ -313,7 +313,7 @@ public abstract class AbstractServletWebServerFactoryTests {
this.webServer.start(); this.webServer.start();
InOrder ordered = inOrder((Object[]) initializers); InOrder ordered = inOrder((Object[]) initializers);
for (ServletContextInitializer initializer : initializers) { for (ServletContextInitializer initializer : initializers) {
ordered.verify(initializer).onStartup((ServletContext) any()); ordered.verify(initializer).onStartup(any(ServletContext.class));
} }
} }

Loading…
Cancel
Save