Skip to content

Commit

Permalink
Merge pull request kitodo#6104 from slub/replace_junit4_with_junit5_k…
Browse files Browse the repository at this point in the history
…itodo-dataformat

[Kitodo DataFormat] Replace Junit4 with Junit5
  • Loading branch information
solth authored Jul 10, 2024
2 parents 5981cfa + 95577c3 commit 925ba4d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 38 deletions.
4 changes: 0 additions & 4 deletions Kitodo-DataFormat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@

package org.kitodo.dataformat;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class DataFormatVersionProviderTest {

private DataFormatVersionProvider versionProvider = new DataFormatVersionProvider();
private final DataFormatVersionProvider versionProvider = new DataFormatVersionProvider();

@Test
public void getDataFormatVersionTest() {
Assert.assertEquals("Data format version was not correct", "1.0", versionProvider.getDataFormatVersion());
assertEquals("1.0", versionProvider.getDataFormatVersion(), "Data format version was not correct");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

package org.kitodo.dataformat.access;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.Files;
Expand All @@ -28,13 +30,14 @@
import java.util.List;
import java.util.stream.Collectors;

import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.kitodo.api.MdSec;
import org.kitodo.api.MetadataEntry;
import org.kitodo.api.MetadataGroup;
import org.kitodo.api.dataformat.LogicalDivision;
import org.kitodo.api.dataformat.PhysicalDivision;
import org.kitodo.api.dataformat.MediaVariant;
import org.kitodo.api.dataformat.PhysicalDivision;
import org.kitodo.api.dataformat.ProcessingNote;
import org.kitodo.api.dataformat.View;
import org.kitodo.api.dataformat.Workpiece;
Expand Down Expand Up @@ -251,42 +254,44 @@ public void testSave() throws Exception {

@Test
public void missingMetsHeaderCreationDateDidNotThrowNullPointerException() throws IOException {
Workpiece workpiece = new MetsXmlElementAccess()
.read(new FileInputStream(new File("src/test/resources/meta_missing_createdate.xml")));
assertNotNull(workpiece.getCreationDate());
try (InputStream fileContent = new FileInputStream("src/test/resources/meta_missing_createdate.xml")) {
Workpiece workpiece = new MetsXmlElementAccess()
.read(fileContent);
assertNotNull(workpiece.getCreationDate());
}
}

@Test
public void missingMetsFileForPointer() throws Exception {
try {
new MetsXmlElementAccess().read(new FileInputStream(new File("src/test/resources/meta_missing_file.xml")));
} catch (IllegalArgumentException e) {
assertEquals("Corrupt file: file id for <mets:fptr> not found for div PHYS_0001", e.getMessage());
};
public void missingMetsFileForPointer() {
Exception exception = assertThrows(IllegalArgumentException.class,
() -> new MetsXmlElementAccess().read(
new FileInputStream("src/test/resources/meta_missing_file.xml")
)
);

assertEquals("Corrupt file: file id for <mets:fptr> not found for div PHYS_0001", exception.getMessage());
}

@Test
public void duplicateMetsFileDefinition() throws Exception {
try {
new MetsXmlElementAccess().read(
new FileInputStream(new File("src/test/resources/meta_duplicate_file.xml"))
@Disabled("See GitHub discussion https://github.com/kitodo/kitodo-production/discussions/6087")
public void duplicateMetsFileDefinition() {
Exception exception = assertThrows(IllegalArgumentException.class,
() -> new MetsXmlElementAccess().read(
new FileInputStream("src/test/resources/meta_duplicate_file.xml")
)
);
} catch (IllegalArgumentException e) {
assertEquals("Corrupt file: file with id FILE_0001 is part of multiple groups", e.getMessage());
};

assertEquals("Corrupt file: file with id FILE_0001 is part of multiple groups", exception.getMessage());
}

@Test
public void missingMetsFileGroupUse() throws Exception {
try {
new MetsXmlElementAccess().read(
new FileInputStream(new File("src/test/resources/meta_missing_file_use.xml"))
public void missingMetsFileGroupUse() {
Exception exception = assertThrows(IllegalArgumentException.class,
() -> new MetsXmlElementAccess().read(
new FileInputStream("src/test/resources/meta_missing_file_use.xml")
)
);
} catch (IllegalArgumentException e) {
assertEquals(
"Corrupt file: file use for <mets:fptr> with id FILE_0001 not found in <mets:fileGrp>",
e.getMessage()
);
};

assertEquals("Corrupt file: file use for <mets:fptr> with id FILE_0001 not found in <mets:fileGrp>", exception.getMessage());
}
}

0 comments on commit 925ba4d

Please sign in to comment.