Revisit Assert to avoid single-arg assert methods (with refined messages)
Issue: SPR-15196
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -41,10 +41,10 @@ import static org.junit.Assert.fail;
|
||||
public class HttpHandlerAdapterSupportTests {
|
||||
|
||||
@Test
|
||||
public void invalidContextPath() throws Exception {
|
||||
testInvalidContextPath(" ", "contextPath must not be empty");
|
||||
testInvalidContextPath("path", "contextPath must begin with '/'");
|
||||
testInvalidContextPath("/path/", "contextPath must not end with '/'");
|
||||
public void invalidContextPath() {
|
||||
testInvalidContextPath(" ", "Context path must not be empty");
|
||||
testInvalidContextPath("path", "Context path must begin with '/'");
|
||||
testInvalidContextPath("/path/", "Context path must not end with '/'");
|
||||
}
|
||||
|
||||
private void testInvalidContextPath(String contextPath, String errorMessage) {
|
||||
@@ -58,7 +58,7 @@ public class HttpHandlerAdapterSupportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void match() throws Exception {
|
||||
public void match() {
|
||||
TestHttpHandler handler1 = new TestHttpHandler();
|
||||
TestHttpHandler handler2 = new TestHttpHandler();
|
||||
TestHttpHandler handler3 = new TestHttpHandler();
|
||||
@@ -75,7 +75,7 @@ public class HttpHandlerAdapterSupportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWithContextPathEqualToPath() throws Exception {
|
||||
public void matchWithContextPathEqualToPath() {
|
||||
TestHttpHandler handler1 = new TestHttpHandler();
|
||||
TestHttpHandler handler2 = new TestHttpHandler();
|
||||
TestHttpHandler handler3 = new TestHttpHandler();
|
||||
@@ -92,7 +92,7 @@ public class HttpHandlerAdapterSupportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWithNativeContextPath() throws Exception {
|
||||
public void matchWithNativeContextPath() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest
|
||||
.get("/yet/another/path")
|
||||
.contextPath("/yet") // contextPath in underlying request
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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,12 +80,12 @@ public abstract class AbstractHttpServer implements HttpServer {
|
||||
|
||||
@Override
|
||||
public final void afterPropertiesSet() throws Exception {
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
Assert.isTrue(this.host != null);
|
||||
Assert.isTrue(this.port != -1);
|
||||
Assert.isTrue(this.httpHandler != null || this.handlerMap != null);
|
||||
Assert.isTrue(!this.running);
|
||||
Assert.notNull(this.host, "Host must not be null");
|
||||
Assert.isTrue(this.port >= 0, "Port must not be a negative number");
|
||||
Assert.isTrue(this.httpHandler != null || this.handlerMap != null, "No HttpHandler configured");
|
||||
Assert.state(!this.running, "Cannot reconfigure while running");
|
||||
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
initServer();
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public abstract class AbstractHttpServer implements HttpServer {
|
||||
try {
|
||||
startInternal();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public abstract class AbstractHttpServer implements HttpServer {
|
||||
try {
|
||||
stopInternal();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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,7 +16,6 @@
|
||||
|
||||
package org.springframework.http.server.reactive.bootstrap;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -43,7 +43,7 @@ public class TomcatHttpServer extends AbstractHttpServer {
|
||||
}
|
||||
|
||||
public TomcatHttpServer(String baseDir, Class<?> wsListener) {
|
||||
Assert.notNull(baseDir);
|
||||
Assert.notNull(baseDir, "Base dir must not be null");
|
||||
this.baseDir = baseDir;
|
||||
this.wsListener = wsListener;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -61,7 +61,7 @@ public class MockAsyncContext implements AsyncContext {
|
||||
|
||||
|
||||
public void addDispatchHandler(Runnable handler) {
|
||||
Assert.notNull(handler);
|
||||
Assert.notNull(handler, "Dispatch handler must not be null");
|
||||
this.dispatchHandlers.add(handler);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class MockAsyncContext implements AsyncContext {
|
||||
|
||||
@Override
|
||||
public boolean hasOriginalRequestAndResponse() {
|
||||
return (this.request instanceof MockHttpServletRequest) && (this.response instanceof MockHttpServletResponse);
|
||||
return (this.request instanceof MockHttpServletRequest && this.response instanceof MockHttpServletResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,8 +112,8 @@ public class MockAsyncContext implements AsyncContext {
|
||||
try {
|
||||
listener.onComplete(new AsyncEvent(this, this.request, this.response));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("AsyncListener failure", e);
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("AsyncListener failure", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -356,12 +356,12 @@ public class MockPageContext extends PageContext {
|
||||
}
|
||||
|
||||
public byte[] getContentAsByteArray() {
|
||||
Assert.isTrue(this.response instanceof MockHttpServletResponse);
|
||||
Assert.state(this.response instanceof MockHttpServletResponse, "MockHttpServletResponse required");
|
||||
return ((MockHttpServletResponse) this.response).getContentAsByteArray();
|
||||
}
|
||||
|
||||
public String getContentAsString() throws UnsupportedEncodingException {
|
||||
Assert.isTrue(this.response instanceof MockHttpServletResponse);
|
||||
Assert.state(this.response instanceof MockHttpServletResponse, "MockHttpServletResponse required");
|
||||
return ((MockHttpServletResponse) this.response).getContentAsString();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -21,13 +22,14 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultUriTemplateHandler}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DefaultUriTemplateHandlerTests {
|
||||
|
||||
private final DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
|
||||
|
||||
Reference in New Issue
Block a user