Skip to content

Commit

Permalink
8266460: java.io tests fail on null stream with upgraded jtreg/TestNG
Browse files Browse the repository at this point in the history
Reviewed-by: goetz
Backport-of: e840597
  • Loading branch information
gdams authored and GoeLin committed Jul 21, 2022
1 parent 533a4e6 commit 16a84de
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 107 deletions.
56 changes: 27 additions & 29 deletions test/jdk/java/io/InputStream/NullInputStream.java
@@ -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
Expand All @@ -21,12 +21,14 @@
* questions.
*/

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

import java.io.ByteArrayOutputStream;
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.*;

/*
Expand All @@ -39,13 +41,9 @@ public class NullInputStream {
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();
Expand All @@ -54,7 +52,7 @@ public static void openAndCloseStream() {
}
}

@AfterGroups(groups="open")
@AfterClass
public static void closeStream() {
try {
openStream.close();
Expand All @@ -63,12 +61,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");
Expand All @@ -77,7 +75,7 @@ public static void testAvailable() {
}
}

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

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

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

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

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

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

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

@Test(groups = "closed")
@Test
public static void testAvailableClosed() {
try {
closedStream.available();
Expand All @@ -164,7 +162,7 @@ public static void testAvailableClosed() {
}
}

@Test(groups = "closed")
@Test
public static void testReadClosed() {
try {
closedStream.read();
Expand All @@ -173,7 +171,7 @@ public static void testReadClosed() {
}
}

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

@Test(groups = "closed")
@Test
public static void testReadAllBytesClosed() {
try {
closedStream.readAllBytes();
Expand All @@ -191,7 +189,7 @@ public static void testReadAllBytesClosed() {
}
}

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

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

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

@Test(groups = "closed")
@Test
public static void testTransferToClosed() {
try {
closedStream.transferTo(new ByteArrayOutputStream(7));
Expand Down
33 changes: 16 additions & 17 deletions test/jdk/java/io/OutputStream/NullOutputStream.java
@@ -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
Expand All @@ -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
Expand All @@ -38,13 +41,9 @@ public class NullOutputStream {
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();
Expand All @@ -53,7 +52,7 @@ public static void openAndCloseStream() {
}
}

@AfterGroups(groups="open")
@AfterClass
public static void closeStream() {
try {
openStream.close();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -86,7 +85,7 @@ public static void testWriteBII() {
}
}

@Test(groups="closed")
@Test
public static void testWriteClosed() {
try {
closedStream.write(62832);
Expand All @@ -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);
Expand Down

1 comment on commit 16a84de

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.