001/************************************************************************
002 * Licensed under Public Domain (CC0)                                    *
003 *                                                                       *
004 * To the extent possible under law, the person who associated CC0 with  *
005 * this code has waived all copyright and related or neighboring         *
006 * rights to this code.                                                  *
007 *                                                                       *
008 * You should have received a copy of the CC0 legalcode along with this  *
009 * work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.*
010 ************************************************************************/
011
012package org.reactivestreams.tck.flow;
013
014import org.reactivestreams.FlowAdapters;
015import org.reactivestreams.Subscriber;
016import org.reactivestreams.tck.SubscriberWhiteboxVerification;
017import org.reactivestreams.tck.TestEnvironment;
018import org.reactivestreams.tck.flow.support.SubscriberWhiteboxVerificationRules;
019
020import java.util.concurrent.Flow;
021
022/**
023 * Provides whitebox style tests for verifying {@link java.util.concurrent.Flow.Subscriber}
024 * and {@link java.util.concurrent.Flow.Subscription} specification rules.
025 *
026 * @see java.util.concurrent.Flow.Subscriber
027 * @see java.util.concurrent.Flow.Subscription
028 */
029public abstract class FlowSubscriberWhiteboxVerification<T> extends SubscriberWhiteboxVerification<T>
030  implements SubscriberWhiteboxVerificationRules {
031
032  protected FlowSubscriberWhiteboxVerification(TestEnvironment env) {
033    super(env);
034  }
035
036  @Override
037  final public Subscriber<T> createSubscriber(WhiteboxSubscriberProbe<T> probe) {
038    return FlowAdapters.toSubscriber(createFlowSubscriber(probe));
039  }
040  /**
041   * This is the main method you must implement in your test incarnation.
042   * It must create a new {@link org.reactivestreams.Subscriber} instance to be subjected to the testing logic.
043   *
044   * In order to be meaningfully testable your Subscriber must inform the given
045   * `WhiteboxSubscriberProbe` of the respective events having been received.
046   */
047  protected abstract Flow.Subscriber<T> createFlowSubscriber(WhiteboxSubscriberProbe<T> probe);
048}