Navigation Menu

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: bpb
  • Loading branch information
Lance Andersen committed May 6, 2021
1 parent fcedfc8 commit e840597
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 110 deletions.
62 changes: 30 additions & 32 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,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.*;

/*
Expand All @@ -40,13 +42,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 @@ -55,7 +53,7 @@ public static void openAndCloseStream() {
}
}

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

@Test(groups = "open")
@Test
public static void testRead() {
try {
assertEquals(-1, openStream.read(), "read() != -1");
Expand All @@ -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),
Expand All @@ -97,7 +95,7 @@ public static void testReadBII() {
}
}

@Test(groups = "open")
@Test
public static void testReadAllBytes() {
try {
assertEquals(0, openStream.readAllBytes().length,
Expand All @@ -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),
Expand All @@ -117,7 +115,7 @@ public static void testReadNBytes() {
}
}

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

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

@Test(groups = "open")
@Test
public static void testSkipNBytes() {
try {
openStream.skipNBytes(-1);
Expand All @@ -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)),
Expand All @@ -171,7 +169,7 @@ public static void testTransferTo() {
}
}

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

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

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

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

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

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

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

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

@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 e840597

@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.