Skip to content

Commit 7709a66

Browse files
Merge pull request #115 from LibraryOfCongress/junit5
converting Junit4 to Junit5
2 parents 4c6cb6d + 8a97016 commit 7709a66

File tree

58 files changed

+794
-833
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+794
-833
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,23 @@ List<BagitWarning> warnings = linter.lintBag(rootDir, Arrays.asList(BagitWarning
160160
## Developing Bagit-Java
161161
Bagit-Java uses [Gradle](https://gradle.org/) for its build system. Check out the great [documentation](https://docs.gradle.org/current/userguide/userguide_single.html) to learn more.
162162
##### Running tests and code quality checks
163-
Inside the bagit-java root directory, run `gradle check`.
163+
Inside the bagit-java root directory, run `./gradlew check`.
164164
##### Uploading to maven central
165165
1. Follow their guides
166166
1. http://central.sonatype.org/pages/releasing-the-deployment.html
167167
2. https://issues.sonatype.org/secure/Dashboard.jspa
168-
2. Once you have access, to create an official release and upload it you should specify the version by running `gradle -Pversion=<VERSION> uploadArchives`
168+
2. Once you have access, to create an official release and upload it you should specify the version by running `./gradlew -Pversion=<VERSION> uploadArchives`
169169
1. *Don't forget to tag the repository!*
170170
171171
##### Uploading to jcenter
172172
1. Follow their guide
173173
1. https://github.com/bintray/bintray-examples/tree/master/gradle-bintray-plugin-examples
174-
2. Once you have access, to create an official release and upload it you should specify the version by running `gradle -Pversion=<VERSION> bintrayUpload`
174+
2. Once you have access, to create an official release and upload it you should specify the version by running `./gradlew -Pversion=<VERSION> bintrayUpload`
175175
1. *Don't forget to tag the repository!*
176176

177177
### Note if using with Eclipse
178-
Simply run `gradle eclipse` and it will automatically create a eclipse project for you that you can import.
178+
Simply run `./gradlew eclipse` and it will automatically create a eclipse project for you that you can import.
179179

180180
### Roadmap for this library
181-
* Further refine reading and writing of bags version 0.93-0.97
182181
* Fix bugs/issues reported with new library (on going)
183182
* Translate to various languages (on going)

build.gradle

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
id "org.owasp.dependencycheck" version "3.1.2"
88
id "com.dorongold.task-tree" version "1.3"
99
id "org.ajoberstar.grgit" version "2.0.1"
10-
id "com.github.spotbugs" version "1.4"
10+
id "com.github.spotbugs" version "1.6.1"
1111
id "com.jfrog.bintray" version "1.7.3"
1212
}
1313
apply from: 'eclipse.gradle'
@@ -33,14 +33,23 @@ dependencies {
3333
'com.fasterxml.jackson.core:jackson-core:2.9.0.pr4',
3434
'com.fasterxml.jackson.core:jackson-databind:2.9.0.pr4'
3535

36-
testCompile 'junit:junit:4.12',
36+
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0',
3737
'org.springframework.boot:spring-boot-starter-logging:1.5.4.RELEASE',
3838
'org.bouncycastle:bcprov-jdk15on:1.57',
3939
'org.kamranzafar:jtar:2.3'
40+
41+
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
4042
}
4143

42-
test { //show test output
43-
testLogging.showStandardStreams = true
44+
test {
45+
useJUnitPlatform()
46+
testLogging {
47+
events "passed", "skipped", "failed"
48+
}
49+
reports {
50+
html.enabled = true
51+
}
52+
//testLogging.showStandardStreams = true
4453
}
4554

4655
tasks.withType(com.github.spotbugs.SpotBugsTask) {

gradle/wrapper/gradle-wrapper.jar

-299 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
4-
zipStorePath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
54
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

src/integration/java/gov/loc/repository/bagit/BagitSuiteComplanceTest.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
import java.util.concurrent.ConcurrentMap;
1414
import java.util.concurrent.atomic.AtomicLong;
1515

16-
import org.junit.Assert;
17-
import org.junit.BeforeClass;
18-
import org.junit.Rule;
19-
import org.junit.Test;
20-
import org.junit.rules.TemporaryFolder;
16+
import org.junit.jupiter.api.Assertions;
17+
import org.junit.jupiter.api.BeforeAll;
18+
import org.junit.jupiter.api.Test;
2119
import org.slf4j.Logger;
2220
import org.slf4j.LoggerFactory;
2321

@@ -42,18 +40,15 @@
4240
/**
4341
* This class assumes that the compliance test suite repo has been cloned and is available locally
4442
*/
45-
public class BagitSuiteComplanceTest extends Assert {
43+
public class BagitSuiteComplanceTest extends TempFolderTest {
4644
private static final Logger logger = LoggerFactory.getLogger(BagitSuiteComplanceTest.class);
4745

48-
@Rule
49-
public TemporaryFolder folder= new TemporaryFolder();
50-
5146
private static final Path complianceRepoRootDir = Paths.get("bagit-conformance-suite");
5247
private static final BagTestCaseVistor visitor = new BagTestCaseVistor();
5348
private static final BagReader reader = new BagReader();
5449
private static final BagVerifier verifier = new BagVerifier();
5550

56-
@BeforeClass
51+
@BeforeAll
5752
public static void setupOnce() throws IOException{
5853
if(!Files.exists(complianceRepoRootDir)){
5954
throw new IOException("bagit-conformance-suite git repo was not found, did you clone it?");
@@ -94,7 +89,7 @@ public void testInvalidBags(){
9489
}
9590
}
9691

97-
assertEquals("every test case should throw an error", visitor.getInvalidTestCases().size(), errorCount);
92+
Assertions.assertEquals(visitor.getInvalidTestCases().size(), errorCount, "every test case should throw an error");
9893
logger.debug("Count of all errors found in generic invalid cases: {}", map);
9994
}
10095

@@ -125,7 +120,7 @@ public void testInvalidOperatingSystemSpecificBags(){
125120
}
126121
}
127122

128-
assertEquals("every test case should throw an error", osSpecificInvalidPaths.size(), errorCount);
123+
Assertions.assertEquals(osSpecificInvalidPaths.size(), errorCount, "every test case should throw an error");
129124
logger.debug("Count of all errors found in os specific invalid cases: {}", map);
130125
}
131126

@@ -135,7 +130,7 @@ public void testWarnings() throws Exception{
135130

136131
for(Path bagDir : visitor.getWarningTestCases()){
137132
warnings = BagLinter.lintBag(bagDir);
138-
assertTrue(warnings.size() > 0);
133+
Assertions.assertTrue(warnings.size() > 0);
139134
}
140135
}
141136

@@ -145,7 +140,7 @@ public void testReadWriteProducesSameBag() throws Exception{
145140
Path newBagDir;
146141

147142
for(final Path bagDir : visitor.getValidTestCases()){
148-
newBagDir = folder.newFolder().toPath();
143+
newBagDir = folder.resolve("readWriteProducesSameBag");
149144
bag = reader.read(bagDir);
150145
BagWriter.write(bag, newBagDir);
151146

@@ -158,22 +153,20 @@ public void testReadWriteProducesSameBag() throws Exception{
158153
private void testTagFileContents(final Bag originalBag, final Path newBagDir) throws IOException{
159154
Path original = originalBag.getRootDir().resolve("bagit.txt");
160155
Path newFile = newBagDir.resolve("bagit.txt");
161-
assertTrue("bagit.txt files differ",
162-
compareFileContents(original,
163-
newFile, StandardCharsets.UTF_8));
156+
Assertions.assertTrue(compareFileContents(original, newFile, StandardCharsets.UTF_8), "bagit.txt files differ");
164157

165158
if(originalBag.getVersion().isSameOrOlder(new Version(0, 95))){
166159
original = originalBag.getRootDir().resolve("package-info.txt");
167160
newFile = newBagDir.resolve("package-info.txt");
168-
assertTrue(original + " differs from " + newFile,
169-
compareFileContents(original, newFile, originalBag.getFileEncoding()));
161+
Assertions.assertTrue(compareFileContents(original, newFile, originalBag.getFileEncoding()),
162+
original + " differs from " + newFile);
170163
}
171164
else{
172165
if(Files.exists(originalBag.getRootDir().resolve("bag-info.txt"))){
173166
original = originalBag.getRootDir().resolve("bag-info.txt");
174167
newFile = newBagDir.resolve("bag-info.txt");
175-
assertTrue(original + " differs from " + newFile,
176-
compareFileContents(original,newFile, originalBag.getFileEncoding()));
168+
Assertions.assertTrue(compareFileContents(original,newFile, originalBag.getFileEncoding()),
169+
original + " differs from " + newFile);
177170
}
178171
}
179172

src/integration/java/gov/loc/repository/bagit/FileExistsVistor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.nio.file.SimpleFileVisitor;
88
import java.nio.file.attribute.BasicFileAttributes;
99

10-
import org.junit.Assert;
10+
import org.junit.jupiter.api.Assertions;
1111

1212
public class FileExistsVistor extends SimpleFileVisitor<Path>{
1313
private transient final Path originalBag;
@@ -21,15 +21,15 @@ public FileExistsVistor(final Path originalBag, final Path newBag){
2121
@Override
2222
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
2323
Path relative = originalBag.relativize(dir);
24-
Assert.assertTrue(Files.exists(newBag.resolve(relative)));
24+
Assertions.assertTrue(Files.exists(newBag.resolve(relative)));
2525

2626
return FileVisitResult.CONTINUE;
2727
}
2828

2929
@Override
3030
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs)throws IOException{
3131
final Path relative = originalBag.relativize(path);
32-
Assert.assertTrue(Files.exists(newBag.resolve(relative)));
32+
Assertions.assertTrue(Files.exists(newBag.resolve(relative)));
3333

3434
return FileVisitResult.CONTINUE;
3535
}

src/integration/java/gov/loc/repository/bagit/ReaderWriterVerifierIntegrationTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,21 @@
55
import java.nio.file.Path;
66
import java.nio.file.Paths;
77

8-
import org.junit.Rule;
9-
import org.junit.Test;
10-
import org.junit.rules.TemporaryFolder;
8+
import org.junit.jupiter.api.Test;
119

1210
import gov.loc.repository.bagit.domain.Bag;
1311
import gov.loc.repository.bagit.reader.BagReader;
1412
import gov.loc.repository.bagit.verify.BagVerifier;
1513
import gov.loc.repository.bagit.writer.BagWriter;
1614

17-
public class ReaderWriterVerifierIntegrationTest {
18-
@Rule
19-
public TemporaryFolder folder= new TemporaryFolder();
15+
public class ReaderWriterVerifierIntegrationTest extends TempFolderTest {
2016

2117
@Test
2218
public void testReaderWriterVersion93() throws Exception{
2319
try(BagVerifier verifier = new BagVerifier()){
2420
BagReader reader = new BagReader();
2521
Path rootDir = Paths.get(this.getClass().getClassLoader().getResource("bags/v0_93/bag").toURI());
26-
Path outputDir = Paths.get(folder.newFolder().toURI());
22+
Path outputDir = folder.resolve("version93");
2723

2824
Bag bag = reader.read(rootDir);
2925
verifier.isValid(bag, true);
@@ -40,7 +36,7 @@ public void testReaderWriterVersion94() throws Exception{
4036
BagReader reader = new BagReader();
4137
Path rootDir = Paths.get(this.getClass().getClassLoader().getResource("bags/v0_94/bag").toURI());
4238
Bag bag = reader.read(rootDir);
43-
Path outputDir = Paths.get(folder.newFolder().toURI());
39+
Path outputDir = folder.resolve("version94");
4440

4541
BagWriter.write(bag, outputDir);
4642

@@ -55,7 +51,7 @@ public void testReaderWriterVersion95() throws Exception{
5551
BagReader reader = new BagReader();
5652
Path rootDir = Paths.get(this.getClass().getClassLoader().getResource("bags/v0_95/bag").toURI());
5753
Bag bag = reader.read(rootDir);
58-
Path outputDir = Paths.get(folder.newFolder().toURI());
54+
Path outputDir = folder.resolve("version95");
5955

6056
BagWriter.write(bag, outputDir);
6157

@@ -70,7 +66,7 @@ public void testReaderWriterVersion96() throws Exception{
7066
BagReader reader = new BagReader();
7167
Path rootDir = Paths.get(this.getClass().getClassLoader().getResource("bags/v0_96/bag").toURI());
7268
Bag bag = reader.read(rootDir);
73-
Path outputDir = Paths.get(folder.newFolder().toURI());
69+
Path outputDir = folder.resolve("version96");
7470

7571
BagWriter.write(bag, outputDir);
7672

@@ -85,7 +81,7 @@ public void testReaderWriterVersion97() throws Exception{
8581
BagReader reader = new BagReader();
8682
Path rootDir = Paths.get(this.getClass().getClassLoader().getResource("bags/v0_97/bag").toURI());
8783
Bag bag = reader.read(rootDir);
88-
Path outputDir = Paths.get(folder.newFolder().toURI());
84+
Path outputDir = folder.resolve("version97");
8985

9086
BagWriter.write(bag, outputDir);
9187

@@ -100,7 +96,7 @@ public void testReaderWriterVersion2_0() throws Exception{
10096
BagReader reader = new BagReader();
10197
Path rootDir = Paths.get(this.getClass().getClassLoader().getResource("bags/v2_0/bag").toURI());
10298
Bag bag = reader.read(rootDir);
103-
Path outputDir = Paths.get(folder.newFolder().toURI());
99+
Path outputDir = folder.resolve("version2");
104100

105101
BagWriter.write(bag, outputDir);
106102

src/main/java/gov/loc/repository/bagit/creator/AbstractCreateManifestsVistor.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public abstract class AbstractCreateManifestsVistor extends SimpleFileVisitor<Pa
2525
private static final Logger logger = LoggerFactory.getLogger(AbstractCreateManifestsVistor.class);
2626
private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");
2727

28-
protected final Map<Manifest, MessageDigest> manifestToMessageDigestMap;
29-
protected final boolean includeHiddenFiles;
28+
protected transient final Map<Manifest, MessageDigest> manifestToMessageDigestMap;
29+
protected transient final boolean includeHiddenFiles;
3030

3131
public AbstractCreateManifestsVistor(final Map<Manifest, MessageDigest> manifestToMessageDigestMap, final boolean includeHiddenFiles){
3232
this.manifestToMessageDigestMap = manifestToMessageDigestMap;
@@ -57,12 +57,4 @@ public FileVisitResult visitFile(final Path path, final BasicFileAttributes attr
5757

5858
return FileVisitResult.CONTINUE;
5959
}
60-
61-
public Map<Manifest, MessageDigest> getManifestToMessageDigestMap() {
62-
return manifestToMessageDigestMap;
63-
}
64-
65-
public boolean isIncludeHiddenFiles() {
66-
return includeHiddenFiles;
67-
}
6860
}

src/main/java/gov/loc/repository/bagit/verify/AbstractPayloadFileExistsInManifestsVistor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
abstract public class AbstractPayloadFileExistsInManifestsVistor extends SimpleFileVisitor<Path> {
2020
protected static final Logger logger = LoggerFactory.getLogger(AbstractPayloadFileExistsInManifestsVistor.class);
2121
protected static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");
22-
protected final boolean ignoreHiddenFiles;
22+
protected transient final boolean ignoreHiddenFiles;
2323

2424
public AbstractPayloadFileExistsInManifestsVistor(final boolean ignoreHiddenFiles) {
2525
this.ignoreHiddenFiles = ignoreHiddenFiles;
@@ -34,8 +34,4 @@ public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttribut
3434

3535
return FileVisitResult.CONTINUE;
3636
}
37-
38-
public boolean isIgnoreHiddenFiles() {
39-
return ignoreHiddenFiles;
40-
}
4137
}

src/main/java/gov/loc/repository/bagit/verify/CheckIfFileExistsTask.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
public class CheckIfFileExistsTask implements Runnable {
2020
private static final Logger logger = LoggerFactory.getLogger(CheckIfFileExistsTask.class);
2121
private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");
22-
private final Path file;
23-
//TODO if performance is an issue look at concurrentHashMap - it will take up more space but insertion is O(1) vs O(n)
24-
private final Set<Path> missingFiles;
25-
private final CountDownLatch latch;
22+
private transient final Path file;
23+
private transient final Set<Path> missingFiles;
24+
private transient final CountDownLatch latch;
2625

2726
public CheckIfFileExistsTask(final Path file, final Set<Path> missingFiles, final CountDownLatch latch) {
2827
this.file = file;
@@ -72,16 +71,4 @@ private boolean existsNormalized(){
7271

7372
return false;
7473
}
75-
76-
public Path getFile() {
77-
return file;
78-
}
79-
80-
public Set<Path> getMissingFiles() {
81-
return missingFiles;
82-
}
83-
84-
public CountDownLatch getLatch() {
85-
return latch;
86-
}
8774
}

0 commit comments

Comments
 (0)