Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate majority of tests to junit5 #3711

Merged
merged 8 commits into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, not sure if I like these Supplier Lambdas...Are they really needed? Makes the methods look more complex and I doubt that the evaluation of the message really takes a long time. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the beginning I did not see that I can pass the message as parameter without a supplier . The later tests are without. The supplier is only needed in the assertThroes


// 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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MainArchitectureTests {

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

public MainArchitectureTests(String firstPackage, String secondPackage) {
this.firstPackage = firstPackage;
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
28 changes: 15 additions & 13 deletions src/test/java/org/jabref/cli/JabRefCLITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@

import java.util.Collections;

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

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

public class JabRefCLITest {

@Test
public void testCLIParsingLongOptions() {
JabRefCLI cli = new JabRefCLI(new String[] {"--nogui", "--import=some/file", "--output=some/export/file"});

Assert.assertEquals(Collections.emptyList(), cli.getLeftOver());
Assert.assertEquals("some/file", cli.getFileImport());
Assert.assertTrue(cli.isDisableGui());
Assert.assertEquals("some/export/file", cli.getFileExport());
assertEquals(Collections.emptyList(), cli.getLeftOver());
assertEquals("some/file", cli.getFileImport());
assertTrue(cli.isDisableGui());
assertEquals("some/export/file", cli.getFileExport());
}

@Test
public void testCLIParsingShortOptions() {
JabRefCLI cli = new JabRefCLI(new String[] {"-n", "-i=some/file", "-o=some/export/file"});

Assert.assertEquals(Collections.emptyList(), cli.getLeftOver());
Assert.assertEquals("some/file", cli.getFileImport());
Assert.assertTrue(cli.isDisableGui());
Assert.assertEquals("some/export/file", cli.getFileExport());
assertEquals(Collections.emptyList(), cli.getLeftOver());
assertEquals("some/file", cli.getFileImport());
assertTrue(cli.isDisableGui());
assertEquals("some/export/file", cli.getFileExport());
}

@Test
public void testPreferencesExport() {
JabRefCLI cli = new JabRefCLI(new String[] {"-n", "-x=some/file"});

Assert.assertEquals(Collections.emptyList(), cli.getLeftOver());
Assert.assertEquals("some/file", cli.getPreferencesExport());
Assert.assertTrue(cli.isDisableGui());
assertEquals(Collections.emptyList(), cli.getLeftOver());
assertEquals("some/file", cli.getPreferencesExport());
assertTrue(cli.isDisableGui());
}

}
Loading