< prev index next >

test/jdk/java/io/InputStream/NullInputStream.java

Print this page




   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.ByteArrayOutputStream;

  25 import java.io.InputStream;
  26 import java.io.IOException;
  27 import org.testng.annotations.AfterGroups;
  28 import org.testng.annotations.BeforeGroups;
  29 import org.testng.annotations.Test;
  30 import static org.testng.Assert.*;
  31 
  32 /*
  33  * @test
  34  * @bug 4358774 8139206
  35  * @run testng NullInputStream
  36  * @summary Check for expected behavior of InputStream.nullInputStream().
  37  */
  38 public class NullInputStream {
  39     private static InputStream openStream;
  40     private static InputStream closedStream;
  41 
  42     @BeforeGroups(groups="open")
  43     public static void openStream() {
  44         openStream = InputStream.nullInputStream();
  45     }
  46 
  47     @BeforeGroups(groups="closed")
  48     public static void openAndCloseStream() {
  49         closedStream = InputStream.nullInputStream();
  50         try {
  51            closedStream.close();
  52         } catch (IOException e) {
  53             fail("Unexpected IOException");
  54         }


 129         try {
 130             assertEquals(0, openStream.readNBytes(0).length,
 131                 "readNBytes(0, false) != 0");
 132             assertEquals(0, openStream.readNBytes(1).length,
 133                 "readNBytes(1, false) != 0");
 134         } catch (IOException ioe) {
 135             fail("Unexpected IOException");
 136         }
 137     }
 138 
 139     @Test(groups = "open")
 140     public static void testSkip() {
 141         try {
 142             assertEquals(0, openStream.skip(1), "skip() != 0");
 143         } catch (IOException ioe) {
 144             fail("Unexpected IOException");
 145         }
 146     }
 147 
 148     @Test(groups = "open")















 149     public static void testTransferTo() {
 150         try {
 151             assertEquals(0, openStream.transferTo(new ByteArrayOutputStream(7)),
 152                 "transferTo() != 0");
 153         } catch (IOException ioe) {
 154             fail("Unexpected IOException");
 155         }
 156     }
 157 
 158     @Test(groups = "closed")
 159     public static void testAvailableClosed() {
 160         try {
 161             closedStream.available();
 162             fail("Expected IOException not thrown");
 163         } catch (IOException e) {
 164         }
 165     }
 166 
 167     @Test(groups = "closed")
 168     public static void testReadClosed() {


 202 
 203     @Test(groups = "closed")
 204     public static void testReadNBytesWithLengthClosed() {
 205         try {
 206             closedStream.readNBytes(1);
 207             fail("Expected IOException not thrown");
 208         } catch (IOException e) {
 209         }
 210     }
 211 
 212     @Test(groups = "closed")
 213     public static void testSkipClosed() {
 214         try {
 215             closedStream.skip(1);
 216             fail("Expected IOException not thrown");
 217         } catch (IOException e) {
 218         }
 219     }
 220 
 221     @Test(groups = "closed")









 222     public static void testTransferToClosed() {
 223         try {
 224             closedStream.transferTo(new ByteArrayOutputStream(7));
 225             fail("Expected IOException not thrown");
 226         } catch (IOException e) {
 227         }
 228     }
 229 }


   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.ByteArrayOutputStream;
  25 import java.io.EOFException;
  26 import java.io.InputStream;
  27 import java.io.IOException;
  28 import org.testng.annotations.AfterGroups;
  29 import org.testng.annotations.BeforeGroups;
  30 import org.testng.annotations.Test;
  31 import static org.testng.Assert.*;
  32 
  33 /*
  34  * @test
  35  * @bug 4358774 6516099 8139206
  36  * @run testng NullInputStream
  37  * @summary Check for expected behavior of InputStream.nullInputStream().
  38  */
  39 public class NullInputStream {
  40     private static InputStream openStream;
  41     private static InputStream closedStream;
  42 
  43     @BeforeGroups(groups="open")
  44     public static void openStream() {
  45         openStream = InputStream.nullInputStream();
  46     }
  47 
  48     @BeforeGroups(groups="closed")
  49     public static void openAndCloseStream() {
  50         closedStream = InputStream.nullInputStream();
  51         try {
  52            closedStream.close();
  53         } catch (IOException e) {
  54             fail("Unexpected IOException");
  55         }


 130         try {
 131             assertEquals(0, openStream.readNBytes(0).length,
 132                 "readNBytes(0, false) != 0");
 133             assertEquals(0, openStream.readNBytes(1).length,
 134                 "readNBytes(1, false) != 0");
 135         } catch (IOException ioe) {
 136             fail("Unexpected IOException");
 137         }
 138     }
 139 
 140     @Test(groups = "open")
 141     public static void testSkip() {
 142         try {
 143             assertEquals(0, openStream.skip(1), "skip() != 0");
 144         } catch (IOException ioe) {
 145             fail("Unexpected IOException");
 146         }
 147     }
 148 
 149     @Test(groups = "open")
 150     public static void testSkipNBytes() {
 151         try {
 152             openStream.skipNBytes(-1);
 153             openStream.skipNBytes(0);
 154         } catch (IOException ioe) {
 155             fail("Unexpected IOException");
 156         }
 157     }
 158 
 159     @Test(groups = "open", expectedExceptions = EOFException.class)
 160     public static void testSkipNBytesEOF() throws IOException {
 161         openStream.skipNBytes(1);
 162     }
 163 
 164     @Test(groups = "open")
 165     public static void testTransferTo() {
 166         try {
 167             assertEquals(0, openStream.transferTo(new ByteArrayOutputStream(7)),
 168                 "transferTo() != 0");
 169         } catch (IOException ioe) {
 170             fail("Unexpected IOException");
 171         }
 172     }
 173 
 174     @Test(groups = "closed")
 175     public static void testAvailableClosed() {
 176         try {
 177             closedStream.available();
 178             fail("Expected IOException not thrown");
 179         } catch (IOException e) {
 180         }
 181     }
 182 
 183     @Test(groups = "closed")
 184     public static void testReadClosed() {


 218 
 219     @Test(groups = "closed")
 220     public static void testReadNBytesWithLengthClosed() {
 221         try {
 222             closedStream.readNBytes(1);
 223             fail("Expected IOException not thrown");
 224         } catch (IOException e) {
 225         }
 226     }
 227 
 228     @Test(groups = "closed")
 229     public static void testSkipClosed() {
 230         try {
 231             closedStream.skip(1);
 232             fail("Expected IOException not thrown");
 233         } catch (IOException e) {
 234         }
 235     }
 236 
 237     @Test(groups = "closed")
 238     public static void testSkipNBytesClosed() {
 239         try {
 240             closedStream.skipNBytes(1);
 241             fail("Expected IOException not thrown");
 242         } catch (IOException e) {
 243         }
 244     }
 245 
 246     @Test(groups = "closed")
 247     public static void testTransferToClosed() {
 248         try {
 249             closedStream.transferTo(new ByteArrayOutputStream(7));
 250             fail("Expected IOException not thrown");
 251         } catch (IOException e) {
 252         }
 253     }
 254 }
< prev index next >