コード例 #1
0
ファイル: DynamicTest.java プロジェクト: sbrannen/junit5
  /**
   * Generate a stream of dynamic tests based on the supplied generators and test executor.
   *
   * <p>Use this method when the set of dynamic tests is nondeterministic in nature.
   *
   * <p>The supplied {@code inputGenerator} is responsible for generating input values. A {@link
   * DynamicTest} will be added to the resulting stream for each dynamically generated input value,
   * using the supplied {@code displayNameGenerator} and {@code testExecutor}.
   *
   * @param inputGenerator an {@code Iterator} that serves as a dynamic <em>input generator</em>;
   *     never {@code null}
   * @param displayNameGenerator a function that generates a display name based on an input value;
   *     never {@code null}
   * @param testExecutor a consumer that executes a test based on an input value; never {@code null}
   * @param <T> the type of <em>input</em> generated by the {@code inputGenerator} and used by the
   *     {@code displayNameGenerator} and {@code testExecutor}
   * @return a stream of dynamic tests based on the supplied generators and executor; never {@code
   *     null}
   * @see #dynamicTest(String, Executable)
   */
  public static <T> Stream<DynamicTest> stream(
      Iterator<T> inputGenerator,
      Function<? super T, String> displayNameGenerator,
      ThrowingConsumer<? super T> testExecutor) {

    Preconditions.notNull(inputGenerator, "inputGenerator must not be null");
    Preconditions.notNull(displayNameGenerator, "displayNameGenerator must not be null");
    Preconditions.notNull(testExecutor, "testExecutor must not be null");

    // @formatter:off
    return StreamSupport.stream(spliteratorUnknownSize(inputGenerator, ORDERED), false)
        .map(
            input ->
                dynamicTest(displayNameGenerator.apply(input), () -> testExecutor.accept(input)));
    // @formatter:on
  }
コード例 #2
0
ファイル: DynamicTest.java プロジェクト: sbrannen/junit5
 private DynamicTest(String displayName, Executable executable) {
   this.displayName = Preconditions.notBlank(displayName, "displayName must not be null or blank");
   this.executable = Preconditions.notNull(executable, "executable must not be null");
 }