Skip to content

Commit e1a8e30

Browse files
committed
increase code coverage
1 parent 706b647 commit e1a8e30

File tree

8 files changed

+35
-72
lines changed

8 files changed

+35
-72
lines changed

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
}

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class CheckManifestHashesTask implements Runnable {
2525
private static final Logger logger = LoggerFactory.getLogger(CheckManifestHashesTask.class);
2626
private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");
2727

28-
private final Entry<Path, String> entry;
29-
private final CountDownLatch latch;
30-
private final Collection<Exception> exceptions;
31-
private final String algorithm;
28+
private transient final Entry<Path, String> entry;
29+
private transient final CountDownLatch latch;
30+
private transient final Collection<Exception> exceptions;
31+
private transient final String algorithm;
3232

3333
public CheckManifestHashesTask(final Entry<Path, String> entry, final String algorithm, final CountDownLatch latch, final Collection<Exception> exceptions) {
3434
this.entry = entry;
@@ -59,21 +59,4 @@ protected static void checkManifestEntry(final Entry<Path, String> entry, final
5959
}
6060
//if the file doesn't exist it will be caught by checkAllFilesListedInManifestExist method
6161
}
62-
63-
public Entry<Path, String> getEntry() {
64-
return entry;
65-
}
66-
67-
public CountDownLatch getLatch() {
68-
return latch;
69-
}
70-
71-
public Collection<Exception> getExceptions() {
72-
return exceptions;
73-
}
74-
75-
public String getAlgorithm() {
76-
return algorithm;
77-
}
78-
7962
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class FileCountAndTotalSizeVistor extends SimpleFileVisitor<Path> {
1919
private static final Logger logger = LoggerFactory.getLogger(FileCountAndTotalSizeVistor.class);
2020
private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");
2121

22-
private long totalSize;
23-
private long count;
22+
private transient long totalSize;
23+
private transient long count;
2424

2525
@Override
2626
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
@@ -49,12 +49,4 @@ public long getCount() {
4949
public long getTotalSize() {
5050
return totalSize;
5151
}
52-
53-
public void setTotalSize(final long totalSize) {
54-
this.totalSize = totalSize;
55-
}
56-
57-
public void setCount(final long count) {
58-
this.count = count;
59-
}
6052
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class PayloadVerifier implements AutoCloseable{
3535
private static final Logger logger = LoggerFactory.getLogger(PayloadVerifier.class);
3636
private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle");
3737

38-
private final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping;
39-
private final ExecutorService executor;
38+
private transient final BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping;
39+
private transient final ExecutorService executor;
4040

4141
/**
4242
* Create a PayloadVerifier using a cached thread pool and the
@@ -176,12 +176,4 @@ private static void CheckAllFilesInPayloadDirAreListedInAllManifests(final Set<M
176176
Files.walkFileTree(payloadDir, new PayloadFileExistsInAllManifestsVistor(payLoadManifests, ignoreHiddenFiles));
177177
}
178178
}
179-
180-
public BagitAlgorithmNameToSupportedAlgorithmMapping getNameMapping() {
181-
return nameMapping;
182-
}
183-
184-
public ExecutorService getExecutor() {
185-
return executor;
186-
}
187179
}

src/test/java/gov/loc/repository/bagit/reader/TagFileReaderTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public void testCreateFileFromManifestWithAsterisk() throws Exception{
2525
Assertions.assertEquals(bagRootDir.resolve("data/bar/ham.txt"), path);
2626
}
2727

28+
@Test
29+
public void testCreateFileFromManifestWithURISyntax() throws Exception{
30+
Path bagRootDir = Paths.get("/foo");
31+
String uri = "file:///foo/data/bar/ham.txt";
32+
Path path = TagFileReader.createFileFromManifest(bagRootDir, uri);
33+
Assertions.assertEquals(bagRootDir.resolve("data/bar/ham.txt"), path);
34+
}
35+
2836
@Test
2937
public void testBackslashThrowsException() throws Exception{
3038
Path bagRootDir = Paths.get("foo");

src/test/java/gov/loc/repository/bagit/verify/PayloadVerifierTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.nio.file.Path;
55
import java.nio.file.Paths;
6+
import java.util.concurrent.Executors;
67

78
import org.junit.jupiter.api.Assertions;
89
import org.junit.jupiter.api.BeforeEach;
@@ -25,6 +26,18 @@ public class PayloadVerifierTest {
2526
public void setup(){
2627
sut = new PayloadVerifier(new StandardBagitAlgorithmNameToSupportedAlgorithmMapping());
2728
}
29+
30+
@Test
31+
public void testOtherConstructors() throws Exception {
32+
rootDir = Paths.get(new File("src/test/resources/bags/v0_96/bag-with-tagfiles-in-payload-manifest").toURI());
33+
Bag bag = reader.read(rootDir);
34+
35+
sut = new PayloadVerifier();
36+
sut.verifyPayload(bag, true);
37+
38+
sut = new PayloadVerifier(Executors.newCachedThreadPool());
39+
sut.verifyPayload(bag, true);
40+
}
2841

2942
@Test
3043
public void testErrorWhenManifestListFileThatDoesntExist() throws Exception{

0 commit comments

Comments
 (0)