test/jdk/java/net/httpclient/SubscriberPublisherAPIExceptions.java
author chegar
Tue, 18 Jun 2019 18:38:53 +0100
changeset 55405 17f24c0e2f01
parent 49765 ee6f7a61f3a5
child 56451 9585061fdb04
permissions -rw-r--r--
8226319: Add forgotten test/jdk/java/net/httpclient/BodySubscribersTest.java Reviewed-by: dfuchs, prappo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
     1
/*
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
     4
 *
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
     8
 *
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    13
 * accompanied this code).
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    14
 *
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    18
 *
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    21
 * questions.
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    22
 */
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    23
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    24
import java.io.FileNotFoundException;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    25
import java.nio.ByteBuffer;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    26
import java.nio.file.Files;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    27
import java.nio.file.Path;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    28
import java.nio.file.Paths;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    29
import java.nio.file.OpenOption;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    30
import java.util.List;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    31
import java.util.concurrent.CompletableFuture;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    32
import java.util.concurrent.Flow;
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    33
import java.net.http.HttpHeaders;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    34
import java.net.http.HttpRequest.BodyPublishers;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    35
import java.net.http.HttpResponse.BodyHandler;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    36
import java.net.http.HttpResponse.ResponseInfo;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    37
import java.net.http.HttpResponse.BodyHandlers;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    38
import java.net.http.HttpResponse.BodySubscriber;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    39
import java.net.http.HttpResponse.BodySubscribers;
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    40
import java.util.function.Function;
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    41
import org.testng.annotations.DataProvider;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    42
import org.testng.annotations.Test;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    43
import static java.nio.charset.StandardCharsets.UTF_8;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    44
import static java.nio.file.StandardOpenOption.CREATE;
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    45
import static java.nio.file.StandardOpenOption.DELETE_ON_CLOSE;
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    46
import static java.nio.file.StandardOpenOption.WRITE;
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    47
import static java.nio.file.StandardOpenOption.READ;
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    48
import static org.testng.Assert.assertThrows;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    49
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    50
/*
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    51
 * @test
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    52
 * @summary Basic tests for API specified exceptions from Publisher, Handler,
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    53
 *          and Subscriber convenience static factory methods.
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    54
 * @run testng SubscriberPublisherAPIExceptions
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    55
 */
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    56
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    57
public class SubscriberPublisherAPIExceptions {
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    58
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    59
    static final Class<NullPointerException> NPE = NullPointerException.class;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    60
    static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    61
    static final Class<IndexOutOfBoundsException> IOB = IndexOutOfBoundsException.class;
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    62
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    63
    @Test
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    64
    public void publisherAPIExceptions() {
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    65
        assertThrows(NPE, () -> BodyPublishers.ofByteArray(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    66
        assertThrows(NPE, () -> BodyPublishers.ofByteArray(null, 0, 1));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    67
        assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100],    0, 101));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    68
        assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100],    1, 100));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    69
        assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100],   -1,  10));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    70
        assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100],   99,   2));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    71
        assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[1],   -100,   1));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    72
        assertThrows(NPE, () -> BodyPublishers.ofByteArray(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    73
        assertThrows(NPE, () -> BodyPublishers.ofFile(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    74
        assertThrows(NPE, () -> BodyPublishers.ofInputStream(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    75
        assertThrows(NPE, () -> BodyPublishers.ofString(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    76
        assertThrows(NPE, () -> BodyPublishers.ofString("A", null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    77
        assertThrows(NPE, () -> BodyPublishers.ofString(null, UTF_8));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    78
        assertThrows(NPE, () -> BodyPublishers.ofString(null, null));
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    79
    }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    80
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    81
    @DataProvider(name = "nonExistentFiles")
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    82
    public Object[][] nonExistentFiles() {
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    83
        List<Path> paths = List.of(Paths.get("doesNotExist"),
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    84
                                   Paths.get("tsixEtoNseod"),
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    85
                                   Paths.get("doesNotExist2"));
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    86
        paths.forEach(p -> {
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    87
            if (Files.exists(p))
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    88
                throw new AssertionError("Unexpected " + p);
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    89
        });
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    90
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    91
        return paths.stream().map(p -> new Object[] { p }).toArray(Object[][]::new);
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    92
    }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    93
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    94
    @Test(dataProvider = "nonExistentFiles", expectedExceptions = FileNotFoundException.class)
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    95
    public void fromFileCheck(Path path) throws Exception {
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
    96
        BodyPublishers.ofFile(path);
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    97
    }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    98
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
    99
    @Test
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   100
    public void handlerAPIExceptions() throws Exception {
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   101
        Path path = Paths.get(".").resolve("tt");
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   102
        Path file = Files.createFile(Paths.get(".").resolve("aFile"));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   103
        Path doesNotExist = Paths.get(".").resolve("doneNotExist");
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   104
        if (Files.exists(doesNotExist))
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   105
            throw new AssertionError("Unexpected " + doesNotExist);
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   106
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   107
        assertThrows(NPE, () -> BodyHandlers.ofByteArrayConsumer(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   108
        assertThrows(NPE, () -> BodyHandlers.ofFile(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   109
        assertThrows(NPE, () -> BodyHandlers.ofFile(null, CREATE, WRITE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   110
        assertThrows(NPE, () -> BodyHandlers.ofFile(path, (OpenOption[])null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   111
        assertThrows(NPE, () -> BodyHandlers.ofFile(path, new OpenOption[] {null}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   112
        assertThrows(NPE, () -> BodyHandlers.ofFile(path, new OpenOption[] {CREATE, null}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   113
        assertThrows(NPE, () -> BodyHandlers.ofFile(path, new OpenOption[] {null, CREATE}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   114
        assertThrows(NPE, () -> BodyHandlers.ofFile(null, (OpenOption[])null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   115
        assertThrows(NPE, () -> BodyHandlers.ofFileDownload(null, CREATE, WRITE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   116
        assertThrows(NPE, () -> BodyHandlers.ofFileDownload(path, (OpenOption[])null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   117
        assertThrows(NPE, () -> BodyHandlers.ofFileDownload(path, new OpenOption[] {null}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   118
        assertThrows(NPE, () -> BodyHandlers.ofFileDownload(path, new OpenOption[] {CREATE, null}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   119
        assertThrows(NPE, () -> BodyHandlers.ofFileDownload(path, new OpenOption[] {null, CREATE}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   120
        assertThrows(NPE, () -> BodyHandlers.ofFileDownload(null, (OpenOption[])null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   121
        assertThrows(IAE, () -> BodyHandlers.ofFileDownload(file, CREATE, WRITE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   122
        assertThrows(IAE, () -> BodyHandlers.ofFileDownload(doesNotExist, CREATE, WRITE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   123
        assertThrows(NPE, () -> BodyHandlers.ofString(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   124
        assertThrows(NPE, () -> BodyHandlers.buffering(null, 1));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   125
        assertThrows(IAE, () -> BodyHandlers.buffering(new NoOpHandler(), 0));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   126
        assertThrows(IAE, () -> BodyHandlers.buffering(new NoOpHandler(), -1));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   127
        assertThrows(IAE, () -> BodyHandlers.buffering(new NoOpHandler(), Integer.MIN_VALUE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   128
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   129
        // implementation specific exceptions
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   130
        assertThrows(IAE, () -> BodyHandlers.ofFile(path, READ));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   131
        assertThrows(IAE, () -> BodyHandlers.ofFile(path, DELETE_ON_CLOSE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   132
        assertThrows(IAE, () -> BodyHandlers.ofFile(path, READ, DELETE_ON_CLOSE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   133
        assertThrows(IAE, () -> BodyHandlers.ofFileDownload(path, DELETE_ON_CLOSE));
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   134
    }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   135
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   136
    @Test
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   137
    public void subscriberAPIExceptions() {
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   138
        Path path = Paths.get(".").resolve("tt");
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   139
        assertThrows(NPE, () -> BodySubscribers.ofByteArrayConsumer(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   140
        assertThrows(NPE, () -> BodySubscribers.ofFile(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   141
        assertThrows(NPE, () -> BodySubscribers.ofFile(null, CREATE, WRITE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   142
        assertThrows(NPE, () -> BodySubscribers.ofFile(path, (OpenOption[])null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   143
        assertThrows(NPE, () -> BodySubscribers.ofFile(path, new OpenOption[] {null}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   144
        assertThrows(NPE, () -> BodySubscribers.ofFile(path, new OpenOption[] {CREATE, null}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   145
        assertThrows(NPE, () -> BodySubscribers.ofFile(path, new OpenOption[] {null, CREATE}));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   146
        assertThrows(NPE, () -> BodySubscribers.ofFile(null, (OpenOption[])null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   147
        assertThrows(NPE, () -> BodySubscribers.ofString(null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   148
        assertThrows(NPE, () -> BodySubscribers.buffering(null, 1));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   149
        assertThrows(IAE, () -> BodySubscribers.buffering(new NoOpSubscriber(), 0));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   150
        assertThrows(IAE, () -> BodySubscribers.buffering(new NoOpSubscriber(), -1));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   151
        assertThrows(IAE, () -> BodySubscribers.buffering(new NoOpSubscriber(), Integer.MIN_VALUE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   152
        assertThrows(NPE, () -> BodySubscribers.mapping(null, Function.identity()));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   153
        assertThrows(NPE, () -> BodySubscribers.mapping(BodySubscribers.ofByteArray(), null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   154
        assertThrows(NPE, () -> BodySubscribers.mapping(null, null));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   155
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   156
        // implementation specific exceptions
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   157
        assertThrows(IAE, () -> BodySubscribers.ofFile(path, READ));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   158
        assertThrows(IAE, () -> BodySubscribers.ofFile(path, DELETE_ON_CLOSE));
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   159
        assertThrows(IAE, () -> BodySubscribers.ofFile(path, READ, DELETE_ON_CLOSE));
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   160
    }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   161
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   162
    static class NoOpHandler implements BodyHandler<Void> {
49765
ee6f7a61f3a5 8197564: HTTP Client implementation
chegar
parents: 48379
diff changeset
   163
        @Override public BodySubscriber<Void> apply(ResponseInfo rinfo) { return null; }
48379
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   164
    }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   165
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   166
    static class NoOpSubscriber implements BodySubscriber<Void> {
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   167
        @Override public void onSubscribe(Flow.Subscription subscription) { }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   168
        @Override public void onNext(List<ByteBuffer> item) { }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   169
        @Override public void onError(Throwable throwable) { }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   170
        @Override public void onComplete() { }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   171
        @Override public CompletableFuture<Void> getBody() { return null; }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   172
    }
5382baab8371 8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
diff changeset
   173
}