Skip to content

Commit

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

[Kitodo Core] Replace Junit 4 with Junit 5
  • Loading branch information
solth authored Jul 31, 2024
2 parents 62ef5a4 + 811c1d2 commit a690e9b
Show file tree
Hide file tree
Showing 133 changed files with 2,488 additions and 2,985 deletions.
12 changes: 8 additions & 4 deletions Kitodo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
Expand All @@ -250,6 +246,14 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

package de.sub.goobi.helper.encryption;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;

import org.bouncycastle.crypto.digests.MD4Digest;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class MD4Test {
private static HashMap<String, byte[]> testData;
Expand All @@ -43,8 +43,7 @@ public void encryptTest() {
byte[] encrypted = new byte[digester.getDigestSize()];
digester.update(unicodePassword, 0, unicodePassword.length);
digester.doFinal(encrypted, 0);
assertArrayEquals("Encrypted password doesn't match the precomputed one! ",
encrypted, testData.get(clearText));
assertArrayEquals(encrypted, testData.get(clearText), "Encrypted password doesn't match the precomputed one! ");
}
}
}
10 changes: 5 additions & 5 deletions Kitodo/src/test/java/org/kitodo/BasePrimefaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public abstract class BasePrimefaceTest {

@Mock
Expand All @@ -31,7 +31,7 @@ public abstract class BasePrimefaceTest {
protected ExternalContext externalContext;


@Before
@BeforeEach
public void initPrimeface() {
when(facesContext.getExternalContext()).thenReturn(externalContext);
}
Expand Down
8 changes: 4 additions & 4 deletions Kitodo/src/test/java/org/kitodo/config/ConfigCoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@

package org.kitodo.config;

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

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ConfigCoreTest {

@Test
public void shouldGetKitodoConfigDirectory() {
String expected = "src/test/resources/";

assertEquals("Directory was queried incorrectly!", expected, ConfigCore.getKitodoConfigDirectory());
assertEquals(expected, ConfigCore.getKitodoConfigDirectory(), "Directory was queried incorrectly!");
}

@Test
public void shouldGetKitodoDataDirectory() {
String expected = "src/test/resources/metadata/";

assertEquals("Directory was queried incorrectly!", expected, ConfigCore.getKitodoDataDirectory());
assertEquals(expected, ConfigCore.getKitodoDataDirectory(), "Directory was queried incorrectly!");
}
}
26 changes: 13 additions & 13 deletions Kitodo/src/test/java/org/kitodo/config/ConfigProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,64 @@

package org.kitodo.config;

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

import java.io.IOException;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.kitodo.FileLoader;
import org.kitodo.exceptions.DoctypeMissingException;

import static org.junit.Assert.assertEquals;

public class ConfigProjectTest {

private static ConfigProject configProject;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
FileLoader.createConfigProjectsFile();
configProject = new ConfigProject("default");
}

@AfterClass
@AfterAll
public static void tearDown() throws IOException {
FileLoader.deleteConfigProjectsFile();
}

@Test
public void shouldGetConfigProjectsForItems() {
List<String> items = configProject.getParamList("createNewProcess.itemlist.item");
assertEquals("Incorrect amount of items!", 10, items.size());
assertEquals(10, items.size(), "Incorrect amount of items!");
}

@Test
public void shouldGetConfigProjectsForSelectItems() {
List<String> items = configProject.getParamList("createNewProcess.itemlist.item(1).select");
assertEquals("Incorrect amount of select items for second element!", 3, items.size());
assertEquals(3, items.size(), "Incorrect amount of select items for second element!");
}

@Test
public void shouldGetConfigProjectsForProcessTitles() {
List<String> processTitles = configProject.getParamList("createNewProcess.itemlist.processtitle");
assertEquals("Incorrect amount of process titles!", 5, processTitles.size());
assertEquals(5, processTitles.size(), "Incorrect amount of process titles!");
}

@Test
public void shouldGetDocType() throws DoctypeMissingException {
assertEquals("Document type is incorrect!", "monograph", configProject.getDocType());
assertEquals("monograph", configProject.getDocType(), "Document type is incorrect!");
}

@Test
public void shouldGetTifDefinition() throws DoctypeMissingException {
assertEquals("Tif definition is incorrect!", "kitodo", configProject.getTifDefinition());
assertEquals("kitodo", configProject.getTifDefinition(), "Tif definition is incorrect!");
}

@Test
public void shouldGetTitleDefinition() throws DoctypeMissingException {
String titleDefinition = configProject.getTitleDefinition();
String expected = "TSL_ATS+'_'+CatalogIDDigital";
assertEquals("Title definition is incorrect!", expected, titleDefinition);
assertEquals(expected, titleDefinition, "Title definition is incorrect!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,77 +11,68 @@

package org.kitodo.config.enums;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.FileNotFoundException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.kitodo.FileLoader;
import org.kitodo.config.ConfigCore;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class KitodoConfigFileTest {

@Rule
public final ExpectedException exception = ExpectedException.none();

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
FileLoader.createConfigProjectsFile();
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
FileLoader.deleteConfigProjectsFile();
}

@Test
public void shouldGetFileNameTest() {
assertEquals("Config projects file name is incorrect!", "kitodo_projects.xml",
String.valueOf(KitodoConfigFile.PROJECT_CONFIGURATION));
assertEquals("Config projects file name is incorrect!", "kitodo_projects.xml",
KitodoConfigFile.PROJECT_CONFIGURATION.getName());
assertEquals("kitodo_projects.xml", String.valueOf(KitodoConfigFile.PROJECT_CONFIGURATION), "Config projects file name is incorrect!");
assertEquals("kitodo_projects.xml", KitodoConfigFile.PROJECT_CONFIGURATION.getName(), "Config projects file name is incorrect!");
}

@Test
public void shouldGetAbsolutePathTest() {
assertTrue("Config projects file absolute path is incorrect!",
KitodoConfigFile.PROJECT_CONFIGURATION.getAbsolutePath().contains("Kitodo" + File.separator + "src"
+ File.separator + "test" + File.separator + "resources" + File.separator + "kitodo_projects.xml"));
assertTrue(KitodoConfigFile.PROJECT_CONFIGURATION.getAbsolutePath().contains("Kitodo" + File.separator + "src"
+ File.separator + "test" + File.separator + "resources" + File.separator + "kitodo_projects.xml"), "Config projects file absolute path is incorrect!");
}

@Test
public void shouldGetFileTest() {
assertEquals("Config projects file absolute path is incorrect!",
new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_projects.xml"),
KitodoConfigFile.PROJECT_CONFIGURATION.getFile());
assertEquals(new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_projects.xml"), KitodoConfigFile.PROJECT_CONFIGURATION.getFile(), "Config projects file absolute path is incorrect!");
}

@Test
public void shouldGetByFileNameTest() throws FileNotFoundException {
assertEquals("Config projects file doesn't exists for given!", KitodoConfigFile.PROJECT_CONFIGURATION,
KitodoConfigFile.getByName("kitodo_projects.xml"));
assertEquals(KitodoConfigFile.PROJECT_CONFIGURATION, KitodoConfigFile.getByName("kitodo_projects.xml"), "Config projects file doesn't exists for given!");
}

@Test
public void shouldNotGetByFileNameTest() throws FileNotFoundException {
exception.expect(FileNotFoundException.class);
exception.expectMessage("Configuration file 'kitodo_nonexistent.xml' doesn't exists!");
KitodoConfigFile.getByName("kitodo_nonexistent.xml");
public void shouldNotGetByFileNameTest() {
Exception exception = assertThrows(FileNotFoundException.class,
() -> KitodoConfigFile.getByName("kitodo_nonexistent.xml"));

assertEquals("Configuration file 'kitodo_nonexistent.xml' doesn't exists!", exception.getMessage());
}

@Test
public void configFileShouldExistTest() {
assertTrue("Config projects file doesn't exist!", KitodoConfigFile.PROJECT_CONFIGURATION.exists());
assertTrue(KitodoConfigFile.PROJECT_CONFIGURATION.exists(), "Config projects file doesn't exist!");
}

@Test
public void configFileShouldNotExistTest() {
assertTrue("Config OPAC file exists!", KitodoConfigFile.OPAC_CONFIGURATION.exists());
assertTrue(KitodoConfigFile.OPAC_CONFIGURATION.exists(), "Config OPAC file exists!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@

package org.kitodo.config.enums;

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

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ParameterCoreTest {

@Test
public void shouldGetParameterWithoutDefaultValueTest() {
assertNull("Default value for param exists!",
ParameterCore.DIR_USERS.getParameter().getDefaultValue());
assertNull(ParameterCore.DIR_USERS.getParameter().getDefaultValue(), "Default value for param exists!");
}

@Test
public void shouldOverrideToStringWithParameterKeyTests() {
ParameterCore parameterCore = ParameterCore.DIR_USERS;
assertEquals("Methods toString() was not overridden!", parameterCore.getParameter().getKey(),
String.valueOf(parameterCore));
assertEquals(parameterCore.getParameter().getKey(), String.valueOf(parameterCore), "Methods toString() was not overridden!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,34 @@

package org.kitodo.config.xml.fileformats;

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

import java.util.Locale;
import java.util.Locale.LanguageRange;

import javax.xml.bind.JAXBException;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.kitodo.api.imagemanagement.ImageFileFormat;


public class FileFormatsConfigIT {
@Test
public void testFileFormatsConfig() throws JAXBException {
assertEquals("kitodo_fileFormats.xml does not contain exactly 8 entries", 8,
FileFormatsConfig.getFileFormats().size());
assertEquals(8, FileFormatsConfig.getFileFormats().size(), "kitodo_fileFormats.xml does not contain exactly 8 entries");

FileFormat tiff = FileFormatsConfig.getFileFormat("image/tiff").get();
assertEquals("Wrong label of TIFF file format", "Tagged Image File Format (image/tiff, *.tif)",
tiff.getLabel());
assertEquals("Wrong label with declared language range of TIFF file format",
"Tagged Image File Format (image/tiff, *.tif)",
tiff.getLabel(Locale.LanguageRange.parse("fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5")));
assertTrue("Long time preservation validation file type is missing for TIFF file format",
tiff.getFileType().isPresent());
assertEquals("Image management file format of TIFF file format is not TIFF", ImageFileFormat.TIFF,
tiff.getImageFileFormat().get());
assertEquals("Tagged Image File Format (image/tiff, *.tif)", tiff.getLabel(), "Wrong label of TIFF file format");
assertEquals("Tagged Image File Format (image/tiff, *.tif)", tiff.getLabel(LanguageRange.parse("fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5")), "Wrong label with declared language range of TIFF file format");
assertTrue(tiff.getFileType().isPresent(), "Long time preservation validation file type is missing for TIFF file format");
assertEquals(ImageFileFormat.TIFF, tiff.getImageFileFormat().get(), "Image management file format of TIFF file format is not TIFF");
}

@Test
public void testFileFormatsConfigTransliteration() throws JAXBException {
FileFormat gif = FileFormatsConfig.getFileFormat("image/gif").get();
assertEquals("Wrong label without declared language of GIF file format",
"Graphics Interchange Format (image/gif, *.gif)", gif.getLabel());
assertEquals("Wrong label for language requesting arab of GIF file format",
"تنسيق تبادل الرسومات (image/gif, *.gif)", gif.getLabel(LanguageRange.parse("fr;q=0.9,ar;q=0.4,*;q=0.2")));
assertEquals("Wrong label for language requesting no specialized label of GIF file format",
"Graphics Interchange Format (image/gif, *.gif)",
gif.getLabel(LanguageRange.parse("en;q=0.9,fr;q=0.4,*;q=0.2")));
assertEquals("Graphics Interchange Format (image/gif, *.gif)", gif.getLabel(), "Wrong label without declared language of GIF file format");
assertEquals("تنسيق تبادل الرسومات (image/gif, *.gif)", gif.getLabel(LanguageRange.parse("fr;q=0.9,ar;q=0.4,*;q=0.2")), "Wrong label for language requesting arab of GIF file format");
assertEquals("Graphics Interchange Format (image/gif, *.gif)", gif.getLabel(LanguageRange.parse("en;q=0.9,fr;q=0.4,*;q=0.2")), "Wrong label for language requesting no specialized label of GIF file format");
}
}
Loading

0 comments on commit a690e9b

Please sign in to comment.