Path: blob/master/test/jdk/java/io/OutputStream/NullOutputStream.java
41149 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import org.testng.annotations.AfterClass;24import org.testng.annotations.BeforeClass;25import org.testng.annotations.Test;2627import java.io.IOException;28import java.io.OutputStream;2930import static org.testng.Assert.assertNotNull;31import static org.testng.Assert.fail;3233/*34* @test35* @bug 435877436* @run testng NullOutputStream37* @summary Check for expected behavior of OutputStream.nullOutputStream().38*/39public class NullOutputStream {40private static OutputStream openStream;41private static OutputStream closedStream;4243@BeforeClass44public static void setup() {45openStream = OutputStream.nullOutputStream();46closedStream = OutputStream.nullOutputStream();47try {48closedStream.close();49} catch (IOException e) {50fail("Unexpected IOException");51}52}5354@AfterClass55public static void closeStream() {56try {57openStream.close();58} catch (IOException e) {59fail("Unexpected IOException");60}61}6263@Test64public static void testOpen() {65assertNotNull(openStream,66"OutputStream.nullOutputStream() returned null");67}6869@Test70public static void testWrite() {71try {72openStream.write(62832);73} catch (IOException e) {74fail("Unexpected IOException");75}76}7778@Test79public static void testWriteBII() {80try {81openStream.write(new byte[] {(byte)6}, 0, 1);82} catch (Exception e) {83fail("Unexpected IOException");84}85}8687@Test88public static void testWriteClosed() {89try {90closedStream.write(62832);91fail("Expected IOException not thrown");92} catch (IOException e) {93}94}9596@Test97public static void testWriteBIIClosed() {98try {99closedStream.write(new byte[] {(byte)6}, 0, 1);100fail("Expected IOException not thrown");101} catch (IOException e) {102}103}104}105106107