test/jdk/java/net/httpclient/LineAdaptersCompileOnly.java
branchhttp-client-branch
changeset 56009 cf8792f51dee
child 56089 42208b2f224e
equal deleted inserted replaced
56008:bbd688c6fbbb 56009:cf8792f51dee
       
     1 /*
       
     2  * Copyright (c) 2018, 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.charset.StandardCharsets;
       
    25 import java.util.concurrent.Flow;
       
    26 import java.util.function.Function;
       
    27 import jdk.incubator.http.HttpResponse.BodyHandler;
       
    28 import jdk.incubator.http.HttpResponse.BodySubscriber;
       
    29 
       
    30 /*
       
    31  * @test
       
    32  * @summary Basic test for Flow adapters with generic type parameters
       
    33  * @compile LineAdaptersCompileOnly.java
       
    34  */
       
    35 
       
    36 public class LineAdaptersCompileOnly {
       
    37 
       
    38     public static void main(String[] args) {
       
    39         makesSureDifferentGenericSignaturesCompile();
       
    40     }
       
    41 
       
    42     static void makesSureDifferentGenericSignaturesCompile() {
       
    43 
       
    44         BodyHandler.fromLineSubscriber(new StringSubscriber());
       
    45         BodyHandler.fromLineSubscriber(new CharSequenceSubscriber());
       
    46         BodyHandler.fromLineSubscriber(new ObjectSubscriber());
       
    47 
       
    48 
       
    49         BodySubscriber.fromLineSubscriber(new StringSubscriber());
       
    50         BodySubscriber.fromLineSubscriber(new CharSequenceSubscriber());
       
    51         BodySubscriber.fromLineSubscriber(new ObjectSubscriber());
       
    52 
       
    53 
       
    54         BodyHandler.fromLineSubscriber(new StringSubscriber(), Function.identity(), "\n");
       
    55         BodyHandler.fromLineSubscriber(new CharSequenceSubscriber(), Function.identity(),  "\r\n");
       
    56         BodyHandler.fromLineSubscriber(new ObjectSubscriber(), Function.identity(), "\n");
       
    57         BodyHandler.fromLineSubscriber(new StringSubscriber(), Function.identity(), null);
       
    58         BodyHandler.fromLineSubscriber(new CharSequenceSubscriber(), Function.identity(),  null);
       
    59         BodyHandler.fromLineSubscriber(new ObjectSubscriber(), Function.identity(), null);
       
    60 
       
    61         BodySubscriber.fromLineSubscriber(new StringSubscriber(), Function.identity(),
       
    62                 StandardCharsets.UTF_8, "\n");
       
    63         BodySubscriber.fromLineSubscriber(new CharSequenceSubscriber(), Function.identity(),
       
    64                 StandardCharsets.UTF_16, "\r\n");
       
    65         BodySubscriber.fromLineSubscriber(new ObjectSubscriber(), Function.identity(),
       
    66                 StandardCharsets.US_ASCII, "\n");
       
    67         BodySubscriber.fromLineSubscriber(new StringSubscriber(), Function.identity(),
       
    68                 StandardCharsets.UTF_8, null);
       
    69         BodySubscriber.fromLineSubscriber(new CharSequenceSubscriber(), Function.identity(),
       
    70                 StandardCharsets.UTF_16, null);
       
    71         BodySubscriber.fromLineSubscriber(new ObjectSubscriber(), Function.identity(),
       
    72                 StandardCharsets.US_ASCII, null);
       
    73     }
       
    74 
       
    75     static class StringSubscriber implements Flow.Subscriber<String> {
       
    76         @Override public void onSubscribe(Flow.Subscription subscription) { }
       
    77         @Override public void onNext(String item) { }
       
    78         @Override public void onError(Throwable throwable) { }
       
    79         @Override public void onComplete() { }
       
    80     }
       
    81 
       
    82     static class CharSequenceSubscriber implements Flow.Subscriber<CharSequence> {
       
    83         @Override public void onSubscribe(Flow.Subscription subscription) { }
       
    84         @Override public void onNext(CharSequence item) { }
       
    85         @Override public void onError(Throwable throwable) { }
       
    86         @Override public void onComplete() { }
       
    87     }
       
    88 
       
    89     static class ObjectSubscriber implements Flow.Subscriber<Object> {
       
    90         @Override public void onSubscribe(Flow.Subscription subscription) { }
       
    91         @Override public void onNext(Object item) { }
       
    92         @Override public void onError(Throwable throwable) { }
       
    93         @Override public void onComplete() { }
       
    94     }
       
    95 }