Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Reader/NullReader.java
41152 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 java.io.Reader;
25
import java.io.IOException;
26
import java.io.StringWriter;
27
import java.nio.CharBuffer;
28
import java.nio.ReadOnlyBufferException;
29
30
import org.testng.annotations.*;
31
32
import static org.testng.Assert.*;
33
34
/*
35
* @test
36
* @bug 8196298 8204930
37
* @run testng NullReader
38
* @summary Check for expected behavior of Reader.nullReader().
39
*/
40
public class NullReader {
41
private static Reader openReader;
42
private static Reader closedReader;
43
44
@BeforeClass
45
public static void setup() throws IOException {
46
openReader = Reader.nullReader();
47
closedReader = Reader.nullReader();
48
closedReader.close();
49
}
50
51
@AfterClass
52
public static void closeStream() throws IOException {
53
openReader.close();
54
}
55
56
@Test
57
public static void testOpen() {
58
assertNotNull(openReader, "Reader.nullReader() returned null");
59
}
60
61
@Test
62
public static void testRead() throws IOException {
63
assertEquals(-1, openReader.read(), "read() != -1");
64
}
65
66
@Test
67
public static void testReadBII() throws IOException {
68
assertEquals(-1, openReader.read(new char[1], 0, 1),
69
"read(char[],int,int) != -1");
70
}
71
72
@Test
73
public static void testReadBIILenZero() throws IOException {
74
assertEquals(0, openReader.read(new char[1], 0, 0),
75
"read(char[],int,int) != 0");
76
}
77
78
@Test
79
public static void testReadCharBuffer() throws IOException {
80
CharBuffer charBuffer = CharBuffer.allocate(1);
81
assertEquals(-1, openReader.read(charBuffer),
82
"read(CharBuffer) != -1");
83
}
84
85
@Test
86
public static void testReadCharBufferZeroRemaining() throws IOException {
87
CharBuffer charBuffer = CharBuffer.allocate(0);
88
assertEquals(0, openReader.read(charBuffer),
89
"read(CharBuffer) != 0");
90
}
91
92
@Test
93
public static void testReady() throws IOException {
94
assertFalse(openReader.ready());
95
}
96
97
@Test
98
public static void testSkip() throws IOException {
99
assertEquals(0, openReader.skip(1), "skip() != 0");
100
}
101
102
@Test
103
public static void testTransferTo() throws IOException {
104
assertEquals(0, openReader.transferTo(new StringWriter(7)),
105
"transferTo() != 0");
106
}
107
108
@Test(expectedExceptions = IOException.class)
109
public static void testReadClosed() throws IOException {
110
closedReader.read();
111
}
112
113
@Test(expectedExceptions = IOException.class)
114
public static void testReadBIIClosed() throws IOException {
115
closedReader.read(new char[1], 0, 1);
116
}
117
118
@Test(expectedExceptions = IOException.class)
119
public static void testReadCharBufferClosed() throws IOException {
120
CharBuffer charBuffer = CharBuffer.allocate(0);
121
closedReader.read(charBuffer);
122
}
123
124
@Test(expectedExceptions = IOException.class)
125
public static void testReadCharBufferZeroRemainingClosed() throws IOException {
126
CharBuffer charBuffer = CharBuffer.allocate(0);
127
closedReader.read(charBuffer);
128
}
129
130
@Test(expectedExceptions = IOException.class)
131
public static void testReadyClosed() throws IOException {
132
closedReader.ready();
133
}
134
135
@Test(expectedExceptions = IOException.class)
136
public static void testSkipClosed() throws IOException {
137
closedReader.skip(1);
138
}
139
140
@Test(expectedExceptions = IOException.class)
141
public static void testTransferToClosed() throws IOException {
142
closedReader.transferTo(new StringWriter(7));
143
}
144
}
145
146