Fix mutual static references between HttpMethod and HttpMethodImpl

This commit is contained in:
Julien Viet
2020-01-20 10:49:38 +01:00
parent a5b2fa5434
commit db4dca16f0
4 changed files with 71 additions and 35 deletions

View File

@@ -280,6 +280,6 @@ public interface HttpMethod {
* @return an un-modifiable list of known HTTP methods
*/
static List<HttpMethod> values() {
return HttpMethodImpl.ALL;
return HttpMethods.ALL;
}
}

View File

@@ -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 <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
class HttpMethods {
static final List<HttpMethod> 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
));
}

View File

@@ -19,40 +19,6 @@ import java.util.Objects;
public class HttpMethodImpl implements HttpMethod {
public static final List<HttpMethod> 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;

View File

@@ -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<HttpMethod> list = HttpMethod.values();
assertTrue(!list.isEmpty());
list.forEach(Assert::assertNotNull);
}
}