Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/InputStream/NullInputStream.java
41149 views
1
/*
2
* Copyright (c) 2018, 2021, 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 org.testng.annotations.AfterClass;
25
import org.testng.annotations.BeforeClass;
26
import org.testng.annotations.Test;
27
28
import java.io.ByteArrayOutputStream;
29
import java.io.EOFException;
30
import java.io.IOException;
31
import java.io.InputStream;
32
33
import static org.testng.Assert.*;
34
35
/*
36
* @test
37
* @bug 4358774 6516099 8139206
38
* @run testng NullInputStream
39
* @summary Check for expected behavior of InputStream.nullInputStream().
40
*/
41
public class NullInputStream {
42
private static InputStream openStream;
43
private static InputStream closedStream;
44
45
@BeforeClass
46
public static void setup() {
47
openStream = InputStream.nullInputStream();
48
closedStream = InputStream.nullInputStream();
49
try {
50
closedStream.close();
51
} catch (IOException e) {
52
fail("Unexpected IOException");
53
}
54
}
55
56
@AfterClass
57
public static void closeStream() {
58
try {
59
openStream.close();
60
} catch (IOException e) {
61
fail("Unexpected IOException");
62
}
63
}
64
65
@Test
66
public static void testOpen() {
67
assertNotNull(openStream, "InputStream.nullInputStream() returned null");
68
}
69
70
@Test
71
public static void testAvailable() {
72
try {
73
assertEquals(0, openStream.available(), "available() != 0");
74
} catch (IOException ioe) {
75
fail("Unexpected IOException");
76
}
77
}
78
79
@Test
80
public static void testRead() {
81
try {
82
assertEquals(-1, openStream.read(), "read() != -1");
83
} catch (IOException ioe) {
84
fail("Unexpected IOException");
85
}
86
}
87
88
@Test
89
public static void testReadBII() {
90
try {
91
assertEquals(-1, openStream.read(new byte[1], 0, 1),
92
"read(byte[],int,int) != -1");
93
} catch (IOException ioe) {
94
fail("Unexpected IOException");
95
}
96
}
97
98
@Test
99
public static void testReadAllBytes() {
100
try {
101
assertEquals(0, openStream.readAllBytes().length,
102
"readAllBytes().length != 0");
103
} catch (IOException ioe) {
104
fail("Unexpected IOException");
105
}
106
}
107
108
@Test
109
public static void testReadNBytes() {
110
try {
111
assertEquals(0, openStream.readNBytes(new byte[1], 0, 1),
112
"readNBytes(byte[],int,int) != 0");
113
} catch (IOException ioe) {
114
fail("Unexpected IOException");
115
}
116
}
117
118
@Test
119
public static void testReadNBytesWithLength() {
120
try {
121
assertEquals(0, openStream.readNBytes(-1).length,
122
"readNBytes(-1) != 0");
123
fail("Expected IllegalArgumentException not thrown");
124
} catch (IllegalArgumentException iae) {
125
} catch (IOException ioe) {
126
fail("Unexpected IOException");
127
}
128
try {
129
assertEquals(0, openStream.readNBytes(0).length,
130
"readNBytes(0, false) != 0");
131
assertEquals(0, openStream.readNBytes(1).length,
132
"readNBytes(1, false) != 0");
133
} catch (IOException ioe) {
134
fail("Unexpected IOException");
135
}
136
}
137
138
@Test
139
public static void testSkip() {
140
try {
141
assertEquals(0, openStream.skip(1), "skip() != 0");
142
} catch (IOException ioe) {
143
fail("Unexpected IOException");
144
}
145
}
146
147
@Test
148
public static void testSkipNBytes() {
149
try {
150
openStream.skipNBytes(-1);
151
openStream.skipNBytes(0);
152
} catch (IOException ioe) {
153
fail("Unexpected IOException");
154
}
155
}
156
157
@Test(expectedExceptions = EOFException.class)
158
public static void testSkipNBytesEOF() throws IOException {
159
openStream.skipNBytes(1);
160
}
161
162
@Test
163
public static void testTransferTo() {
164
try {
165
assertEquals(0, openStream.transferTo(new ByteArrayOutputStream(7)),
166
"transferTo() != 0");
167
} catch (IOException ioe) {
168
fail("Unexpected IOException");
169
}
170
}
171
172
@Test
173
public static void testAvailableClosed() {
174
try {
175
closedStream.available();
176
fail("Expected IOException not thrown");
177
} catch (IOException e) {
178
}
179
}
180
181
@Test
182
public static void testReadClosed() {
183
try {
184
closedStream.read();
185
fail("Expected IOException not thrown");
186
} catch (IOException e) {
187
}
188
}
189
190
@Test
191
public static void testReadBIIClosed() {
192
try {
193
closedStream.read(new byte[1], 0, 1);
194
fail("Expected IOException not thrown");
195
} catch (IOException e) {
196
}
197
}
198
199
@Test
200
public static void testReadAllBytesClosed() {
201
try {
202
closedStream.readAllBytes();
203
fail("Expected IOException not thrown");
204
} catch (IOException e) {
205
}
206
}
207
208
@Test
209
public static void testReadNBytesClosed() {
210
try {
211
closedStream.readNBytes(new byte[1], 0, 1);
212
fail("Expected IOException not thrown");
213
} catch (IOException e) {
214
}
215
}
216
217
@Test
218
public static void testReadNBytesWithLengthClosed() {
219
try {
220
closedStream.readNBytes(1);
221
fail("Expected IOException not thrown");
222
} catch (IOException e) {
223
}
224
}
225
226
@Test
227
public static void testSkipClosed() {
228
try {
229
closedStream.skip(1);
230
fail("Expected IOException not thrown");
231
} catch (IOException e) {
232
}
233
}
234
235
@Test
236
public static void testSkipNBytesClosed() {
237
try {
238
closedStream.skipNBytes(1);
239
fail("Expected IOException not thrown");
240
} catch (IOException e) {
241
}
242
}
243
244
@Test
245
public static void testTransferToClosed() {
246
try {
247
closedStream.transferTo(new ByteArrayOutputStream(7));
248
fail("Expected IOException not thrown");
249
} catch (IOException e) {
250
}
251
}
252
}
253
254