Skip to content

Commit c92d323

Browse files
committed
Test filtering with Category and JUnitPlatform
Tests that extend TestCase do not properly work with JUnit4 Category filtering when running with JUnitPlatform, so migrate to use the JUnit4 @test annotations.
1 parent 5100c18 commit c92d323

File tree

10 files changed

+92
-126
lines changed

10 files changed

+92
-126
lines changed

cdm-test/src/test/java/ucar/nc2/dataset/TestVertical.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
2-
* Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
5+
56
package ucar.nc2.dataset;
67

7-
import junit.framework.*;
8+
import org.junit.Test;
89
import org.junit.experimental.categories.Category;
910
import org.slf4j.Logger;
1011
import org.slf4j.LoggerFactory;
@@ -21,13 +22,11 @@
2122
* Test basic projection methods
2223
*/
2324
@Category(NeedsCdmUnitTest.class)
24-
public class TestVertical extends TestCase {
25-
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
25+
public class TestVertical {
2626

27-
public TestVertical(String name) {
28-
super(name);
29-
}
27+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
3028

29+
@Test
3130
public void testOceanS() throws java.io.IOException, InvalidRangeException {
3231
GridDataset gds =
3332
ucar.nc2.dt.grid.GridDataset.open(TestDir.cdmUnitTestDir + "transforms/roms_ocean_s_coordinate.nc");
@@ -50,12 +49,14 @@ public void testOceanS() throws java.io.IOException, InvalidRangeException {
5049
assert ca.getRank() == 3 : ca.getRank();
5150

5251
int[] shape = ca.getShape();
53-
for (int i = 0; i < 3; i++)
52+
for (int i = 0; i < 3; i++) {
5453
System.out.println(" shape " + i + " = " + shape[i]);
54+
}
5555

5656
gds.close();
5757
}
5858

59+
@Test
5960
public void testOceanSigma() throws java.io.IOException, InvalidRangeException {
6061
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(TestDir.cdmUnitTestDir + "conventions/cf/gomoos_cf.nc");
6162

@@ -80,12 +81,14 @@ public void testOceanSigma() throws java.io.IOException, InvalidRangeException {
8081
assert ca.getRank() == 3 : ca.getRank();
8182

8283
int[] shape = ca.getShape();
83-
for (int i = 0; i < 3; i++)
84+
for (int i = 0; i < 3; i++) {
8485
System.out.println(" shape " + i + " = " + shape[i]);
86+
}
8587
}
8688
gds.close();
8789
}
8890

91+
@Test
8992
public void testAtmSigma() throws java.io.IOException, InvalidRangeException {
9093
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(TestDir.cdmUnitTestDir + "transforms/temperature.nc");
9194

@@ -107,12 +110,14 @@ public void testAtmSigma() throws java.io.IOException, InvalidRangeException {
107110
assert ca.getRank() == 3 : ca.getRank();
108111

109112
int[] shape = ca.getShape();
110-
for (int i = 0; i < 3; i++)
113+
for (int i = 0; i < 3; i++) {
111114
System.out.println(" shape " + i + " = " + shape[i]);
115+
}
112116

113117
gds.close();
114118
}
115119

120+
@Test
116121
public void testAtmHybrid() throws java.io.IOException, InvalidRangeException {
117122
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(TestDir.cdmUnitTestDir + "conventions/cf/ccsm2.nc");
118123

@@ -134,12 +139,14 @@ public void testAtmHybrid() throws java.io.IOException, InvalidRangeException {
134139
assert ca.getRank() == 3 : ca.getRank();
135140

136141
int[] shape = ca.getShape();
137-
for (int i = 0; i < 3; i++)
142+
for (int i = 0; i < 3; i++) {
138143
System.out.println(" shape " + i + " = " + shape[i]);
144+
}
139145

140146
gds.close();
141147
}
142148

149+
@Test
143150
public void testWrfEta() throws java.io.IOException, InvalidRangeException {
144151
GridDataset gds =
145152
ucar.nc2.dt.grid.GridDataset.open(TestDir.cdmUnitTestDir + "conventions/wrf/wrfout_v2_Lambert.nc");
@@ -162,14 +169,16 @@ public void testWrfEta() throws java.io.IOException, InvalidRangeException {
162169
assert ca.getRank() == 3 : ca.getRank();
163170

164171
int[] shape = ca.getShape();
165-
for (int i = 0; i < 3; i++)
172+
for (int i = 0; i < 3; i++) {
166173
System.out.println(" shape " + i + " = " + shape[i]);
174+
}
167175

168176
gds.close();
169177
}
170178

171179
// TestAll.upcShareDir + /testdata2/grid/netcdf/wrf/wrfout_v2_Lambert.nc
172180

181+
@Test
173182
public void testStride() throws java.io.IOException, InvalidRangeException {
174183
String filename = TestDir.cdmUnitTestDir + "/conventions/wrf/wrfout_d01_2006-03-08_21-00-00";
175184
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(filename);
@@ -190,8 +199,9 @@ public void testStride() throws java.io.IOException, InvalidRangeException {
190199
assert ca.getRank() == 3 : ca.getRank();
191200

192201
int[] shape = ca.getShape();
193-
for (int i = 0; i < 3; i++)
202+
for (int i = 0; i < 3; i++) {
194203
System.out.println(" shape " + i + " = " + shape[i]);
204+
}
195205

196206
assert shape[0] == 44;
197207
assert shape[1] == 399 / 2 + 1;

cdm-test/src/test/java/ucar/nc2/dt/grid/TestGridVerticalTransforms.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
55

66
package ucar.nc2.dt.grid;
77

8-
import junit.framework.TestCase;
8+
import org.junit.Test;
99
import org.junit.experimental.categories.Category;
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
@@ -22,13 +22,11 @@
2222
import java.lang.invoke.MethodHandles;
2323

2424
@Category(NeedsCdmUnitTest.class)
25-
public class TestGridVerticalTransforms extends TestCase {
26-
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
25+
public class TestGridVerticalTransforms {
2726

28-
public TestGridVerticalTransforms(String name) {
29-
super(name);
30-
}
27+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
3128

29+
@Test
3230
public void testWRF() throws Exception {
3331
testDataset(TestDir.cdmUnitTestDir + "conventions/wrf/wrfout_v2_Lambert.nc");
3432
testDataset(TestDir.cdmUnitTestDir + "conventions/wrf/wrfout_d01_2006-03-08_21-00-00");
@@ -77,13 +75,14 @@ private void testGrid(GeoGrid grid) throws IOException, InvalidRangeException {
7775

7876
/*
7977
* The 3D coordinate array does not return correct shape and values. Just running this simple code to get z values..
80-
*
78+
*
8179
* url=http://coast-enviro.er.usgs.gov/models/share/erie_test.ncml;
8280
* var='temp';
83-
*
81+
*
8482
* z is of shape 20x2x87, it should be 20x87x193.
8583
*/
8684

85+
@Test
8786
public void testErie() throws IOException, InvalidRangeException {
8887
String uri = TestDir.cdmUnitTestDir + "transforms/erie_test.ncml";
8988
String var = "temp";
Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,16 @@
11
/*
2-
* Copyright (c) 1998 - 2009. University Corporation for Atmospheric Research/Unidata
3-
* Portions of this software were developed by the Unidata Program at the
4-
* University Corporation for Atmospheric Research.
5-
*
6-
* Access and use of this software shall impose the following obligations
7-
* and understandings on the user. The user is granted the right, without
8-
* any fee or cost, to use, copy, modify, alter, enhance and distribute
9-
* this software, and any derivative works thereof, and its supporting
10-
* documentation for any purpose whatsoever, provided that this entire
11-
* notice appears in all copies of the software, derivative works and
12-
* supporting documentation. Further, UCAR requests that the user credit
13-
* UCAR/Unidata in any publications that result from the use of this
14-
* software or in any product that includes this software. The names UCAR
15-
* and/or Unidata, however, may not be used in any advertising or publicity
16-
* to endorse or promote any products or commercial entity unless specific
17-
* written permission is obtained from UCAR/Unidata. The user also
18-
* understands that UCAR/Unidata is not obligated to provide the user with
19-
* any support, consulting, training or assistance of any kind with regard
20-
* to the use, operation and performance of this software nor to provide
21-
* the user with any updates, revisions, new versions or "bug fixes."
22-
*
23-
* THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR
24-
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26-
* DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL,
27-
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
28-
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
29-
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
30-
* WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.
2+
* Copyright (c) 2009-2025 University Corporation for Atmospheric Research/Unidata
3+
* See LICENSE for license information.
314
*/
325

336
package ucar.nc2.dt.grid;
347

8+
import org.junit.Test;
359
import org.junit.experimental.categories.Category;
3610
import org.slf4j.Logger;
3711
import org.slf4j.LoggerFactory;
3812
import ucar.nc2.dt.GridCoordSystem;
3913
import ucar.ma2.Array;
40-
import junit.framework.TestCase;
4114
import ucar.unidata.util.test.category.NeedsCdmUnitTest;
4215
import ucar.unidata.util.test.TestDir;
4316
import java.lang.invoke.MethodHandles;
@@ -50,9 +23,11 @@
5023
* @since Oct 16, 2009
5124
*/
5225
@Category(NeedsCdmUnitTest.class)
53-
public class TestStag3D extends TestCase {
26+
public class TestStag3D {
27+
5428
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
5529

30+
@Test
5631
public void testSubset() throws Exception {
5732
ucar.nc2.dt.grid.GridDataset dataset = GridDataset.open(TestDir.cdmUnitTestDir + "ft/grid/stag/bora_feb.nc");
5833

@@ -73,8 +48,9 @@ public void testSubset() throws Exception {
7348

7449
private String showShape(int[] shape) {
7550
Formatter f = new Formatter();
76-
for (int s : shape)
51+
for (int s : shape) {
7752
f.format(" %d", s);
53+
}
7854
return f.toString();
7955
}
8056
}

cdm-test/src/test/java/ucar/nc2/ncml/TestNcMLStrides.java

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,14 @@
11
/*
2-
* Copyright (c) 1998 - 2011. University Corporation for Atmospheric Research/Unidata
3-
* Portions of this software were developed by the Unidata Program at the
4-
* University Corporation for Atmospheric Research.
5-
*
6-
* Access and use of this software shall impose the following obligations
7-
* and understandings on the user. The user is granted the right, without
8-
* any fee or cost, to use, copy, modify, alter, enhance and distribute
9-
* this software, and any derivative works thereof, and its supporting
10-
* documentation for any purpose whatsoever, provided that this entire
11-
* notice appears in all copies of the software, derivative works and
12-
* supporting documentation. Further, UCAR requests that the user credit
13-
* UCAR/Unidata in any publications that result from the use of this
14-
* software or in any product that includes this software. The names UCAR
15-
* and/or Unidata, however, may not be used in any advertising or publicity
16-
* to endorse or promote any products or commercial entity unless specific
17-
* written permission is obtained from UCAR/Unidata. The user also
18-
* understands that UCAR/Unidata is not obligated to provide the user with
19-
* any support, consulting, training or assistance of any kind with regard
20-
* to the use, operation and performance of this software nor to provide
21-
* the user with any updates, revisions, new versions or "bug fixes."
22-
*
23-
* THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR
24-
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26-
* DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL,
27-
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
28-
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
29-
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
30-
* WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.
2+
* Copyright (c) 1998-2025 University Corporation for Atmospheric Research/Unidata
3+
* See LICENSE for license information.
314
*/
5+
326
package ucar.nc2.ncml;
337

34-
import junit.framework.TestCase;
8+
import org.junit.Test;
359
import org.junit.experimental.categories.Category;
10+
import org.junit.jupiter.api.AfterEach;
11+
import org.junit.jupiter.api.BeforeEach;
3612
import org.slf4j.Logger;
3713
import org.slf4j.LoggerFactory;
3814
import ucar.ma2.ArrayInt;
@@ -49,16 +25,13 @@
4925

5026
/** Test netcdf dataset in the JUnit framework. */
5127
@Category(NeedsCdmUnitTest.class)
52-
public class TestNcMLStrides extends TestCase {
28+
public class TestNcMLStrides {
5329
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
5430

55-
public TestNcMLStrides(String name) {
56-
super(name);
57-
}
58-
5931
NetcdfFile ncfile = null;
6032
String location = "file:" + TestDir.cdmUnitTestDir + "agg/strides/strides.ncml";
6133

34+
@BeforeEach
6235
public void setUp() {
6336
try {
6437
ncfile = NcMLReader.readNcML(location, null);
@@ -71,10 +44,12 @@ public void setUp() {
7144
}
7245
}
7346

47+
@AfterEach
7448
protected void tearDown() throws IOException {
7549
ncfile.close();
7650
}
7751

52+
@Test
7853
public void testStride() throws IOException, InvalidRangeException {
7954
System.out.println("ncfile opened = " + location + "\n" + ncfile);
8055
Variable time = ncfile.findVariable("time");

cdm-test/src/test/java/ucar/nc2/ncml/TestOffAggDirectory.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
2-
* Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
5+
56
package ucar.nc2.ncml;
67

7-
import junit.framework.TestCase;
8+
import org.junit.Test;
89
import org.junit.experimental.categories.Category;
910
import org.slf4j.Logger;
1011
import org.slf4j.LoggerFactory;
@@ -27,9 +28,10 @@
2728
import java.util.List;
2829

2930
@Category(NeedsCdmUnitTest.class)
30-
public class TestOffAggDirectory extends TestCase {
31+
public class TestOffAggDirectory {
3132
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
3233

34+
@Test
3335
public void testNcmlDirect() throws IOException {
3436
String filename = "file:" + TestDir.cdmUnitTestDir + "ncml/nc/seawifs/aggDirectory.ncml";
3537

@@ -44,6 +46,7 @@ public void testNcmlDirect() throws IOException {
4446
ncfile.close();
4547
}
4648

49+
@Test
4750
public void testNcmlDataset() throws IOException {
4851
String filename = "file:" + TestDir.cdmUnitTestDir + "ncml/nc/seawifs/aggDirectory.ncml";
4952

@@ -58,6 +61,7 @@ public void testNcmlDataset() throws IOException {
5861
ncfile.close();
5962
}
6063

64+
@Test
6165
public void testNcmlGrid() throws IOException {
6266
String filename = "file:" + TestDir.cdmUnitTestDir + "ncml/nc/seawifs/aggDirectory.ncml";
6367

@@ -205,6 +209,7 @@ public void testReadData2(NetcdfFile ncfile) throws IOException {
205209
}
206210
}
207211

212+
@Test
208213
public void testBlanksInDirectory() throws IOException {
209214
String dir = TestDir.cdmUnitTestDir + "encoding/";
210215
String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n"

0 commit comments

Comments
 (0)