|
1 | 1 | /* |
2 | | - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
21 | 21 | * questions. |
22 | 22 | */ |
23 | 23 |
|
24 | | -import java.io.FileNotFoundException; |
25 | 24 | import java.nio.ByteBuffer; |
26 | 25 | import java.nio.file.Files; |
27 | 26 | import java.nio.file.Path; |
|
30 | 29 | import java.util.List; |
31 | 30 | import java.util.concurrent.CompletableFuture; |
32 | 31 | import java.util.concurrent.Flow; |
33 | | -import java.net.http.HttpHeaders; |
34 | | -import java.net.http.HttpRequest.BodyPublishers; |
35 | 32 | import java.net.http.HttpResponse.BodyHandler; |
36 | 33 | import java.net.http.HttpResponse.ResponseInfo; |
37 | 34 | import java.net.http.HttpResponse.BodyHandlers; |
38 | 35 | import java.net.http.HttpResponse.BodySubscriber; |
39 | 36 | import java.net.http.HttpResponse.BodySubscribers; |
40 | 37 | import java.util.function.Function; |
41 | | -import org.testng.annotations.DataProvider; |
| 38 | + |
42 | 39 | import org.testng.annotations.Test; |
43 | | -import static java.nio.charset.StandardCharsets.UTF_8; |
| 40 | + |
44 | 41 | import static java.nio.file.StandardOpenOption.CREATE; |
45 | 42 | import static java.nio.file.StandardOpenOption.DELETE_ON_CLOSE; |
46 | 43 | import static java.nio.file.StandardOpenOption.WRITE; |
|
49 | 46 |
|
50 | 47 | /* |
51 | 48 | * @test |
52 | | - * @summary Basic tests for API specified exceptions from Publisher, Handler, |
| 49 | + * @summary Basic tests for API specified exceptions from Handler, |
53 | 50 | * and Subscriber convenience static factory methods. |
54 | | - * @run testng SubscriberPublisherAPIExceptions |
| 51 | + * @run testng SubscriberAPIExceptions |
55 | 52 | */ |
56 | 53 |
|
57 | | -public class SubscriberPublisherAPIExceptions { |
| 54 | +public class SubscriberAPIExceptions { |
58 | 55 |
|
59 | 56 | static final Class<NullPointerException> NPE = NullPointerException.class; |
60 | 57 | static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class; |
61 | 58 | static final Class<IndexOutOfBoundsException> IOB = IndexOutOfBoundsException.class; |
62 | 59 |
|
63 | | - @Test |
64 | | - public void publisherAPIExceptions() { |
65 | | - assertThrows(NPE, () -> BodyPublishers.ofByteArray(null)); |
66 | | - assertThrows(NPE, () -> BodyPublishers.ofByteArray(null, 0, 1)); |
67 | | - assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100], 0, 101)); |
68 | | - assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100], 1, 100)); |
69 | | - assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100], -1, 10)); |
70 | | - assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[100], 99, 2)); |
71 | | - assertThrows(IOB, () -> BodyPublishers.ofByteArray(new byte[1], -100, 1)); |
72 | | - assertThrows(NPE, () -> BodyPublishers.ofByteArray(null)); |
73 | | - assertThrows(NPE, () -> BodyPublishers.ofFile(null)); |
74 | | - assertThrows(NPE, () -> BodyPublishers.ofInputStream(null)); |
75 | | - assertThrows(NPE, () -> BodyPublishers.ofString(null)); |
76 | | - assertThrows(NPE, () -> BodyPublishers.ofString("A", null)); |
77 | | - assertThrows(NPE, () -> BodyPublishers.ofString(null, UTF_8)); |
78 | | - assertThrows(NPE, () -> BodyPublishers.ofString(null, null)); |
79 | | - } |
80 | | - |
81 | | - @DataProvider(name = "nonExistentFiles") |
82 | | - public Object[][] nonExistentFiles() { |
83 | | - List<Path> paths = List.of(Paths.get("doesNotExist"), |
84 | | - Paths.get("tsixEtoNseod"), |
85 | | - Paths.get("doesNotExist2")); |
86 | | - paths.forEach(p -> { |
87 | | - if (Files.exists(p)) |
88 | | - throw new AssertionError("Unexpected " + p); |
89 | | - }); |
90 | | - |
91 | | - return paths.stream().map(p -> new Object[] { p }).toArray(Object[][]::new); |
92 | | - } |
93 | | - |
94 | | - @Test(dataProvider = "nonExistentFiles", expectedExceptions = FileNotFoundException.class) |
95 | | - public void fromFileCheck(Path path) throws Exception { |
96 | | - BodyPublishers.ofFile(path); |
97 | | - } |
98 | | - |
99 | 60 | @Test |
100 | 61 | public void handlerAPIExceptions() throws Exception { |
101 | 62 | Path path = Paths.get(".").resolve("tt"); |
|
0 commit comments