From db4dca16f0e8e863a873c12cc74067993212dc1d Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Mon, 20 Jan 2020 10:49:38 +0100 Subject: [PATCH] Fix mutual static references between HttpMethod and HttpMethodImpl --- .../java/io/vertx/core/http/HttpMethod.java | 2 +- .../java/io/vertx/core/http/HttpMethods.java | 59 +++++++++++++++++++ .../vertx/core/http/impl/HttpMethodImpl.java | 34 ----------- .../io/vertx/core/http/HttpMethodTest.java | 11 ++++ 4 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 src/main/java/io/vertx/core/http/HttpMethods.java diff --git a/src/main/java/io/vertx/core/http/HttpMethod.java b/src/main/java/io/vertx/core/http/HttpMethod.java index e9db3003b..3d04aacaa 100644 --- a/src/main/java/io/vertx/core/http/HttpMethod.java +++ b/src/main/java/io/vertx/core/http/HttpMethod.java @@ -280,6 +280,6 @@ public interface HttpMethod { * @return an un-modifiable list of known HTTP methods */ static List values() { - return HttpMethodImpl.ALL; + return HttpMethods.ALL; } } diff --git a/src/main/java/io/vertx/core/http/HttpMethods.java b/src/main/java/io/vertx/core/http/HttpMethods.java new file mode 100644 index 000000000..9ec6dfeae --- /dev/null +++ b/src/main/java/io/vertx/core/http/HttpMethods.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011-2019 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + */ +package io.vertx.core.http; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * List of HTTP methods, this class is used to avoid exposing a modifiable field on {@link HttpMethod} and the + * {@link io.vertx.core.http.impl.HttpMethodImpl} implementation cannot statically define this field {@link HttpMethod} + * creates static {@link io.vertx.core.http.impl.HttpMethodImpl} instances. + * + * @author Julien Viet + */ +class HttpMethods { + + static final List ALL = Collections.unmodifiableList(Arrays.asList( + HttpMethod.OPTIONS, + HttpMethod.GET, + HttpMethod.HEAD, + HttpMethod.POST, + HttpMethod.PUT, + HttpMethod.DELETE, + HttpMethod.TRACE, + HttpMethod.CONNECT, + HttpMethod.PATCH, + HttpMethod.PROPFIND, + HttpMethod.PROPPATCH, + HttpMethod.MKCOL, + HttpMethod.COPY, + HttpMethod.MOVE, + HttpMethod.LOCK, + HttpMethod.UNLOCK, + HttpMethod.MKCALENDAR, + HttpMethod.VERSION_CONTROL, + HttpMethod.REPORT, + HttpMethod.CHECKIN, + HttpMethod.CHECKOUT, + HttpMethod.UNCHECKOUT, + HttpMethod.MKWORKSPACE, + HttpMethod.UPDATE, + HttpMethod.LABEL, + HttpMethod.MERGE, + HttpMethod.BASELINE_CONTROL, + HttpMethod.MKACTIVITY, + HttpMethod.ORDERPATCH, + HttpMethod.ACL, + HttpMethod.SEARCH + )); +} diff --git a/src/main/java/io/vertx/core/http/impl/HttpMethodImpl.java b/src/main/java/io/vertx/core/http/impl/HttpMethodImpl.java index 47c3baaf5..7510071a8 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpMethodImpl.java +++ b/src/main/java/io/vertx/core/http/impl/HttpMethodImpl.java @@ -19,40 +19,6 @@ import java.util.Objects; public class HttpMethodImpl implements HttpMethod { - public static final List ALL = Collections.unmodifiableList(Arrays.asList( - HttpMethod.OPTIONS, - HttpMethod.GET, - HttpMethod.HEAD, - HttpMethod.POST, - HttpMethod.PUT, - HttpMethod.DELETE, - HttpMethod.TRACE, - HttpMethod.CONNECT, - HttpMethod.PATCH, - HttpMethod.PROPFIND, - HttpMethod.PROPPATCH, - HttpMethod.MKCOL, - HttpMethod.COPY, - HttpMethod.MOVE, - HttpMethod.LOCK, - HttpMethod.UNLOCK, - HttpMethod.MKCALENDAR, - HttpMethod.VERSION_CONTROL, - HttpMethod.REPORT, - HttpMethod.CHECKIN, - HttpMethod.CHECKOUT, - HttpMethod.UNCHECKOUT, - HttpMethod.MKWORKSPACE, - HttpMethod.UPDATE, - HttpMethod.LABEL, - HttpMethod.MERGE, - HttpMethod.BASELINE_CONTROL, - HttpMethod.MKACTIVITY, - HttpMethod.ORDERPATCH, - HttpMethod.ACL, - HttpMethod.SEARCH - )); - public static io.netty.handler.codec.http.HttpMethod toNetty(HttpMethod method) { if (method instanceof HttpMethodImpl) { return ((HttpMethodImpl) method).nettyMethod; diff --git a/src/test/java/io/vertx/core/http/HttpMethodTest.java b/src/test/java/io/vertx/core/http/HttpMethodTest.java index 2845b208a..8e0868efe 100644 --- a/src/test/java/io/vertx/core/http/HttpMethodTest.java +++ b/src/test/java/io/vertx/core/http/HttpMethodTest.java @@ -11,12 +11,16 @@ package io.vertx.core.http; import io.vertx.core.http.impl.HttpMethodImpl; +import org.junit.Assert; import org.junit.Test; import java.util.Arrays; +import java.util.List; +import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; @@ -162,4 +166,11 @@ public class HttpMethodTest { assertEquals(HttpMethodImpl.toNetty(HttpMethod.valueOf("foo")).name(), "foo"); assertEquals(HttpMethodImpl.fromNetty(io.netty.handler.codec.http.HttpMethod.valueOf("foo")).name(), "foo"); } + + @Test + public void testValues() { + List list = HttpMethod.values(); + assertTrue(!list.isEmpty()); + list.forEach(Assert::assertNotNull); + } }