Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Writer/NullWriter.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.IOException;
29
import java.io.Writer;
30
31
import static org.testng.Assert.assertNotNull;
32
import static org.testng.Assert.assertSame;
33
34
/*
35
* @test
36
* @bug 8196298
37
* @run testng NullWriter
38
* @summary Check for expected behavior of Writer.nullWriter().
39
*/
40
public class NullWriter {
41
private static Writer openWriter;
42
private static Writer closedWriter;
43
44
@BeforeClass
45
public static void setup() throws IOException {
46
openWriter = Writer.nullWriter();
47
closedWriter = Writer.nullWriter();
48
closedWriter.close();
49
}
50
51
@AfterClass
52
public static void closeStream() throws IOException {
53
openWriter.close();
54
}
55
56
@Test
57
public static void testOpen() {
58
assertNotNull(openWriter, "Writer.nullWriter() returned null");
59
}
60
61
@Test
62
public static void testAppendChar() throws IOException {
63
assertSame(openWriter, openWriter.append('x'));
64
}
65
66
@Test
67
public static void testAppendCharSequence() throws IOException {
68
CharSequence cs = "abc";
69
assertSame(openWriter, openWriter.append(cs));
70
}
71
72
@Test
73
public static void testAppendCharSequenceNull() throws IOException {
74
assertSame(openWriter, openWriter.append(null));
75
}
76
77
@Test
78
public static void testAppendCharSequenceII() throws IOException {
79
CharSequence cs = "abc";
80
assertSame(openWriter, openWriter.append(cs, 0, 1));
81
}
82
83
@Test
84
public static void testAppendCharSequenceIINull() throws IOException {
85
assertSame(openWriter, openWriter.append(null, 2, 1));
86
}
87
88
@Test
89
public static void testFlush() throws IOException {
90
openWriter.flush();
91
}
92
93
@Test
94
public static void testWrite() throws IOException {
95
openWriter.write(62832);
96
}
97
98
@Test
99
public static void testWriteString() throws IOException {
100
openWriter.write("");
101
}
102
103
@Test
104
public static void testWriteStringII() throws IOException {
105
openWriter.write("", 0, 0);
106
}
107
108
@Test
109
public static void testWriteBII() throws IOException, Exception {
110
openWriter.write(new char[]{(char) 6}, 0, 1);
111
}
112
113
@Test(expectedExceptions = IOException.class)
114
public static void testAppendCharClosed() throws IOException {
115
closedWriter.append('x');
116
}
117
118
@Test(expectedExceptions = IOException.class)
119
public static void testAppendCharSequenceClosed() throws IOException {
120
CharSequence cs = "abc";
121
closedWriter.append(cs);
122
}
123
124
@Test(expectedExceptions = IOException.class)
125
public static void testAppendCharSequenceNullClosed() throws IOException {
126
closedWriter.append(null);
127
}
128
129
@Test(expectedExceptions = IOException.class)
130
public static void testAppendCharSequenceIIClosed() throws IOException {
131
CharSequence cs = "abc";
132
closedWriter.append(cs, 0, 1);
133
}
134
135
@Test(expectedExceptions = IOException.class)
136
public static void testAppendCharSequenceIINullClosed() throws IOException {
137
closedWriter.append(null, 2, 1);
138
}
139
140
@Test(expectedExceptions = IOException.class)
141
public static void testFlushClosed() throws IOException {
142
closedWriter.flush();
143
}
144
145
@Test(expectedExceptions = IOException.class)
146
public static void testWriteClosed() throws IOException {
147
closedWriter.write(62832);
148
}
149
150
@Test(expectedExceptions = IOException.class)
151
public static void testWriteStringClosed() throws IOException {
152
closedWriter.write("");
153
}
154
155
@Test(expectedExceptions = IOException.class)
156
public static void testWriteStringIIClosed() throws IOException {
157
closedWriter.write("", 0, 0);
158
}
159
160
@Test(expectedExceptions = IOException.class)
161
public static void testWriteBIIClosed() throws IOException {
162
closedWriter.write(new char[]{(char) 6}, 0, 1);
163
}
164
}
165
166