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