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

com.spotify.hamcrest.future.FutureMatchers Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
/*-
 * -\-\-
 * hamcrest-future
 * --
 * Copyright (C) 2016 Spotify AB
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * -/-/-
 */

package com.spotify.hamcrest.future;

import static org.hamcrest.CoreMatchers.any;

import java.util.concurrent.Future;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matcher;

public class FutureMatchers {

  private FutureMatchers() {
  }

  /**
   * Creates a Matcher that matches a Future that has completed with an exception. A
   * Future that is not yet completed will not be matched.
   */
  public static  Matcher> futureCompletedWithException() {
    return futureCompletedWithExceptionThat(any(Throwable.class));
  }

  /**
   * Creates a Matcher that matches a Future that has completed with an exception that
   * matches the given Matcher. A Future that is not yet completed will not be matched.
   */

  public static  Matcher> futureCompletedWithExceptionThat(
      final Matcher matcher) {
    return new ExceptionallyCompletedFuture<>(matcher);
  }

  /**
   * Creates a Matcher that matches a Future that has completed with a value. A
   * Future that is not yet completed will not be matched.
   */
  public static Matcher> futureCompletedWithValue() {
    return futureCompletedWithValueThat(CoreMatchers.anything());
  }

  /**
   * Creates a Matcher that matches a Future that has completed with a value that matches
   * a given Matcher. A Future that is not yet completed will not be matched.
   */
  public static  Matcher> futureCompletedWithValueThat(
      final Matcher matcher) {
    return new SuccessfullyCompletedFuture<>(matcher);
  }

  /**
   * Creates a Matcher that matches a Future that has completed with an exception.
   *
   * 

If the Future has not yet completed, this matcher waits for it to finish. */ public static Matcher> futureWillCompleteWithException() { return futureWillCompleteWithExceptionThat(any(Throwable.class)); } /** * Creates a Matcher that matches a Future that has completed with an exception that * matches the given Matcher. * *

If the Future has not yet completed, this matcher waits for it to finish. */ public static Matcher> futureWillCompleteWithExceptionThat( final Matcher matcher) { return new ExceptionallyCompletedBlockingFuture<>(matcher); } /** * Creates a Matcher that matches a Future that has completed with a value. * *

If the Future has not yet completed, this matcher waits for it to finish. */ public static Matcher> futureWillCompleteWithValue() { return futureWillCompleteWithValueThat(CoreMatchers.anything()); } /** * Creates a Matcher that matches a Future that has completed with a value that matches * a given Matcher. * *

If the Future has not yet completed, this matcher waits for it to finish. */ public static Matcher> futureWillCompleteWithValueThat( final Matcher matcher) { return new SuccessfullyCompletedBlockingFuture<>(matcher); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy