|
| 1 | +package ucar.nc2.iosp.sigmet; |
| 2 | + |
| 3 | +import org.apache.commons.io.filefilter.WildcardFileFilter; |
| 4 | +import org.junit.Test; |
| 5 | +import org.junit.runner.RunWith; |
| 6 | +import org.junit.runners.Parameterized; |
| 7 | +import org.slf4j.Logger; |
| 8 | +import org.slf4j.LoggerFactory; |
| 9 | +import ucar.nc2.NetcdfFile; |
| 10 | +import ucar.nc2.NetcdfFiles; |
| 11 | +import ucar.unidata.util.test.TestDir; |
| 12 | + |
| 13 | +import java.io.IOException; |
| 14 | +import java.lang.invoke.MethodHandles; |
| 15 | +import java.util.ArrayList; |
| 16 | +import java.util.Collection; |
| 17 | + |
| 18 | +@RunWith(Parameterized.class) |
| 19 | +public class TestIdeamCo { |
| 20 | + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); |
| 21 | + |
| 22 | + String filename; |
| 23 | + |
| 24 | + @Parameterized.Parameters(name = "{0}") |
| 25 | + public static Collection<Object[]> getTestParameters() throws IOException { |
| 26 | + final Collection<Object[]> filenames = new ArrayList<>(); |
| 27 | + |
| 28 | + try { |
| 29 | + TestDir.actOnAll(TestDir.localTestDataDir + "sigmet/", new WildcardFileFilter("BAR250130122328.RAWK8Y1"), |
| 30 | + new TestDir.Act() { |
| 31 | + public int doAct(String filename) throws IOException { |
| 32 | + filenames.add(new Object[] {filename}); |
| 33 | + return 1; |
| 34 | + } |
| 35 | + }, true); |
| 36 | + } catch (IOException e) { |
| 37 | + // JUnit *always* executes a test class's @Parameters method, even if it won't subsequently run the class's tests |
| 38 | + // due to an @Category exclusion. Therefore, we must not let it throw an exception, or else we'll get a build |
| 39 | + // failure. Instead, we return a collection containing a nonsense value (to wit, the exception message). |
| 40 | + // |
| 41 | + // Naturally, if we execute a test using that nonsense value, it'll fail. That's fine; we need to deal with the |
| 42 | + // root cause. However, it is more likely that the exception occurred because "!isCdmUnitTestDirAvailable", and |
| 43 | + // as a result, all NeedsCdmUnitTest tests will be excluded. |
| 44 | + filenames.add(new Object[] {e.getMessage()}); |
| 45 | + } |
| 46 | + |
| 47 | + return filenames; |
| 48 | + } |
| 49 | + |
| 50 | + public TestIdeamCo(String filename) { |
| 51 | + this.filename = filename; |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testOpen() throws IOException { |
| 56 | + try (NetcdfFile nc = NetcdfFiles.open(filename)) { |
| 57 | + |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments