View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.http;
6   
7   import com.jcabi.http.request.ApacheRequest;
8   import com.jcabi.http.request.JdkRequest;
9   import java.lang.annotation.Retention;
10  import java.lang.annotation.RetentionPolicy;
11  import java.net.URI;
12  import lombok.SneakyThrows;
13  import org.junit.jupiter.params.provider.ValueSource;
14  
15  /**
16   * Template for generic tests for {@link Request}.
17   *
18   * @since 1.17.4
19   */
20  @SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
21  abstract class RequestTestTemplate {
22      /**
23       * Annotation for a parameterized test case.
24       *
25       * @since 1.17.4
26       */
27      @Retention(RetentionPolicy.RUNTIME)
28      @ValueSource(classes = {ApacheRequest.class, JdkRequest.class})
29      protected @interface Values {
30      }
31  
32      /**
33       * Make a request.
34       * @param uri URI to start with
35       * @param type Type of the request
36       * @return Request
37       */
38      @SneakyThrows
39      static Request request(final URI uri, final Class<? extends Request> type) {
40          return type.getDeclaredConstructor(URI.class).newInstance(uri);
41      }
42  }