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

jio.test.stub.httpserver.StatusCodeStub 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 fun.gen.Gen;

import java.util.Objects;
import java.util.function.Supplier;

/**
 * Stub that stands in for the status code of the response of an HTTP request.
 */
public non-sealed interface StatusCodeStub extends HttpRespStub {

  /**
   * Creates a status code stub where each call returns the value generated by the given generator.
   *
   * @param gen The generator for generating status code values.
   * @return A status code stub that returns the generated status code.
   * @throws NullPointerException if the provided generator is null.
   */
  static StatusCodeStub gen(final Gen gen) {
    Supplier supplier = Objects.requireNonNull(gen)
                                        .sample();
    return n -> bodyReq -> uri -> headers -> supplier.get();
  }

  /**
   * Creates a status code stub that always returns the specified status code.
   *
   * @param code The status code to return.
   * @return A status code stub.
   */
  static StatusCodeStub cons(int code) {
    return n -> bodyReq -> uri -> headers -> code;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy