Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/OutputStream/NullOutputStream.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.OutputStream;
30
31
import static org.testng.Assert.assertNotNull;
32
import static org.testng.Assert.fail;
33
34
/*
35
* @test
36
* @bug 4358774
37
* @run testng NullOutputStream
38
* @summary Check for expected behavior of OutputStream.nullOutputStream().
39
*/
40
public class NullOutputStream {
41
private static OutputStream openStream;
42
private static OutputStream closedStream;
43
44
@BeforeClass
45
public static void setup() {
46
openStream = OutputStream.nullOutputStream();
47
closedStream = OutputStream.nullOutputStream();
48
try {
49
closedStream.close();
50
} catch (IOException e) {
51
fail("Unexpected IOException");
52
}
53
}
54
55
@AfterClass
56
public static void closeStream() {
57
try {
58
openStream.close();
59
} catch (IOException e) {
60
fail("Unexpected IOException");
61
}
62
}
63
64
@Test
65
public static void testOpen() {
66
assertNotNull(openStream,
67
"OutputStream.nullOutputStream() returned null");
68
}
69
70
@Test
71
public static void testWrite() {
72
try {
73
openStream.write(62832);
74
} catch (IOException e) {
75
fail("Unexpected IOException");
76
}
77
}
78
79
@Test
80
public static void testWriteBII() {
81
try {
82
openStream.write(new byte[] {(byte)6}, 0, 1);
83
} catch (Exception e) {
84
fail("Unexpected IOException");
85
}
86
}
87
88
@Test
89
public static void testWriteClosed() {
90
try {
91
closedStream.write(62832);
92
fail("Expected IOException not thrown");
93
} catch (IOException e) {
94
}
95
}
96
97
@Test
98
public static void testWriteBIIClosed() {
99
try {
100
closedStream.write(new byte[] {(byte)6}, 0, 1);
101
fail("Expected IOException not thrown");
102
} catch (IOException e) {
103
}
104
}
105
}
106
107