test/jdk/java/io/InputStream/NullInputStream.java
changeset 48696 917868f73209
parent 48461 6a1c3a5e04f3
child 52860 8dd8965df7f6
equal deleted inserted replaced
48695:a7ce228abcd7 48696:917868f73209
    29 import org.testng.annotations.Test;
    29 import org.testng.annotations.Test;
    30 import static org.testng.Assert.*;
    30 import static org.testng.Assert.*;
    31 
    31 
    32 /*
    32 /*
    33  * @test
    33  * @test
    34  * @bug 4358774
    34  * @bug 4358774 8139206
    35  * @run testng NullInputStream
    35  * @run testng NullInputStream
    36  * @summary Check for expected behavior of InputStream.nullInputStream().
    36  * @summary Check for expected behavior of InputStream.nullInputStream().
    37  */
    37  */
    38 public class NullInputStream {
    38 public class NullInputStream {
    39     private static InputStream openStream;
    39     private static InputStream openStream;
   105             fail("Unexpected IOException");
   105             fail("Unexpected IOException");
   106         }
   106         }
   107     }
   107     }
   108 
   108 
   109     @Test(groups = "open")
   109     @Test(groups = "open")
   110     public static void testreadNBytes() {
   110     public static void testReadNBytes() {
   111         try {
   111         try {
   112             assertEquals(0, openStream.readNBytes(new byte[1], 0, 1),
   112             assertEquals(0, openStream.readNBytes(new byte[1], 0, 1),
   113                 "readNBytes(byte[],int,int) != 0");
   113                 "readNBytes(byte[],int,int) != 0");
   114         } catch (IOException ioe) {
   114         } catch (IOException ioe) {
   115             fail("Unexpected IOException");
   115             fail("Unexpected IOException");
   116         }
   116         }
   117     }
   117     }
   118 
   118 
   119     @Test(groups = "open")
   119     @Test(groups = "open")
       
   120     public static void testReadNBytesWithLength() {
       
   121         try {
       
   122             assertEquals(0, openStream.readNBytes(-1).length,
       
   123                 "readNBytes(-1) != 0");
       
   124             fail("Expected IllegalArgumentException not thrown");
       
   125         } catch (IllegalArgumentException iae) {
       
   126         } catch (IOException ioe) {
       
   127             fail("Unexpected IOException");
       
   128         }
       
   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")
   120     public static void testSkip() {
   140     public static void testSkip() {
   121         try {
   141         try {
   122             assertEquals(0, openStream.skip(1), "skip() != 0");
   142             assertEquals(0, openStream.skip(1), "skip() != 0");
   123         } catch (IOException ioe) {
   143         } catch (IOException ioe) {
   124             fail("Unexpected IOException");
   144             fail("Unexpected IOException");
   179         } catch (IOException e) {
   199         } catch (IOException e) {
   180         }
   200         }
   181     }
   201     }
   182 
   202 
   183     @Test(groups = "closed")
   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")
   184     public static void testSkipClosed() {
   213     public static void testSkipClosed() {
   185         try {
   214         try {
   186             closedStream.skip(1);
   215             closedStream.skip(1);
   187             fail("Expected IOException not thrown");
   216             fail("Expected IOException not thrown");
   188         } catch (IOException e) {
   217         } catch (IOException e) {