Consistent Class array vs vararg declarations (and related polishing)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -80,7 +80,7 @@ public class SimpleMappingExceptionResolverTests {
|
||||
@Test
|
||||
public void defaultErrorViewDifferentHandlerClass() {
|
||||
exceptionResolver.setDefaultErrorView("default-view");
|
||||
exceptionResolver.setMappedHandlerClasses(new Class[] {String.class});
|
||||
exceptionResolver.setMappedHandlerClasses(String.class);
|
||||
ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException);
|
||||
assertNull(mav);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ public class SimpleMappingExceptionResolverTests {
|
||||
public void exactExceptionMappingWithHandlerClassSpecified() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("java.lang.Exception", "error");
|
||||
exceptionResolver.setMappedHandlerClasses(new Class[] {String.class});
|
||||
exceptionResolver.setMappedHandlerClasses(String.class);
|
||||
exceptionResolver.setExceptionMappings(props);
|
||||
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
|
||||
assertEquals("error", mav.getViewName());
|
||||
@@ -171,7 +171,7 @@ public class SimpleMappingExceptionResolverTests {
|
||||
public void exactExceptionMappingWithHandlerInterfaceSpecified() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("java.lang.Exception", "error");
|
||||
exceptionResolver.setMappedHandlerClasses(new Class[] {Comparable.class});
|
||||
exceptionResolver.setMappedHandlerClasses(Comparable.class);
|
||||
exceptionResolver.setExceptionMappings(props);
|
||||
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
|
||||
assertEquals("error", mav.getViewName());
|
||||
@@ -191,7 +191,7 @@ public class SimpleMappingExceptionResolverTests {
|
||||
public void simpleExceptionMappingWithHandlerClassSpecifiedButWrongHandler() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("Exception", "error");
|
||||
exceptionResolver.setMappedHandlerClasses(new Class[] {String.class});
|
||||
exceptionResolver.setMappedHandlerClasses(String.class);
|
||||
exceptionResolver.setExceptionMappings(props);
|
||||
ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException);
|
||||
assertNull(mav);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -16,11 +16,9 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -44,6 +42,9 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.method.ControllerAdviceBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestResponseBodyAdviceChain}.
|
||||
*
|
||||
@@ -80,7 +81,6 @@ public class RequestResponseBodyAdviceChainTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void requestBodyAdvice() throws IOException {
|
||||
|
||||
RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class);
|
||||
ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
|
||||
List<Object> advice = Arrays.asList(requestAdvice, responseAdvice);
|
||||
@@ -104,7 +104,6 @@ public class RequestResponseBodyAdviceChainTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void responseBodyAdvice() {
|
||||
|
||||
RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class);
|
||||
ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
|
||||
List<Object> advice = Arrays.asList(requestAdvice, responseAdvice);
|
||||
@@ -123,9 +122,8 @@ public class RequestResponseBodyAdviceChainTests {
|
||||
|
||||
@Test
|
||||
public void controllerAdvice() {
|
||||
|
||||
Object adviceBean = new ControllerAdviceBean(new MyControllerAdvice());
|
||||
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(Arrays.asList(adviceBean));
|
||||
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(Collections.singletonList(adviceBean));
|
||||
|
||||
String actual = (String) chain.beforeBodyWrite(this.body, this.returnType, this.contentType,
|
||||
this.converterType, this.request, this.response);
|
||||
@@ -135,9 +133,8 @@ public class RequestResponseBodyAdviceChainTests {
|
||||
|
||||
@Test
|
||||
public void controllerAdviceNotApplicable() {
|
||||
|
||||
Object adviceBean = new ControllerAdviceBean(new TargetedControllerAdvice());
|
||||
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(Arrays.asList(adviceBean));
|
||||
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(Collections.singletonList(adviceBean));
|
||||
|
||||
String actual = (String) chain.beforeBodyWrite(this.body, this.returnType, this.contentType,
|
||||
this.converterType, this.request, this.response);
|
||||
@@ -164,6 +161,7 @@ public class RequestResponseBodyAdviceChainTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ControllerAdvice(annotations = Controller.class)
|
||||
private static class TargetedControllerAdvice implements ResponseBodyAdvice<String> {
|
||||
|
||||
@@ -182,6 +180,7 @@ public class RequestResponseBodyAdviceChainTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ResponseBody
|
||||
public String handle(String body) {
|
||||
|
||||
Reference in New Issue
Block a user