Skip to content
Permalink
Browse files
8266460: java.io tests fail on null stream with upgraded jtreg/TestNG
Reviewed-by: bpb
  • Loading branch information
Lance Andersen committed May 6, 2021
1 parent fcedfc8 commit e8405970b9998ff8f77bcf196f1456713a98c47f
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,13 +21,15 @@
* questions.
*/

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.InputStream;
import java.io.IOException;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.io.InputStream;

import static org.testng.Assert.*;

/*
@@ -40,13 +42,9 @@
private static InputStream openStream;
private static InputStream closedStream;

@BeforeGroups(groups="open")
public static void openStream() {
@BeforeClass
public static void setup() {
openStream = InputStream.nullInputStream();
}

@BeforeGroups(groups="closed")
public static void openAndCloseStream() {
closedStream = InputStream.nullInputStream();
try {
closedStream.close();
@@ -55,7 +53,7 @@ public static void openAndCloseStream() {
}
}

@AfterGroups(groups="open")
@AfterClass
public static void closeStream() {
try {
openStream.close();
@@ -64,12 +62,12 @@ public static void closeStream() {
}
}

@Test(groups = "open")
@Test
public static void testOpen() {
assertNotNull(openStream, "InputStream.nullInputStream() returned null");
}

@Test(groups = "open")
@Test
public static void testAvailable() {
try {
assertEquals(0, openStream.available(), "available() != 0");
@@ -78,7 +76,7 @@ public static void testAvailable() {
}
}

@Test(groups = "open")
@Test
public static void testRead() {
try {
assertEquals(-1, openStream.read(), "read() != -1");
@@ -87,7 +85,7 @@ public static void testRead() {
}
}

@Test(groups = "open")
@Test
public static void testReadBII() {
try {
assertEquals(-1, openStream.read(new byte[1], 0, 1),
@@ -97,7 +95,7 @@ public static void testReadBII() {
}
}

@Test(groups = "open")
@Test
public static void testReadAllBytes() {
try {
assertEquals(0, openStream.readAllBytes().length,
@@ -107,7 +105,7 @@ public static void testReadAllBytes() {
}
}

@Test(groups = "open")
@Test
public static void testReadNBytes() {
try {
assertEquals(0, openStream.readNBytes(new byte[1], 0, 1),
@@ -117,7 +115,7 @@ public static void testReadNBytes() {
}
}

@Test(groups = "open")
@Test
public static void testReadNBytesWithLength() {
try {
assertEquals(0, openStream.readNBytes(-1).length,
@@ -137,7 +135,7 @@ public static void testReadNBytesWithLength() {
}
}

@Test(groups = "open")
@Test
public static void testSkip() {
try {
assertEquals(0, openStream.skip(1), "skip() != 0");
@@ -146,7 +144,7 @@ public static void testSkip() {
}
}

@Test(groups = "open")
@Test
public static void testSkipNBytes() {
try {
openStream.skipNBytes(-1);
@@ -156,12 +154,12 @@ public static void testSkipNBytes() {
}
}

@Test(groups = "open", expectedExceptions = EOFException.class)
@Test(expectedExceptions = EOFException.class)
public static void testSkipNBytesEOF() throws IOException {
openStream.skipNBytes(1);
}

@Test(groups = "open")
@Test
public static void testTransferTo() {
try {
assertEquals(0, openStream.transferTo(new ByteArrayOutputStream(7)),
@@ -171,7 +169,7 @@ public static void testTransferTo() {
}
}

@Test(groups = "closed")
@Test
public static void testAvailableClosed() {
try {
closedStream.available();
@@ -180,7 +178,7 @@ public static void testAvailableClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testReadClosed() {
try {
closedStream.read();
@@ -189,7 +187,7 @@ public static void testReadClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testReadBIIClosed() {
try {
closedStream.read(new byte[1], 0, 1);
@@ -198,7 +196,7 @@ public static void testReadBIIClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testReadAllBytesClosed() {
try {
closedStream.readAllBytes();
@@ -207,7 +205,7 @@ public static void testReadAllBytesClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testReadNBytesClosed() {
try {
closedStream.readNBytes(new byte[1], 0, 1);
@@ -216,7 +214,7 @@ public static void testReadNBytesClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testReadNBytesWithLengthClosed() {
try {
closedStream.readNBytes(1);
@@ -225,7 +223,7 @@ public static void testReadNBytesWithLengthClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testSkipClosed() {
try {
closedStream.skip(1);
@@ -234,7 +232,7 @@ public static void testSkipClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testSkipNBytesClosed() {
try {
closedStream.skipNBytes(1);
@@ -243,7 +241,7 @@ public static void testSkipNBytesClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testTransferToClosed() {
try {
closedStream.transferTo(new ByteArrayOutputStream(7));
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,12 +21,15 @@
* questions.
*/

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.io.OutputStream;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;

/*
* @test
@@ -38,13 +41,9 @@
private static OutputStream openStream;
private static OutputStream closedStream;

@BeforeGroups(groups="open")
public static void openStream() {
@BeforeClass
public static void setup() {
openStream = OutputStream.nullOutputStream();
}

@BeforeGroups(groups="closed")
public static void openAndCloseStream() {
closedStream = OutputStream.nullOutputStream();
try {
closedStream.close();
@@ -53,7 +52,7 @@ public static void openAndCloseStream() {
}
}

@AfterGroups(groups="open")
@AfterClass
public static void closeStream() {
try {
openStream.close();
@@ -62,13 +61,13 @@ public static void closeStream() {
}
}

@Test(groups="open")
@Test
public static void testOpen() {
assertNotNull(openStream,
"OutputStream.nullOutputStream() returned null");
}

@Test(groups="open")
@Test
public static void testWrite() {
try {
openStream.write(62832);
@@ -77,7 +76,7 @@ public static void testWrite() {
}
}

@Test(groups="open")
@Test
public static void testWriteBII() {
try {
openStream.write(new byte[] {(byte)6}, 0, 1);
@@ -86,7 +85,7 @@ public static void testWriteBII() {
}
}

@Test(groups="closed")
@Test
public static void testWriteClosed() {
try {
closedStream.write(62832);
@@ -95,7 +94,7 @@ public static void testWriteClosed() {
}
}

@Test(groups="closed")
@Test
public static void testWriteBIIClosed() {
try {
closedStream.write(new byte[] {(byte)6}, 0, 1);

0 comments on commit e840597

Please sign in to comment.