001/*************************************************** 002 * Licensed under MIT No Attribution (SPDX: MIT-0) * 003 ***************************************************/ 004 005package org.reactivestreams.tck.flow; 006 007import org.reactivestreams.FlowAdapters; 008import org.reactivestreams.Subscriber; 009import org.reactivestreams.Subscription; 010import org.reactivestreams.tck.SubscriberBlackboxVerification; 011import org.reactivestreams.tck.TestEnvironment; 012import org.reactivestreams.tck.flow.support.SubscriberBlackboxVerificationRules; 013 014import java.util.concurrent.Flow; 015 016/** 017 * Provides tests for verifying {@link java.util.concurrent.Flow.Subscriber} and {@link java.util.concurrent.Flow.Subscription} 018 * specification rules, without any modifications to the tested implementation (also known as "Black Box" testing). 019 * 020 * This verification is NOT able to check many of the rules of the spec, and if you want more 021 * verification of your implementation you'll have to implement {@code org.reactivestreams.tck.SubscriberWhiteboxVerification} 022 * instead. 023 * 024 * @see java.util.concurrent.Flow.Subscriber 025 * @see java.util.concurrent.Flow.Subscription 026 */ 027public abstract class FlowSubscriberBlackboxVerification<T> extends SubscriberBlackboxVerification<T> 028 implements SubscriberBlackboxVerificationRules { 029 030 protected FlowSubscriberBlackboxVerification(TestEnvironment env) { 031 super(env); 032 } 033 034 @Override 035 public final void triggerRequest(Subscriber<? super T> subscriber) { 036 triggerFlowRequest(FlowAdapters.toFlowSubscriber(subscriber)); 037 } 038 /** 039 * Override this method if the {@link java.util.concurrent.Flow.Subscriber} implementation you are verifying 040 * needs an external signal before it signals demand to its Publisher. 041 * 042 * By default this method does nothing. 043 */ 044 public void triggerFlowRequest(Flow.Subscriber<? super T> subscriber) { 045 // this method is intentionally left blank 046 } 047 048 @Override 049 public final Subscriber<T> createSubscriber() { 050 return FlowAdapters.<T>toSubscriber(createFlowSubscriber()); 051 } 052 /** 053 * This is the main method you must implement in your test incarnation. 054 * It must create a new {@link Flow.Subscriber} instance to be subjected to the testing logic. 055 */ 056 abstract public Flow.Subscriber<T> createFlowSubscriber(); 057 058}