Skip to content

Commit d2cdae2

Browse files
committed
Convert the density tests to JUnit 5
The project is migrating to jupiter, so tests added by this branch should not arrive as JUnit 4. Imports move to org.junit.jupiter.api, @before and @after become @beforeeach and @AfterEach, and the seventeen assertions carrying a message have it moved from the first argument to the last, which is where JUnit 5 expects it. The three assertEquals(expected, actual, delta) calls are left alone: the third argument there is a floating point tolerance, not a message, and that overload is unchanged between the two versions. No pom changes: both modules already declare junit-jupiter-engine and junit-jupiter-params.
1 parent fde309b commit d2cdae2

6 files changed

Lines changed: 69 additions & 69 deletions

File tree

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/density/DensityMapIntegrationTest.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818
package org.biojava.nbio.structure.test.io.density;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertNotNull;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
2525

2626
import java.io.File;
2727
import java.io.IOException;
@@ -39,9 +39,9 @@
3939
import org.biojava.nbio.structure.io.density.DensityMapResult;
4040
import org.biojava.nbio.structure.io.density.DensityMapSource;
4141
import org.biojava.nbio.structure.io.density.NoDensityMapException;
42-
import org.junit.After;
43-
import org.junit.Before;
44-
import org.junit.Test;
42+
import org.junit.jupiter.api.AfterEach;
43+
import org.junit.jupiter.api.BeforeEach;
44+
import org.junit.jupiter.api.Test;
4545

4646
/**
4747
* Density fetching against the real services.
@@ -60,13 +60,13 @@ public class DensityMapIntegrationTest {
6060
private File cacheRoot;
6161
private DensityMapCache cache;
6262

63-
@Before
63+
@BeforeEach
6464
public void setUp() throws IOException {
6565
cacheRoot = Files.createTempDirectory("bj-density-it").toFile();
6666
cache = new DensityMapCache(cacheRoot.getAbsolutePath());
6767
}
6868

69-
@After
69+
@AfterEach
7070
public void tearDown() throws IOException {
7171
FileDownloadUtils.deleteDirectory(cacheRoot.toPath());
7272
}
@@ -81,8 +81,8 @@ public void fetchesAnXrayMapFromTheFirstSourceTried() throws IOException {
8181
assertTrue(result.isRenderable());
8282
assertFalse(result.isFromCache());
8383
assertTrue(result.getFileSizeBytes() > 1024);
84-
assertTrue("a .meta sidecar makes the result reconstructible offline",
85-
DensityMapResult.metaFileFor(result.getFile()).isFile());
84+
assertTrue(DensityMapResult.metaFileFor(result.getFile()).isFile(),
85+
"a .meta sidecar makes the result reconstructible offline");
8686

8787
// second call must come from the cache without another download
8888
DensityMapResult again = cache.getDensityMap(new PdbId("1cbs"), DensityMapKind.TWO_FO_FC);
@@ -100,11 +100,11 @@ public void bothKindsShareASingleDownload() throws IOException {
100100
DensityMapResult foFc = cache.getDensityMap(new PdbId("1cbs"), DensityMapKind.FO_FC);
101101

102102
assertEquals(DensityMapKind.FO_FC, foFc.getKind());
103-
assertFalse("the difference map needs its own file name", twoFoFc.getFile().equals(foFc.getFile()));
104-
assertTrue("the marker has to be in the name for Jmol to select the FO-FC block",
105-
foFc.getFile().getName().contains("&diff=1"));
106-
assertEquals("both names must address the same bytes",
107-
twoFoFc.getFileSizeBytes(), foFc.getFileSizeBytes());
103+
assertFalse(twoFoFc.getFile().equals(foFc.getFile()), "the difference map needs its own file name");
104+
assertTrue(foFc.getFile().getName().contains("&diff=1"),
105+
"the marker has to be in the name for Jmol to select the FO-FC block");
106+
assertEquals(twoFoFc.getFileSizeBytes(), foFc.getFileSizeBytes(),
107+
"both names must address the same bytes");
108108
}
109109

110110
/** PDBe serves real CCP4 files, which the header check should recognise. */
@@ -115,7 +115,7 @@ public void pdbeServesAGenuineCcp4Map() throws IOException {
115115

116116
assertEquals(DensityMapSource.PDBE_CCP4, result.getSource());
117117
assertEquals(DensityFileFormat.CCP4, result.getFormat());
118-
assertTrue("the CCP4 stamp should be present at byte 208", Ccp4Header.isCcp4(result.getFile()));
118+
assertTrue(Ccp4Header.isCcp4(result.getFile()), "the CCP4 stamp should be present at byte 208");
119119
assertTrue(FileDownloadUtils.validateFile(result.getFile()));
120120
}
121121

@@ -131,8 +131,8 @@ public void resolvesCryoEmEntriesAndHonoursTheSizeLimit() throws IOException {
131131
DensityMapResult result = cache.getDensityMap(new PdbId("6hu9"), DensityMapKind.AUTO);
132132
assertEquals(DensityMapKind.EM, result.getKind());
133133
assertEquals("EMD-0262", result.getEmdbId());
134-
assertNotNull("EM maps need the author contour level to be displayed properly",
135-
result.getRecommendedContourLevel());
134+
assertNotNull(result.getRecommendedContourLevel(),
135+
"EM maps need the author contour level to be displayed properly");
136136
assertEquals(0.0263, result.getRecommendedContourLevel(), 1e-6);
137137
assertNotNull(result.getContourInSigma());
138138

@@ -177,11 +177,11 @@ public void mapCoefficientsArriveWithAVerifiableChecksum() throws IOException {
177177
.build());
178178

179179
assertEquals(DensityMapSource.WWPDB_MAP_COEFFICIENTS, result.getSource());
180-
assertFalse("structure factors are not a map and must not claim to be renderable",
181-
result.isRenderable());
180+
assertFalse(result.isRenderable(),
181+
"structure factors are not a map and must not claim to be renderable");
182182

183183
File hashFile = new File(result.getFile().getParentFile(), result.getFile().getName() + ".hash_MD5");
184-
assertTrue("an MD5 should have been recorded from the ETag", hashFile.isFile());
184+
assertTrue(hashFile.isFile(), "an MD5 should have been recorded from the ETag");
185185
assertTrue(FileDownloadUtils.validateFile(result.getFile()));
186186

187187
// corrupt it and confirm the checksum actually catches it

biojava-structure/src/test/java/org/biojava/nbio/structure/io/density/TestCcp4Header.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
package org.biojava.nbio.structure.io.density;
1919

20-
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.io.ByteArrayOutputStream;
2424
import java.io.File;
@@ -28,9 +28,9 @@
2828
import java.util.zip.GZIPOutputStream;
2929

3030
import org.biojava.nbio.core.util.FileDownloadUtils;
31-
import org.junit.After;
32-
import org.junit.Before;
33-
import org.junit.Test;
31+
import org.junit.jupiter.api.AfterEach;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
3434

3535
/**
3636
* The CCP4 header check that keeps a server's error page out of the cache.
@@ -42,12 +42,12 @@ public class TestCcp4Header {
4242

4343
private File dir;
4444

45-
@Before
45+
@BeforeEach
4646
public void setUp() throws IOException {
4747
dir = Files.createTempDirectory("bj-ccp4").toFile();
4848
}
4949

50-
@After
50+
@AfterEach
5151
public void tearDown() throws IOException {
5252
FileDownloadUtils.deleteDirectory(dir.toPath());
5353
}
@@ -77,7 +77,7 @@ public void recognisesAGzippedMap() throws IOException {
7777
try (GZIPOutputStream gz = new GZIPOutputStream(buffer)) {
7878
gz.write(fakeMap());
7979
}
80-
assertTrue("EMDB serves its maps gzipped", Ccp4Header.isCcp4(write("good.map.gz", buffer.toByteArray())));
80+
assertTrue(Ccp4Header.isCcp4(write("good.map.gz", buffer.toByteArray())), "EMDB serves its maps gzipped");
8181
}
8282

8383
/**
@@ -101,8 +101,8 @@ public void rejectsRandomBytesAndShortFiles() throws IOException {
101101
noise[i] = (byte) (i * 31);
102102
}
103103
assertFalse(Ccp4Header.isCcp4(write("noise.ccp4", noise)));
104-
assertFalse("a file shorter than the header cannot be a map",
105-
Ccp4Header.isCcp4(write("tiny.ccp4", new byte[10])));
104+
assertFalse(Ccp4Header.isCcp4(write("tiny.ccp4", new byte[10])),
105+
"a file shorter than the header cannot be a map");
106106
}
107107

108108
@Test

biojava-structure/src/test/java/org/biojava/nbio/structure/io/density/TestDensityCacheLayout.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
*/
1818
package org.biojava.nbio.structure.io.density;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2323

2424
import java.io.File;
2525
import java.util.HashSet;
2626
import java.util.Set;
2727

2828
import org.biojava.nbio.structure.PdbId;
2929
import org.biojava.nbio.structure.io.LocalPDBDirectory;
30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
3131

3232
/**
3333
* Cache layout: directory derivation, and that no two source and kind
@@ -99,7 +99,7 @@ public void everySourceAndKindCombinationIsDistinct() {
9999
}
100100
for (DensityFileFormat format : DensityFileFormat.values()) {
101101
File f = DensityCacheLayout.pdbMapFile(ROOT, id, kind, source, format, null);
102-
assertTrue("duplicate cache path: " + f, seen.add(f.getPath()));
102+
assertTrue(seen.add(f.getPath()), "duplicate cache path: " + f);
103103
}
104104
}
105105
}

biojava-structure/src/test/java/org/biojava/nbio/structure/io/density/TestDensityFallbackChain.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
*/
1818
package org.biojava.nbio.structure.io.density;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
23-
import static org.junit.Assert.fail;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.fail;
2424

2525
import java.io.File;
2626
import java.io.IOException;
@@ -31,8 +31,8 @@
3131

3232
import org.biojava.nbio.core.util.HttpStatusException;
3333
import org.biojava.nbio.structure.PdbId;
34-
import org.junit.Before;
35-
import org.junit.Test;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
3636

3737
/**
3838
* The fallback chain, exercised with stub providers so that no server is
@@ -51,7 +51,7 @@ public class TestDensityFallbackChain {
5151
private DensityMapCache cache;
5252
private List<DensityMapSource> called;
5353

54-
@Before
54+
@BeforeEach
5555
public void setUp() {
5656
cache = new DensityMapCache(System.getProperty("java.io.tmpdir"));
5757
called = new ArrayList<>();

biojava-structure/src/test/java/org/biojava/nbio/structure/io/density/TestDensityMapUrlTemplates.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
*/
1818
package org.biojava.nbio.structure.io.density;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.io.File;
2424

2525
import org.biojava.nbio.structure.PdbId;
26-
import org.junit.After;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.Test;
2828

2929
/**
3030
* URL construction for each provider. These run offline: only the strings are
@@ -37,7 +37,7 @@ public class TestDensityMapUrlTemplates {
3737

3838
private static final File ROOT = new File("/tmp/bjcache");
3939

40-
@After
40+
@AfterEach
4141
public void restoreDefaults() {
4242
PdbeCcp4MapProvider.resetToDefaults();
4343
WwpdbMapCoefficientsProvider.resetToDefaults();

biojava-structure/src/test/java/org/biojava/nbio/structure/io/density/TestEmdbAndLocalOnly.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818
package org.biojava.nbio.structure.io.density;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertNotNull;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
2525

2626
import java.io.File;
2727
import java.io.IOException;
@@ -33,9 +33,9 @@
3333
import org.biojava.nbio.core.util.FileDownloadUtils;
3434
import org.biojava.nbio.structure.PdbId;
3535
import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior;
36-
import org.junit.After;
37-
import org.junit.Before;
38-
import org.junit.Test;
36+
import org.junit.jupiter.api.AfterEach;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Test;
3939

4040
/**
4141
* EMDB metadata parsing against captured responses, and the guarantee that
@@ -54,12 +54,12 @@ public class TestEmdbAndLocalOnly {
5454

5555
private File cacheRoot;
5656

57-
@Before
57+
@BeforeEach
5858
public void setUp() throws IOException {
5959
cacheRoot = Files.createTempDirectory("bj-density").toFile();
6060
}
6161

62-
@After
62+
@AfterEach
6363
public void tearDown() throws IOException {
6464
FileDownloadUtils.deleteDirectory(cacheRoot.toPath());
6565
PdbeCcp4MapProvider.resetToDefaults();
@@ -71,7 +71,7 @@ public void tearDown() throws IOException {
7171
private void copyResource(String resource, File target) throws IOException {
7272
target.getParentFile().mkdirs();
7373
try (InputStream in = getClass().getResourceAsStream(resource)) {
74-
assertNotNull("missing test resource " + resource, in);
74+
assertNotNull(in, "missing test resource " + resource);
7575
Files.copy(in, target.toPath());
7676
}
7777
}
@@ -92,7 +92,7 @@ public void parsesEmdbMapMetadata() throws IOException {
9292
assertNotNull(info);
9393
assertEquals("EMD-0262", info.getEmdbId());
9494
assertEquals(0.0263, info.getRecommendedContourLevel(), 1e-9);
95-
assertNotNull("sigma is needed to express the contour in sigma units", info.getSigma());
95+
assertNotNull(info.getSigma(), "sigma is needed to express the contour in sigma units");
9696
// 119165 kB, which is well past the default download ceiling
9797
assertEquals(119165L * 1024L, info.getMapSizeBytes().longValue());
9898
}
@@ -115,14 +115,14 @@ public void theFullEmMapIsLargeButWithinTheDefaultCeiling() throws IOException {
115115
resolver.setFetchBehavior(FetchBehavior.LOCAL_ONLY);
116116

117117
long bytes = resolver.getEntryInfo("EMD-0262").getMapSizeBytes();
118-
assertTrue("expected a map of order 100 MB, got " + bytes, bytes > 100L * 1024 * 1024);
119-
assertTrue("the ceiling alone would not stop this download",
120-
bytes < DensityMapCache.DEFAULT_MAX_DOWNLOAD_BYTES);
118+
assertTrue(bytes > 100L * 1024 * 1024, "expected a map of order 100 MB, got " + bytes);
119+
assertTrue(bytes < DensityMapCache.DEFAULT_MAX_DOWNLOAD_BYTES,
120+
"the ceiling alone would not stop this download");
121121

122122
DensityMapCache cache = new DensityMapCache(cacheRoot.getAbsolutePath());
123123
List<DensityMapSource> em = cache.getSourceChain(DensityMapKind.EM);
124-
assertTrue("a density server must be tried before the full archive",
125-
em.indexOf(DensityMapSource.RCSB_VOLUME_SERVER) < em.indexOf(DensityMapSource.EMDB_MAP));
124+
assertTrue(em.indexOf(DensityMapSource.RCSB_VOLUME_SERVER) < em.indexOf(DensityMapSource.EMDB_MAP),
125+
"a density server must be tried before the full archive");
126126
}
127127

128128
@Test
@@ -192,8 +192,8 @@ public void localOnlyServesACachedMapOffline() throws IOException {
192192
assertEquals(DensityMapSource.PDBE_CCP4, result.getSource());
193193
assertTrue(result.isFromCache());
194194
assertEquals(cached, result.getFile());
195-
assertTrue("a sidecar should have been written for the recovered file",
196-
DensityMapResult.metaFileFor(cached).isFile());
195+
assertTrue(DensityMapResult.metaFileFor(cached).isFile(),
196+
"a sidecar should have been written for the recovered file");
197197
}
198198

199199
@Test

0 commit comments

Comments
 (0)