Skip to content

Commit

Permalink
Merge pull request #3711 from JabRef/junit5
Browse files Browse the repository at this point in the history
migrate majority of tests to junit5
  • Loading branch information
koppor authored Feb 11, 2018
2 parents 9ab29d5 + 276f549 commit 1cef924
Show file tree
Hide file tree
Showing 246 changed files with 2,582 additions and 2,668 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.jabref.JabRefExecutorService;
import org.jabref.JabRefGUI;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.importer.EntryFromFileCreator;
import org.jabref.gui.importer.EntryFromFileCreatorManager;
import org.jabref.gui.importer.UnlinkedFilesCrawler;
Expand Down Expand Up @@ -167,7 +168,7 @@ public FindUnlinkedFilesDialog(Frame owner, JabRefFrame frame, BasePanel panel)
restoreSizeOfDialog();

databaseContext = panel.getDatabaseContext();
creatorManager = new EntryFromFileCreatorManager();
creatorManager = new EntryFromFileCreatorManager(ExternalFileTypes.getInstance());
crawler = new UnlinkedFilesCrawler(databaseContext);

lastSelectedDirectory = loadLastSelectedDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public final class EntryFromFileCreatorManager {
private final List<EntryFromFileCreator> entryCreators;


public EntryFromFileCreatorManager() {
public EntryFromFileCreatorManager(ExternalFileTypes externalFilesTypes) {

entryCreators = new ArrayList<>(10);
entryCreators.add(new EntryFromPDFCreator());
entryCreators.add(new EntryFromPDFCreator(externalFilesTypes));

// add a creator for each ExternalFileType if there is no specialized
// creator existing.
Collection<ExternalFileType> fileTypes = ExternalFileTypes.getInstance().getExternalFileTypeSelection();
Collection<ExternalFileType> fileTypes = externalFilesTypes.getExternalFileTypeSelection();

for (ExternalFileType exFileType : fileTypes) {
if (!hasSpecialisedCreatorForExternalFileType(exFileType)) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/gui/importer/EntryFromPDFCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
*/
public class EntryFromPDFCreator extends EntryFromFileCreator {

public EntryFromPDFCreator() {
super(EntryFromPDFCreator.getPDFExternalFileType());
public EntryFromPDFCreator(ExternalFileTypes externalFileTypes) {
super(EntryFromPDFCreator.getPDFExternalFileType(externalFileTypes));
}

private static ExternalFileType getPDFExternalFileType() {
Optional<ExternalFileType> pdfFileType = ExternalFileTypes.getInstance().getExternalFileTypeByExt("pdf");
private static ExternalFileType getPDFExternalFileType(ExternalFileTypes externalFileTypes) {
Optional<ExternalFileType> pdfFileType = externalFileTypes.getExternalFileTypeByExt("pdf");
if (!pdfFileType.isPresent()) {
return new ExternalFileType("PDF", "pdf", "application/pdf", "evince", "pdfSmall", IconTheme.JabRefIcon.PDF_FILE.getSmallIcon());
}
Expand Down Expand Up @@ -90,7 +90,7 @@ private void addEntryDataFromPDDocumentInformation(File pdfFile, BibEntry entry)
if (pdfDocInfo != null) {
Optional<BibEntry> entryDI = XMPUtil
.getBibtexEntryFromDocumentInformation(document
.getDocumentInformation());
.getDocumentInformation());
if (entryDI.isPresent()) {
addEntryDataToEntry(entry, entryDI.get());
Calendar creationDate = pdfDocInfo.getCreationDate();
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/jabref/CodeStyleTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import org.jabref.model.strings.StringUtil;

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

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

public class CodeStyleTests {

Expand All @@ -17,8 +18,8 @@ public void StringUtilClassIsSmall() throws Exception {
Path path = Paths.get("src", "main", "java", StringUtil.class.getName().replace('.', '/') + ".java");
int lineCount = Files.readAllLines(path, StandardCharsets.UTF_8).size();

Assert.assertTrue("StringUtil increased in size. "
assertTrue(lineCount <= 722, "StringUtil increased in size. "
+ "We try to keep this class as small as possible. "
+ "Thus think twice if you add something to StringUtil.", lineCount <= 722);
+ "Thus think twice if you add something to StringUtil.");
}
}
113 changes: 0 additions & 113 deletions src/test/java/org/jabref/SearchQueryHighlightListenerTest.java

This file was deleted.

16 changes: 7 additions & 9 deletions src/test/java/org/jabref/TestIconsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

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

public class TestIconsProperties {

Expand All @@ -31,15 +31,14 @@ public void testExistenceOfIconImagesReferencedFromIconsProperties() throws IOEx
try (Reader reader = Files.newBufferedReader(Paths.get(iconsPropertiesPath))) {
properties.load(reader);
}
assertFalse("There must be loaded properties after loading " + iconsPropertiesPath,
properties.entrySet().isEmpty());
assertFalse(properties.entrySet().isEmpty(), "There must be loaded properties after loading " + iconsPropertiesPath);

// check that each key references an existing file
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String name = entry.getKey().toString();
String value = entry.getValue().toString();

assertTrue("Referenced image (" + name + " --> " + value + " does not exist in folder " + folder, Files.exists(Paths.get(folder, value)));
assertTrue(Files.exists(Paths.get(folder, value)), "Referenced image (" + name + " --> " + value + " does not exist in folder " + folder);
}

// check that each image in the folder is referenced by a key
Expand All @@ -51,8 +50,7 @@ public void testExistenceOfIconImagesReferencedFromIconsProperties() throws IOEx
try (Stream<Path> pathStream = Files.list(Paths.get(folder))) {
List<String> fileNamesInFolder = pathStream.map(p -> p.getFileName().toString()).collect(Collectors.toList());
fileNamesInFolder.removeAll(imagesReferencedFromProperties);

assertEquals("Images are in the folder that are unused", "[red.png]", fileNamesInFolder.toString());
assertEquals("[red.png]", fileNamesInFolder.toString(), "Images are in the folder that are unused");
}
}
}
69 changes: 31 additions & 38 deletions src/test/java/org/jabref/architecture/MainArchitectureTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -16,11 +15,11 @@
import java.util.stream.Stream;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class MainArchitectureTests {

public static final String CLASS_ORG_JABREF_GLOBALS = "org.jabref.Globals";
Expand All @@ -35,17 +34,13 @@ public class MainArchitectureTests {
private static final String EXCEPTION_PACKAGE_JAVA_FX_BEANS = "javafx.beans";
private static final String EXCEPTION_CLASS_JAVA_FX_COLOR = "javafx.scene.paint.Color";

private final String firstPackage;
private final String secondPackage;
private Map<String, List<String>> exceptions;

public MainArchitectureTests(String firstPackage, String secondPackage) {
this.firstPackage = firstPackage;
this.secondPackage = secondPackage;
private static Map<String, List<String>> exceptions;

@BeforeAll
public static void setUp() {
exceptions = new HashMap<>();
// Add exceptions for the architectural test here
// Note that bending the architectural constraints should not be done inconsiderately
exceptions = new HashMap<>();

List<String> logicExceptions = new ArrayList<>(4);
logicExceptions.add(EXCEPTION_PACKAGE_JAVA_AWT_GEOM);
Expand All @@ -63,32 +58,29 @@ public MainArchitectureTests(String firstPackage, String secondPackage) {
exceptions.put(PACKAGE_ORG_JABREF_MODEL, modelExceptions);
}


@Parameterized.Parameters(name = "{index} -- is {0} independent of {1}?")
public static Iterable<Object[]> data() {
return Arrays.asList(
new Object[][]{
{PACKAGE_ORG_JABREF_LOGIC, PACKAGE_JAVA_AWT},
{PACKAGE_ORG_JABREF_LOGIC, PACKAGE_JAVAX_SWING},
{PACKAGE_ORG_JABREF_LOGIC, PACKAGE_JAVA_FX},
{PACKAGE_ORG_JABREF_LOGIC, PACKAGE_ORG_JABREF_GUI},
{PACKAGE_ORG_JABREF_LOGIC, CLASS_ORG_JABREF_GLOBALS},

{PACKAGE_ORG_JABREF_MODEL, PACKAGE_JAVA_AWT},
{PACKAGE_ORG_JABREF_MODEL, PACKAGE_JAVAX_SWING},
{PACKAGE_ORG_JABREF_MODEL, PACKAGE_JAVA_FX},
{PACKAGE_ORG_JABREF_MODEL, PACKAGE_ORG_JABREF_GUI},
{PACKAGE_ORG_JABREF_MODEL, PACKAGE_ORG_JABREF_LOGIC},
{PACKAGE_ORG_JABREF_MODEL, CLASS_ORG_JABREF_GLOBALS}
}
);
public static Stream<Arguments> getPackages() {

return Stream.of(
Arguments.of(PACKAGE_ORG_JABREF_LOGIC, PACKAGE_JAVA_AWT),
Arguments.of(PACKAGE_ORG_JABREF_LOGIC, PACKAGE_JAVAX_SWING),
Arguments.of(PACKAGE_ORG_JABREF_LOGIC, PACKAGE_JAVA_FX),
Arguments.of(PACKAGE_ORG_JABREF_LOGIC, PACKAGE_ORG_JABREF_GUI),
Arguments.of(PACKAGE_ORG_JABREF_LOGIC, CLASS_ORG_JABREF_GLOBALS),

Arguments.of(PACKAGE_ORG_JABREF_MODEL, PACKAGE_JAVA_AWT),
Arguments.of(PACKAGE_ORG_JABREF_MODEL, PACKAGE_JAVAX_SWING),
Arguments.of(PACKAGE_ORG_JABREF_MODEL, PACKAGE_JAVA_FX),
Arguments.of(PACKAGE_ORG_JABREF_MODEL, PACKAGE_ORG_JABREF_GUI),
Arguments.of(PACKAGE_ORG_JABREF_MODEL, PACKAGE_ORG_JABREF_LOGIC),
Arguments.of(PACKAGE_ORG_JABREF_MODEL, CLASS_ORG_JABREF_GLOBALS));
}

@Test
public void firstPackageIsIndependentOfSecondPackage() throws IOException {
Predicate<String> isExceptionPackage = (s) ->
s.startsWith("import " + secondPackage)
&& exceptions.getOrDefault(firstPackage, Collections.emptyList()).stream()
@ParameterizedTest(name = "{index} -- is {0} independent of {1}?")
@MethodSource("getPackages")
public void firstPackageIsIndependentOfSecondPackage(String firstPackage, String secondPackage) throws IOException {
Predicate<String> isExceptionPackage = (s) -> s.startsWith("import " + secondPackage)
&& exceptions.getOrDefault(firstPackage, Collections.emptyList())
.stream()
.noneMatch(exception -> s.startsWith("import " + exception));

Predicate<String> isPackage = (s) -> s.startsWith("package " + firstPackage);
Expand All @@ -109,7 +101,8 @@ public void firstPackageIsIndependentOfSecondPackage() throws IOException {
} catch (IOException e) {
return false;
}
}).collect(Collectors.toList());
})
.collect(Collectors.toList());

Assert.assertEquals("The following classes are not allowed to depend on " + secondPackage,
Collections.emptyList(), files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import org.jabref.model.cleanup.FieldFormatterCleanup;
import org.jabref.model.cleanup.FieldFormatterCleanups;

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

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/org/jabref/cli/AuxCommandLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
import org.jabref.model.database.BibDatabase;
import org.jabref.model.util.DummyFileUpdateMonitor;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;

public class AuxCommandLineTest {

private ImportFormatPreferences importFormatPreferences;

@Before
@BeforeEach
public void setUp() throws Exception {
importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
}
Expand All @@ -40,8 +41,8 @@ public void test() throws URISyntaxException, IOException {

AuxCommandLine auxCommandLine = new AuxCommandLine(auxFile.getAbsolutePath(), result.getDatabase());
BibDatabase newDB = auxCommandLine.perform();
Assert.assertNotNull(newDB);
Assert.assertEquals(2, newDB.getEntries().size());
assertNotNull(newDB);
assertEquals(2, newDB.getEntries().size());
}
}

Expand Down
Loading

0 comments on commit 1cef924

Please sign in to comment.