Skip to content

Commit 16a84de

Browse files
gdamsGoeLin
authored andcommitted
8266460: java.io tests fail on null stream with upgraded jtreg/TestNG
Reviewed-by: goetz Backport-of: e840597
1 parent 533a4e6 commit 16a84de

File tree

4 files changed

+95
-107
lines changed

4 files changed

+95
-107
lines changed

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

Lines changed: 27 additions & 29 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,14 @@
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;
25-
import java.io.InputStream;
2629
import java.io.IOException;
27-
import org.testng.annotations.AfterGroups;
28-
import org.testng.annotations.BeforeGroups;
29-
import org.testng.annotations.Test;
30+
import java.io.InputStream;
31+
3032
import static org.testng.Assert.*;
3133

3234
/*
@@ -39,13 +41,9 @@ public class NullInputStream {
3941
private static InputStream openStream;
4042
private static InputStream closedStream;
4143

42-
@BeforeGroups(groups="open")
43-
public static void openStream() {
44+
@BeforeClass
45+
public static void setup() {
4446
openStream = InputStream.nullInputStream();
45-
}
46-
47-
@BeforeGroups(groups="closed")
48-
public static void openAndCloseStream() {
4947
closedStream = InputStream.nullInputStream();
5048
try {
5149
closedStream.close();
@@ -54,7 +52,7 @@ public static void openAndCloseStream() {
5452
}
5553
}
5654

57-
@AfterGroups(groups="open")
55+
@AfterClass
5856
public static void closeStream() {
5957
try {
6058
openStream.close();
@@ -63,12 +61,12 @@ public static void closeStream() {
6361
}
6462
}
6563

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

71-
@Test(groups = "open")
69+
@Test
7270
public static void testAvailable() {
7371
try {
7472
assertEquals(0, openStream.available(), "available() != 0");
@@ -77,7 +75,7 @@ public static void testAvailable() {
7775
}
7876
}
7977

80-
@Test(groups = "open")
78+
@Test
8179
public static void testRead() {
8280
try {
8381
assertEquals(-1, openStream.read(), "read() != -1");
@@ -86,7 +84,7 @@ public static void testRead() {
8684
}
8785
}
8886

89-
@Test(groups = "open")
87+
@Test
9088
public static void testReadBII() {
9189
try {
9290
assertEquals(-1, openStream.read(new byte[1], 0, 1),
@@ -96,7 +94,7 @@ public static void testReadBII() {
9694
}
9795
}
9896

99-
@Test(groups = "open")
97+
@Test
10098
public static void testReadAllBytes() {
10199
try {
102100
assertEquals(0, openStream.readAllBytes().length,
@@ -106,7 +104,7 @@ public static void testReadAllBytes() {
106104
}
107105
}
108106

109-
@Test(groups = "open")
107+
@Test
110108
public static void testReadNBytes() {
111109
try {
112110
assertEquals(0, openStream.readNBytes(new byte[1], 0, 1),
@@ -116,7 +114,7 @@ public static void testReadNBytes() {
116114
}
117115
}
118116

119-
@Test(groups = "open")
117+
@Test
120118
public static void testReadNBytesWithLength() {
121119
try {
122120
assertEquals(0, openStream.readNBytes(-1).length,
@@ -136,7 +134,7 @@ public static void testReadNBytesWithLength() {
136134
}
137135
}
138136

139-
@Test(groups = "open")
137+
@Test
140138
public static void testSkip() {
141139
try {
142140
assertEquals(0, openStream.skip(1), "skip() != 0");
@@ -145,7 +143,7 @@ public static void testSkip() {
145143
}
146144
}
147145

148-
@Test(groups = "open")
146+
@Test
149147
public static void testTransferTo() {
150148
try {
151149
assertEquals(0, openStream.transferTo(new ByteArrayOutputStream(7)),
@@ -155,7 +153,7 @@ public static void testTransferTo() {
155153
}
156154
}
157155

158-
@Test(groups = "closed")
156+
@Test
159157
public static void testAvailableClosed() {
160158
try {
161159
closedStream.available();
@@ -164,7 +162,7 @@ public static void testAvailableClosed() {
164162
}
165163
}
166164

167-
@Test(groups = "closed")
165+
@Test
168166
public static void testReadClosed() {
169167
try {
170168
closedStream.read();
@@ -173,7 +171,7 @@ public static void testReadClosed() {
173171
}
174172
}
175173

176-
@Test(groups = "closed")
174+
@Test
177175
public static void testReadBIIClosed() {
178176
try {
179177
closedStream.read(new byte[1], 0, 1);
@@ -182,7 +180,7 @@ public static void testReadBIIClosed() {
182180
}
183181
}
184182

185-
@Test(groups = "closed")
183+
@Test
186184
public static void testReadAllBytesClosed() {
187185
try {
188186
closedStream.readAllBytes();
@@ -191,7 +189,7 @@ public static void testReadAllBytesClosed() {
191189
}
192190
}
193191

194-
@Test(groups = "closed")
192+
@Test
195193
public static void testReadNBytesClosed() {
196194
try {
197195
closedStream.readNBytes(new byte[1], 0, 1);
@@ -200,7 +198,7 @@ public static void testReadNBytesClosed() {
200198
}
201199
}
202200

203-
@Test(groups = "closed")
201+
@Test
204202
public static void testReadNBytesWithLengthClosed() {
205203
try {
206204
closedStream.readNBytes(1);
@@ -209,7 +207,7 @@ public static void testReadNBytesWithLengthClosed() {
209207
}
210208
}
211209

212-
@Test(groups = "closed")
210+
@Test
213211
public static void testSkipClosed() {
214212
try {
215213
closedStream.skip(1);
@@ -218,7 +216,7 @@ public static void testSkipClosed() {
218216
}
219217
}
220218

221-
@Test(groups = "closed")
219+
@Test
222220
public static void testTransferToClosed() {
223221
try {
224222
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)