Skip to content

Commit e840597

Browse files
author
Lance Andersen
committed
8266460: java.io tests fail on null stream with upgraded jtreg/TestNG
Reviewed-by: bpb
1 parent fcedfc8 commit e840597

File tree

4 files changed

+98
-110
lines changed

4 files changed

+98
-110
lines changed

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

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,13 +21,15 @@
2121
* questions.
2222
*/
2323

24+
import org.testng.annotations.AfterClass;
25+
import org.testng.annotations.BeforeClass;
26+
import org.testng.annotations.Test;
27+
2428
import java.io.ByteArrayOutputStream;
2529
import java.io.EOFException;
26-
import java.io.InputStream;
2730
import java.io.IOException;
28-
import org.testng.annotations.AfterGroups;
29-
import org.testng.annotations.BeforeGroups;
30-
import org.testng.annotations.Test;
31+
import java.io.InputStream;
32+
3133
import static org.testng.Assert.*;
3234

3335
/*
@@ -40,13 +42,9 @@ public class NullInputStream {
4042
private static InputStream openStream;
4143
private static InputStream closedStream;
4244

43-
@BeforeGroups(groups="open")
44-
public static void openStream() {
45+
@BeforeClass
46+
public static void setup() {
4547
openStream = InputStream.nullInputStream();
46-
}
47-
48-
@BeforeGroups(groups="closed")
49-
public static void openAndCloseStream() {
5048
closedStream = InputStream.nullInputStream();
5149
try {
5250
closedStream.close();
@@ -55,7 +53,7 @@ public static void openAndCloseStream() {
5553
}
5654
}
5755

58-
@AfterGroups(groups="open")
56+
@AfterClass
5957
public static void closeStream() {
6058
try {
6159
openStream.close();
@@ -64,12 +62,12 @@ public static void closeStream() {
6462
}
6563
}
6664

67-
@Test(groups = "open")
65+
@Test
6866
public static void testOpen() {
6967
assertNotNull(openStream, "InputStream.nullInputStream() returned null");
7068
}
7169

72-
@Test(groups = "open")
70+
@Test
7371
public static void testAvailable() {
7472
try {
7573
assertEquals(0, openStream.available(), "available() != 0");
@@ -78,7 +76,7 @@ public static void testAvailable() {
7876
}
7977
}
8078

81-
@Test(groups = "open")
79+
@Test
8280
public static void testRead() {
8381
try {
8482
assertEquals(-1, openStream.read(), "read() != -1");
@@ -87,7 +85,7 @@ public static void testRead() {
8785
}
8886
}
8987

90-
@Test(groups = "open")
88+
@Test
9189
public static void testReadBII() {
9290
try {
9391
assertEquals(-1, openStream.read(new byte[1], 0, 1),
@@ -97,7 +95,7 @@ public static void testReadBII() {
9795
}
9896
}
9997

100-
@Test(groups = "open")
98+
@Test
10199
public static void testReadAllBytes() {
102100
try {
103101
assertEquals(0, openStream.readAllBytes().length,
@@ -107,7 +105,7 @@ public static void testReadAllBytes() {
107105
}
108106
}
109107

110-
@Test(groups = "open")
108+
@Test
111109
public static void testReadNBytes() {
112110
try {
113111
assertEquals(0, openStream.readNBytes(new byte[1], 0, 1),
@@ -117,7 +115,7 @@ public static void testReadNBytes() {
117115
}
118116
}
119117

120-
@Test(groups = "open")
118+
@Test
121119
public static void testReadNBytesWithLength() {
122120
try {
123121
assertEquals(0, openStream.readNBytes(-1).length,
@@ -137,7 +135,7 @@ public static void testReadNBytesWithLength() {
137135
}
138136
}
139137

140-
@Test(groups = "open")
138+
@Test
141139
public static void testSkip() {
142140
try {
143141
assertEquals(0, openStream.skip(1), "skip() != 0");
@@ -146,7 +144,7 @@ public static void testSkip() {
146144
}
147145
}
148146

149-
@Test(groups = "open")
147+
@Test
150148
public static void testSkipNBytes() {
151149
try {
152150
openStream.skipNBytes(-1);
@@ -156,12 +154,12 @@ public static void testSkipNBytes() {
156154
}
157155
}
158156

159-
@Test(groups = "open", expectedExceptions = EOFException.class)
157+
@Test(expectedExceptions = EOFException.class)
160158
public static void testSkipNBytesEOF() throws IOException {
161159
openStream.skipNBytes(1);
162160
}
163161

164-
@Test(groups = "open")
162+
@Test
165163
public static void testTransferTo() {
166164
try {
167165
assertEquals(0, openStream.transferTo(new ByteArrayOutputStream(7)),
@@ -171,7 +169,7 @@ public static void testTransferTo() {
171169
}
172170
}
173171

174-
@Test(groups = "closed")
172+
@Test
175173
public static void testAvailableClosed() {
176174
try {
177175
closedStream.available();
@@ -180,7 +178,7 @@ public static void testAvailableClosed() {
180178
}
181179
}
182180

183-
@Test(groups = "closed")
181+
@Test
184182
public static void testReadClosed() {
185183
try {
186184
closedStream.read();
@@ -189,7 +187,7 @@ public static void testReadClosed() {
189187
}
190188
}
191189

192-
@Test(groups = "closed")
190+
@Test
193191
public static void testReadBIIClosed() {
194192
try {
195193
closedStream.read(new byte[1], 0, 1);
@@ -198,7 +196,7 @@ public static void testReadBIIClosed() {
198196
}
199197
}
200198

201-
@Test(groups = "closed")
199+
@Test
202200
public static void testReadAllBytesClosed() {
203201
try {
204202
closedStream.readAllBytes();
@@ -207,7 +205,7 @@ public static void testReadAllBytesClosed() {
207205
}
208206
}
209207

210-
@Test(groups = "closed")
208+
@Test
211209
public static void testReadNBytesClosed() {
212210
try {
213211
closedStream.readNBytes(new byte[1], 0, 1);
@@ -216,7 +214,7 @@ public static void testReadNBytesClosed() {
216214
}
217215
}
218216

219-
@Test(groups = "closed")
217+
@Test
220218
public static void testReadNBytesWithLengthClosed() {
221219
try {
222220
closedStream.readNBytes(1);
@@ -225,7 +223,7 @@ public static void testReadNBytesWithLengthClosed() {
225223
}
226224
}
227225

228-
@Test(groups = "closed")
226+
@Test
229227
public static void testSkipClosed() {
230228
try {
231229
closedStream.skip(1);
@@ -234,7 +232,7 @@ public static void testSkipClosed() {
234232
}
235233
}
236234

237-
@Test(groups = "closed")
235+
@Test
238236
public static void testSkipNBytesClosed() {
239237
try {
240238
closedStream.skipNBytes(1);
@@ -243,7 +241,7 @@ public static void testSkipNBytesClosed() {
243241
}
244242
}
245243

246-
@Test(groups = "closed")
244+
@Test
247245
public static void testTransferToClosed() {
248246
try {
249247
closedStream.transferTo(new ByteArrayOutputStream(7));

test/jdk/java/io/OutputStream/NullOutputStream.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,12 +21,15 @@
2121
* questions.
2222
*/
2323

24+
import org.testng.annotations.AfterClass;
25+
import org.testng.annotations.BeforeClass;
26+
import org.testng.annotations.Test;
27+
2428
import java.io.IOException;
2529
import java.io.OutputStream;
26-
import org.testng.annotations.AfterGroups;
27-
import org.testng.annotations.BeforeGroups;
28-
import org.testng.annotations.Test;
29-
import static org.testng.Assert.*;
30+
31+
import static org.testng.Assert.assertNotNull;
32+
import static org.testng.Assert.fail;
3033

3134
/*
3235
* @test
@@ -38,13 +41,9 @@ public class NullOutputStream {
3841
private static OutputStream openStream;
3942
private static OutputStream closedStream;
4043

41-
@BeforeGroups(groups="open")
42-
public static void openStream() {
44+
@BeforeClass
45+
public static void setup() {
4346
openStream = OutputStream.nullOutputStream();
44-
}
45-
46-
@BeforeGroups(groups="closed")
47-
public static void openAndCloseStream() {
4847
closedStream = OutputStream.nullOutputStream();
4948
try {
5049
closedStream.close();
@@ -53,7 +52,7 @@ public static void openAndCloseStream() {
5352
}
5453
}
5554

56-
@AfterGroups(groups="open")
55+
@AfterClass
5756
public static void closeStream() {
5857
try {
5958
openStream.close();
@@ -62,13 +61,13 @@ public static void closeStream() {
6261
}
6362
}
6463

65-
@Test(groups="open")
64+
@Test
6665
public static void testOpen() {
6766
assertNotNull(openStream,
6867
"OutputStream.nullOutputStream() returned null");
6968
}
7069

71-
@Test(groups="open")
70+
@Test
7271
public static void testWrite() {
7372
try {
7473
openStream.write(62832);
@@ -77,7 +76,7 @@ public static void testWrite() {
7776
}
7877
}
7978

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

89-
@Test(groups="closed")
88+
@Test
9089
public static void testWriteClosed() {
9190
try {
9291
closedStream.write(62832);
@@ -95,7 +94,7 @@ public static void testWriteClosed() {
9594
}
9695
}
9796

98-
@Test(groups="closed")
97+
@Test
9998
public static void testWriteBIIClosed() {
10099
try {
101100
closedStream.write(new byte[] {(byte)6}, 0, 1);

0 commit comments

Comments
 (0)