test/jdk/java/net/httpclient/reactivestreams-tck/org/reactivestreams/tck/flow/FlowSubscriberBlackboxVerification.java
changeset 55546 3ae57bbf9585
equal deleted inserted replaced
55545:8a153a932d0f 55546:3ae57bbf9585
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package org.reactivestreams.tck.flow;
       
    25 
       
    26 import org.reactivestreams.FlowAdapters;
       
    27 import org.reactivestreams.Subscriber;
       
    28 import org.reactivestreams.Subscription;
       
    29 import org.reactivestreams.tck.SubscriberBlackboxVerification;
       
    30 import org.reactivestreams.tck.TestEnvironment;
       
    31 import org.reactivestreams.tck.flow.support.SubscriberBlackboxVerificationRules;
       
    32 
       
    33 import java.util.concurrent.Flow;
       
    34 
       
    35 /**
       
    36  * Provides tests for verifying {@link java.util.concurrent.Flow.Subscriber} and {@link java.util.concurrent.Flow.Subscription}
       
    37  * specification rules, without any modifications to the tested implementation (also known as "Black Box" testing).
       
    38  *
       
    39  * This verification is NOT able to check many of the rules of the spec, and if you want more
       
    40  * verification of your implementation you'll have to implement {@code org.reactivestreams.tck.SubscriberWhiteboxVerification}
       
    41  * instead.
       
    42  *
       
    43  * @see java.util.concurrent.Flow.Subscriber
       
    44  * @see java.util.concurrent.Flow.Subscription
       
    45  */
       
    46 public abstract class FlowSubscriberBlackboxVerification<T> extends SubscriberBlackboxVerification<T>
       
    47   implements SubscriberBlackboxVerificationRules {
       
    48 
       
    49   protected FlowSubscriberBlackboxVerification(TestEnvironment env) {
       
    50     super(env);
       
    51   }
       
    52 
       
    53   @Override
       
    54   public final void triggerRequest(Subscriber<? super T> subscriber) {
       
    55     triggerFlowRequest(FlowAdapters.toFlowSubscriber(subscriber));
       
    56   }
       
    57   /**
       
    58    * Override this method if the {@link java.util.concurrent.Flow.Subscriber} implementation you are verifying
       
    59    * needs an external signal before it signals demand to its Publisher.
       
    60    *
       
    61    * By default this method does nothing.
       
    62    */
       
    63   public void triggerFlowRequest(Flow.Subscriber<? super T> subscriber) {
       
    64     // this method is intentionally left blank
       
    65   }
       
    66 
       
    67   @Override
       
    68   public final Subscriber<T> createSubscriber() {
       
    69     return FlowAdapters.<T>toSubscriber(createFlowSubscriber());
       
    70   }
       
    71   /**
       
    72    * This is the main method you must implement in your test incarnation.
       
    73    * It must create a new {@link Flow.Subscriber} instance to be subjected to the testing logic.
       
    74    */
       
    75   abstract public Flow.Subscriber<T> createFlowSubscriber();
       
    76 
       
    77 }