All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jio.test.stub.httpserver.OptionsStub Maven / Gradle / Ivy

Go to download

JIO test library based on Property Based Testing and Java Flight Recording Debuggers

There is a newer version: 3.0.0-RC2
Show newest version
package jio.test.stub.httpserver;

import com.sun.net.httpserver.HttpHandler;

import static java.util.Objects.requireNonNull;

/**
 * Stub that stands in for the {@link HttpHandler} of an OPTIONS HTTP request.
 */
public final class OptionsStub extends ReqHandlerStub {

  private OptionsStub(final BodyStub body,
                      final StatusCodeStub statusCode,
                      final HeadersStub headers
                     ) {
    super(requireNonNull(body),
          requireNonNull(statusCode),
          requireNonNull(headers),
          "options"
         );
  }

  /**
   * Creates a GET handler stub that builds the HTTP response from the given body, status code, and headers stubs.
   *
   * @param body       The body response stub.
   * @param statusCode The status code response stub.
   * @param headers    The headers response stub.
   * @return A GET stub.
   */
  public static OptionsStub of(final BodyStub body,
                               final StatusCodeStub statusCode,
                               final HeadersStub headers
                              ) {
    return new OptionsStub(body,
                           statusCode,
                           headers);
  }

  /**
   * Creates a GET handler stub that builds the HTTP response from the given body and status code stubs.
   *
   * @param body       The body response stub.
   * @param statusCode The status code response stub.
   * @return A GET stub.
   */
  public static OptionsStub of(final BodyStub body,
                               final StatusCodeStub statusCode
                              ) {
    return new OptionsStub(body,
                           statusCode,
                           HeadersStub.EMPTY);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy