1 /*
   2  * Copyright (c) 2017, 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 import java.nio.ByteBuffer;
  25 import java.nio.MappedByteBuffer;
  26 import java.util.Collection;
  27 import java.util.List;
  28 import java.util.concurrent.Flow;
  29 import java.util.function.Function;
  30 import jdk.incubator.http.HttpRequest.BodyPublisher;
  31 import jdk.incubator.http.HttpResponse.BodyHandler;
  32 import jdk.incubator.http.HttpResponse.BodySubscriber;
  33 
  34 /*
  35  * @test
  36  * @summary Basic test for Flow adapters with generic type parameters
  37  * @compile FlowAdaptersCompileOnly.java
  38  */
  39 
  40 public class FlowAdaptersCompileOnly {
  41 
  42     static void makesSureDifferentGenericSignaturesCompile() {
  43         BodyPublisher.fromPublisher(new BBPublisher());
  44         BodyPublisher.fromPublisher(new MBBPublisher());
  45 
  46         BodyHandler.fromSubscriber(new ListSubscriber());
  47         BodyHandler.fromSubscriber(new CollectionSubscriber());
  48         BodyHandler.fromSubscriber(new IterableSubscriber());
  49         BodyHandler.fromSubscriber(new ObjectSubscriber());
  50 
  51         BodySubscriber.fromSubscriber(new ListSubscriber());
  52         BodySubscriber.fromSubscriber(new CollectionSubscriber());
  53         BodySubscriber.fromSubscriber(new IterableSubscriber());
  54         BodySubscriber.fromSubscriber(new ObjectSubscriber());
  55 
  56         BodyPublisher.fromPublisher(new BBPublisher(), 1);
  57         BodyPublisher.fromPublisher(new MBBPublisher(), 1);
  58 
  59         BodyHandler.fromSubscriber(new ListSubscriber(), Function.identity());
  60         BodyHandler.fromSubscriber(new CollectionSubscriber(), Function.identity());
  61         BodyHandler.fromSubscriber(new IterableSubscriber(), Function.identity());
  62         BodyHandler.fromSubscriber(new ObjectSubscriber(), Function.identity());
  63 
  64         BodySubscriber.fromSubscriber(new ListSubscriber(), Function.identity());
  65         BodySubscriber.fromSubscriber(new CollectionSubscriber(), Function.identity());
  66         BodySubscriber.fromSubscriber(new IterableSubscriber(), Function.identity());
  67         BodySubscriber.fromSubscriber(new ObjectSubscriber(), Function.identity());
  68     }
  69 
  70     static class BBPublisher implements Flow.Publisher<ByteBuffer> {
  71         @Override
  72         public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber) { }
  73     }
  74 
  75     static class MBBPublisher implements Flow.Publisher<MappedByteBuffer> {
  76         @Override
  77         public void subscribe(Flow.Subscriber<? super MappedByteBuffer> subscriber) { }
  78     }
  79 
  80     static class ListSubscriber implements Flow.Subscriber<List<ByteBuffer>> {
  81         @Override public void onSubscribe(Flow.Subscription subscription) { }
  82         @Override public void onNext(List<ByteBuffer> item) { }
  83         @Override public void onError(Throwable throwable) { }
  84         @Override public void onComplete() { }
  85     }
  86 
  87     static class CollectionSubscriber implements Flow.Subscriber<Collection<ByteBuffer>> {
  88         @Override public void onSubscribe(Flow.Subscription subscription) { }
  89         @Override public void onNext(Collection<ByteBuffer> item) { }
  90         @Override public void onError(Throwable throwable) { }
  91         @Override public void onComplete() { }
  92     }
  93 
  94     static class IterableSubscriber implements Flow.Subscriber<Iterable<ByteBuffer>> {
  95         @Override public void onSubscribe(Flow.Subscription subscription) { }
  96         @Override public void onNext(Iterable<ByteBuffer> item) { }
  97         @Override public void onError(Throwable throwable) { }
  98         @Override public void onComplete() { }
  99     }
 100 
 101     static class ObjectSubscriber implements Flow.Subscriber<Object> {
 102         @Override public void onSubscribe(Flow.Subscription subscription) { }
 103         @Override public void onNext(Object item) { }
 104         @Override public void onError(Throwable throwable) { }
 105         @Override public void onComplete() { }
 106     }
 107 }