Remove final class suppression 86/101686/5
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 1 Jul 2022 15:14:12 +0000 (17:14 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 1 Jul 2022 17:01:40 +0000 (19:01 +0200)
Rework constructor design to remove the need for @SuppressWarnings.

Change-Id: Ifac715ba69b2cb4268c15ecef2d40abfc759b022
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/util/http/SimpleHttpClient.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/util/http/SimpleHttpRequest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/realm/KeystoneAuthRealmTest.java

index beed0b015693e4249dc1640ad9a131537f666474..825356fb4012f36ccce3803925a9b84cc55f4a59 100644 (file)
@@ -15,16 +15,13 @@ import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
 
 /**
- * An utility that represents an HTTP client that allows to make
- * HTTP requests.
+ * An utility that represents an HTTP client that allows to make HTTP requests.
  */
-//Suppressed so UT's can mock it using Mockito.
-@SuppressWarnings("checkstyle:FinalClass")
+// Non-final for mocking
 public class SimpleHttpClient {
-
     private final Client client;
 
-    private SimpleHttpClient(final Client client) {
+    SimpleHttpClient(final Client client) {
         this.client = client;
     }
 
@@ -44,17 +41,17 @@ public class SimpleHttpClient {
      * @param <T> the return type of the request.
      * @return the request builder.
      */
-    public <T> SimpleHttpRequest.Builder<T> requestBuilder(Class<T> outputType) {
+    public <T> SimpleHttpRequest.Builder<T> requestBuilder(final Class<T> outputType) {
         return new SimpleHttpRequest.Builder<>(client, outputType);
     }
 
+    // Non-final for mocking
     public static class Builder {
-
+        private final Set<Class<?>> providers = new HashSet<>();
         private SSLContext sslContext;
         private HostnameVerifier hostnameVerifier;
-        private final Set<Class<?>> providers = new HashSet<>();
 
-        private Builder() {
+        Builder() {
 
         }
 
@@ -65,7 +62,7 @@ public class SimpleHttpClient {
          * @return self, the client builder.
          */
         public Builder sslContext(final SSLContext context) {
-            this.sslContext = context;
+            sslContext = context;
             return this;
         }
 
@@ -76,7 +73,7 @@ public class SimpleHttpClient {
          * @return self, the client builder.
          */
         public Builder hostnameVerifier(final HostnameVerifier verifier) {
-            this.hostnameVerifier = verifier;
+            hostnameVerifier = verifier;
             return this;
         }
 
@@ -106,6 +103,5 @@ public class SimpleHttpClient {
 
             return new SimpleHttpClient(clientBuilder.build());
         }
-
     }
 }
index a3bf7eecaa5249b9a1089f50e6a43884958e24c4..fa64fd26fa3dc045a04c9d709543444762de3d70 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.aaa.shiro.realm.util.http;
 
 import java.net.URI;
@@ -19,16 +18,15 @@ import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-
 /**
  * Basic utility to do an HTTP request. See {@link
  * SimpleHttpClient#requestBuilder(Class)} on how to obtain a request builder.
  *
  * @param <T> the return type of the request.
  */
-// Suppressed so UT's can mock it using Mockito.
-@SuppressWarnings("checkstyle:FinalClass")
+// Non-final for mocking
 public class SimpleHttpRequest<T> {
+    private final Map<String, String> queryParams = new HashMap<>();
     private final Client client;
     private final Class<T> outputType;
     private URI uri;
@@ -36,9 +34,8 @@ public class SimpleHttpRequest<T> {
     private String method;
     private MediaType mediaType;
     private Object entity;
-    private final Map<String, String> queryParams = new HashMap<>();
 
-    private SimpleHttpRequest(final Client client, final Class<T> outputType) {
+    SimpleHttpRequest(final Client client, final Class<T> outputType) {
         this.client = client;
         this.outputType = outputType;
     }
@@ -76,14 +73,15 @@ public class SimpleHttpRequest<T> {
      *
      * @return the builder.
      */
-    static <T> Builder<T> builder(Client client, Class<T> outputType) {
+    static <T> Builder<T> builder(final Client client, final Class<T> outputType) {
         return new Builder<>(client, outputType);
     }
 
+    // Non-final for mocking
     public static class Builder<T> {
         private final SimpleHttpRequest<T> request;
 
-        Builder(Client client, Class<T> outputType) {
+        Builder(final Client client, final Class<T> outputType) {
             request = new SimpleHttpRequest<>(client, outputType);
         }
 
@@ -93,7 +91,7 @@ public class SimpleHttpRequest<T> {
          * @param uri the URI.
          * @return self, the request builder.
          */
-        public Builder<T> uri(URI uri) {
+        public Builder<T> uri(final URI uri) {
             request.uri = uri;
             return this;
         }
@@ -104,7 +102,7 @@ public class SimpleHttpRequest<T> {
          * @param path the path.
          * @return self, the request builder.
          */
-        public Builder<T> path(String path) {
+        public Builder<T> path(final String path) {
             request.path = path;
             return this;
         }
@@ -115,7 +113,7 @@ public class SimpleHttpRequest<T> {
          * @param method the method.
          * @return self, the request builder.
          */
-        public Builder<T> method(String method) {
+        public Builder<T> method(final String method) {
             request.method = method;
             return this;
         }
@@ -126,7 +124,7 @@ public class SimpleHttpRequest<T> {
          * @param mediaType the media type.
          * @return self, the request builder.
          */
-        public Builder<T> mediaType(MediaType mediaType) {
+        public Builder<T> mediaType(final MediaType mediaType) {
             request.mediaType = mediaType;
             return this;
         }
@@ -137,7 +135,7 @@ public class SimpleHttpRequest<T> {
          * @param input the input payload.
          * @return self, the request builder.
          */
-        public Builder<T> entity(Object input) {
+        public Builder<T> entity(final Object input) {
             request.entity = input;
             return this;
         }
@@ -151,7 +149,7 @@ public class SimpleHttpRequest<T> {
          * @param theParamValue the parameter value
          * @return  self, the request builder
          */
-        public Builder<T> queryParam(String theQueryParam, String theParamValue) {
+        public Builder<T> queryParam(final String theQueryParam, final String theParamValue) {
             request.queryParams.put(theQueryParam, theParamValue);
             return this;
         }
index 352f218fa94fee87cebaea66385db5107021187e..81d8da629e19af822618aad0506f6f2b3b2c0540 100644 (file)
@@ -52,9 +52,6 @@ import org.opendaylight.aaa.shiro.web.env.ThreadLocals;
 @RunWith(MockitoJUnitRunner.class)
 public class KeystoneAuthRealmTest {
 
-    @Mock
-    private SimpleHttpRequest.Builder<KeystoneToken> builder;
-
     @Mock
     private ICertificateManager certificateManager;