Skip to content

Commit

Permalink
Fix for issue 3959: migrate all tests to JUnit 5 (#4260)
Browse files Browse the repository at this point in the history
* Update migrate from JUnit 4 to JUnit 5

* Update migrate from JUnit 4 to JUnit 5

* Trying to change git accounts on my laptop

* Trying to change git accounts on my laptop

* Trying to change git accounts on my laptop

* Using static assert methods.

* Migrate from JUnit 4 to JUnit 5

*AuthorListParameterTest.java

* Migrate from JUnit 4 to JUnit 5

*XmpUtilWriterTest.java

* Migrate from JUnit 4 to JUnit 5

*XmpUtilReaderTest.java

* Migrate from JUnit 4 to JUnit 5

*SearchQueryHighlightObservableTest.java

    -did not use MockitoExtension.class as its official version has not been released yet.

* Migrate from JUnit 4 to JUnit 5

*CitationEntryTest.java

* Migrate from JUnit 4 to JUnit 5

*RTFCharsTest.java

* Migrate from JUnit 4 to JUnit 5

*ProtectedTermsLoaderTest.java

    -When running tests, outputs in command line are different. I don't know if this change is correct.

* Trying to change to a new branch.

* commit_test

* delete my meaningless txt

* Migrate from JUnit 4 to JUnit 5

*AuthorAndToSemicolonReplacerTest.java

* Migrate from JUnit 4 to JUnit 5

*FileDialogConfigurationTest.java

* Migrate from JUnit 4 to JUnit 5

*IntegrityCheckTest.java

* Migrate from JUnit 4 to JUnit 5

*ModsExportFormatTest.java

* Migrate from JUnit 4 to JUnit 5

*AutoSetFileLinksUtilTest.java

* Migrate from JUnit 4 to JUnit 5

*MsBibExportFormatTest.java

* Migrate from JUnit 4 to JUnit 5

*CsvExportFormatTest.java

* Migrate from JUnit 4 to JUnit 5

*HtmlExportFormatTest.java

* Migrate from JUnit 4 to JUnit 5

*HtmlExportFormatTest.java

* Migrate from JUnit 4 to JUnit 5

*RenamePdfCleanupTest.java

* Migrate from JUnit 4 to JUnit 5

*ProtectedTermsListTest.java

* Migrate from JUnit 4 to JUnit 5

*MoveFilesCleanupTest.java

* Migrate from JUnit 4 to JUnit 5

*ImporterTest.java

* Migrate from JUnit 4 to JUnit 5

    *ExporterTest.java

* Try to trigger the Travis CI build.

* Try to trigger the Travis CI build.

* Migrate from JUnit 4 to JUnit 5

* Try to migrate from JUnit 4 to JUnit 5
    *BibTeXMLExporterTestFiles.java
        *Test, not finished

* Roll back to earlier version.
    *BibTeXMLExporterTestFiles.java
    *CleanupWorkerTest.java

* Migrate from JUnit 4 to JUnit 5
    *ImportFormatReaderIntegrationTest.java

* Migrate from JUnit 4 to JUnit 5
    *MimeTypeDetectorTest.java

* failed to modify CleanupWorkerTest

* failed to modify cleanupWorkTest

* change cleanupWorkerTest to initial

* ***DatabaseTest***
Migrate from JUnit 4 to JUnit 5
    *DBMSProcessorTest.java
        *Wait for the Travis CI

* ***DatabaseTest***
Migrate from JUnit 4 to JUnit 5
    *DBMSProcessorTest.java
        *Wait for the Travis CI

* Migrate from JUnit 4 to JUnit 5
    *BibTeXMLExporterTestFiles.java
    *MSBibExportFormatTestFiles.java
    *All the GUI tests

* Migrate from JUnit 4 to JUnit 5
    *CleanupWorkerTest.java

    *It seems that worker doesn't work in cleanupRenamePdfRenamesRelativeFile() and cleanupRelativePathsConvertAbsoluteToRelativePath()

* Migrate JUnit 4 to JUnit 5.
    *AuthorListParameterTest.java
        -Follow up tp the newest.

* Migrate JUnit 4 to JUnit 5.
    *CleanupWorkerTest.java
        -Delete my sout.

* Migrate JUnit 4 to JUnit 5.
    *EntryTypesTest.java
        -Just some method name changes.

* Fix part of CleanupWorkerTest.
    -cleanupRelativePathsConvertAbsoluteToRelativePath() test passed.
    -The cleanupRenamePdfRenamesRelativeFile() test still failed.

* Migrate and sync.
    *CiteKeyBasedFileFinderTest.java

* Migrate.
    *FileUtilTest.java
Partly migrate.
    *ModsExportFormatTestFiles.java

* Fix CleanupWorkerTest.java

* Fix .travis.yml

* Remove unnecessary @rule.
    *IntegrityCheckTest.java

* AuxParserTest.java

* BibtexParserTest.java

* EntryComparatorTest.java

* Migrate JUnit 4 to JUnit 5 -------by 1160300229

* Migrate. Some tasks by my team members.
    *LinkedFileViewModelTest.java
    *RecursiveTreeItemTest.java
    *UndoTest.java
    *EntryComparatorTest.java
    *MakeLabelWithDatabaseTest.java
    *MakeLabelWithoutDatabaseTest.java
    *CleanupUrlFormatterTest.java
    *BibtexParserTest.java
    *MedlinePlainImporterTest.java
    *SilverPlatterImporterTest.java
    *EntryLinkCheckerTest.java
    *LocalizationKeyTest.java
    *JabRefPreferencesTest.java

* Fix 1160300302's error.

* Remove unnecessary "public".
    *AuxParserTest.java

* fix architecture test by removing check for public make some classes default visibility level

* Fix "cannot find files" problem in JUnit 4.

* Migrate to JUnit 5.
    *BibTeXMLExporterTestFiles.java
    *ModsExportFormatTestFiles.java
    *MSBibExportFormatTestFiles.java

* Change the slash direction.
    *BibTeXMLExporterTestFiles.java
    *ModsExportFormatTestFiles.java
    *MSBibExportFormatTestFiles.java

* fix resolving of paths in msbibexporterpath update junit and correct resource dirs in gradle

* Fix the path issue in
    *BibTeXMLExporterTestFiles.java
    *ModsExportFormatTestFiles.java

* Disable the failing exporter tests and change the build.gradle

* Fix the parent folder issue by make every path to their child once.
    -You can see in the code. :)

* Fix some minor issues.
    -Use the NIO methods in MoveFilesCleanupTest.java

    -Use toAbsolutePath() method in RenamePdfCleanupTest.java

    -Rename "tempFilename" to "tempFilePath" in BibTeXMLExporterTestFiles.java

* include main/java in resources as well convert legalcy file methods to nio
  • Loading branch information
Metatronwings authored and tobiasdiez committed Aug 16, 2018
1 parent 7d4b2ae commit a880add
Show file tree
Hide file tree
Showing 61 changed files with 1,372 additions and 1,390 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

22 changes: 15 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ sourceSets {
srcDirs = ["src/main/java", "src/main/resources"]
}
}
test{
java {
srcDirs = ["src/test/java"]
}
resources {
srcDirs = ["src/test/resources"]
}
}
}

repositories {
Expand Down Expand Up @@ -152,11 +160,11 @@ dependencies {
compile group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.1.2'
compile group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '2.1.2'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testCompile 'org.junit.jupiter:junit-jupiter-params:5.2.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.2.0'
testCompile 'org.junit.platform:junit-platform-launcher:1.2.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.0-RC1'
testCompile 'org.junit.jupiter:junit-jupiter-params:5.3.0-RC1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.0-RC1'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.3.0-RC1'
testCompile 'org.junit.platform:junit-platform-launcher:1.3.0-RC1'
testCompile 'org.junit-pioneer:junit-pioneer:0.1.2'
testRuntime 'org.apache.logging.log4j:log4j-core:2.11.0'
testRuntime 'org.apache.logging.log4j:log4j-jul:2.11.0'
Expand Down Expand Up @@ -197,7 +205,7 @@ dependencyUpdates.resolutionStrategy = {
selection.reject("Cannot be updated to 9.*.* until Jabref works with Java 9")
}
}
rules.withModule("com.github.tomtung:latex2unicode_2.12") { ComponentSelection selection ->
rules.withModule("com.github.tomtung:latex2unicode_2.12") { ComponentSelection selection ->
if (selection.candidate.version ==~ /0.2.2/) { // Reject version higher than 2.0.2
selection.reject("Cannot be updated to 0.2.4 until JabRef is prepared for it")
}
Expand All @@ -212,7 +220,7 @@ dependencyUpdates.resolutionStrategy = {
selection.reject("http://dev.mysql.com/downloads/connector/j/ lists the version 5.* as last stable version.")
}
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/jabref/JabRefPreferencesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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.when;

public class JabRefPreferencesTest {
class JabRefPreferencesTest {

private JabRefPreferences prefs;

@BeforeEach
public void setUp() {
void setUp() {
prefs = mock(JabRefPreferences.class);
when(prefs.getDefaultEncoding()).thenReturn(StandardCharsets.UTF_8);
}

@Test
public void getDefaultEncodingReturnsPreviouslyStoredEncoding() {
void getDefaultEncodingReturnsPreviouslyStoredEncoding() {
prefs.setDefaultEncoding(StandardCharsets.UTF_8);
assertEquals(StandardCharsets.UTF_8, prefs.getDefaultEncoding());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static Stream<String[]> data() {
@MethodSource("data")
public void testsAreIndependent(String forbiddenPackage) throws IOException {
Predicate<String> isForbiddenPackage = (s) -> s.startsWith("import " + forbiddenPackage);
Predicate<String> isExceptionClass = (s) -> exceptions.stream().anyMatch(exception -> s.startsWith("public class " + exception));
Predicate<String> isExceptionClass = (s) -> exceptions.stream().anyMatch(exception -> s.startsWith("class " + exception));

try (Stream<Path> pathStream = Files.walk(Paths.get("src/test/"))) {
List<Path> files = pathStream
Expand Down
9 changes: 4 additions & 5 deletions src/test/java/org/jabref/gui/AbstractUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.nio.file.Paths;

import org.jabref.JabRefMain;
import org.jabref.testutils.category.GUITest;

import org.assertj.swing.fixture.AbstractWindowFixture;
import org.assertj.swing.fixture.FrameFixture;
Expand All @@ -17,12 +16,12 @@
import org.assertj.swing.image.ScreenshotTaker;
import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
import org.assertj.swing.timing.Pause;
import org.junit.Assert;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;

import static org.assertj.swing.launcher.ApplicationLauncher.application;
import static org.junit.jupiter.api.Assertions.assertEquals;

@Category(GUITest.class)
@Tag("GUITest")
public abstract class AbstractUITest extends AssertJSwingJUnitTestCase {

protected final static int SPEED_NORMAL = 50;
Expand Down Expand Up @@ -105,6 +104,6 @@ protected void assertColumnValue(JTableFixture table, int rowIndex, int columnIn
tableContent = table.contents();

String value = tableContent[rowIndex][columnIndex];
Assert.assertEquals(value, selectionValue);
assertEquals(value, selectionValue);
}
}
7 changes: 3 additions & 4 deletions src/test/java/org/jabref/gui/DialogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import javax.swing.JButton;
import javax.swing.JDialog;

import org.jabref.testutils.category.GUITest;

import org.assertj.swing.core.GenericTypeMatcher;
import org.assertj.swing.dependency.jsr305.Nonnull;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.assertj.swing.finder.WindowFinder.findDialog;
/**
* This test has been split to work, the other part can be found at DialogTest2
*/
@Category(GUITest.class)
@Tag("GUITest")
public class DialogTest extends AbstractUITest {

@Test
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/org/jabref/gui/DialogTest2.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package org.jabref.gui;


import javax.swing.JButton;
import javax.swing.JDialog;

import org.jabref.testutils.category.GUITest;

import org.assertj.swing.core.GenericTypeMatcher;
import org.assertj.swing.dependency.jsr305.Nonnull;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.assertj.swing.finder.WindowFinder.findDialog;

/**
* Split of DialogTest, since the test cases were only running separately
*/
@Category(GUITest.class)
@Tag("GUITest")
public class DialogTest2 extends AbstractUITest {
@Test
public void testCloseStyleSelectDialog() {
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/org/jabref/gui/EntryTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
import java.awt.event.KeyEvent;
import java.util.regex.Pattern;

import org.jabref.testutils.category.GUITest;

import org.assertj.swing.fixture.JTableCellFixture;
import org.assertj.swing.fixture.JTableFixture;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

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

/**
* Specific Use-Case:
* I import a database. Then I doubleclick on the first entry in the table to open the entry editor.
* Then I click on the first entry again, and scroll through all of the lists entries, without having to click
* on the table again.
*/
@Category(GUITest.class)
@Tag("GUITest")
public class EntryTableTest extends AbstractUITest{

private final static int SCROLL_ACTION_EXECUTION = 5;
Expand Down Expand Up @@ -51,13 +50,13 @@ public void scrollThroughEntryList() {
//go throught the table and check if the entry with the correct index is selected
for (int i=0; i < SCROLL_ACTION_EXECUTION; i++) {
robot().pressAndReleaseKey(DOWN);
Assert.assertTrue(entryTable.selectionValue() != null);
assertNotNull(entryTable.selectionValue());
assertColumnValue(entryTable, i+1, TITLE_COLUMN_INDEX, entryTable.selectionValue());
}
//do the same going up again
for (int i = SCROLL_ACTION_EXECUTION; i > 0; i--) {
robot().pressAndReleaseKey(UP);
Assert.assertTrue(entryTable.selectionValue() != null);
assertNotNull(entryTable.selectionValue());
assertColumnValue(entryTable, i-1, TITLE_COLUMN_INDEX, entryTable.selectionValue());
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/jabref/gui/GUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import org.assertj.swing.core.GenericTypeMatcher;
import org.assertj.swing.dependency.jsr305.Nonnull;
import org.assertj.swing.fixture.DialogFixture;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.assertj.swing.finder.WindowFinder.findDialog;

@Category(org.jabref.testutils.category.GUITest.class)
@Tag("GUITest")
public class GUITest extends AbstractUITest {

@Test
Expand Down
39 changes: 13 additions & 26 deletions src/test/java/org/jabref/gui/IdFetcherDialogTest.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
package org.jabref.gui;


import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.text.JTextComponent;

import org.jabref.testutils.category.GUITest;

import org.assertj.swing.core.GenericTypeMatcher;
import org.assertj.swing.dependency.jsr305.Nonnull;
import org.assertj.swing.fixture.JTableFixture;
import org.assertj.swing.timing.Condition;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import static org.assertj.swing.finder.WindowFinder.findDialog;
import static org.assertj.swing.timing.Pause.pause;

@RunWith(Parameterized.class)
@Category(GUITest.class)
@Tag("GUITest")
public class IdFetcherDialogTest extends AbstractUITest {

private final String databaseMode, fetcherType, fetchID;

public IdFetcherDialogTest(String databaseMode, String fetcherType, String fetchID) {
this.databaseMode = databaseMode;
this.fetcherType = fetcherType;
this.fetchID = fetchID;
}

@Test
public void insertEmptySearchID() {
@ParameterizedTest
@MethodSource("instancesToTest")
public void insertEmptySearchID(String databaseMode, String fetcherType, String fetchID) {
mainFrame.menuItemWithPath("File", "New " + databaseMode + " database").click();
JTableFixture entryTable = mainFrame.table();

Expand Down Expand Up @@ -76,8 +63,9 @@ protected boolean isMatching(@Nonnull JButton jButton) {
entryTable.requireRowCount(0);
}

@Test
public void testFetcherDialog() {
@ParameterizedTest
@MethodSource("instancesToTest")
public void testFetcherDialog(String databaseMode, String fetcherType, String fetchID) {
mainFrame.menuItemWithPath("File", "New " + databaseMode + " database").click();
JTableFixture entryTable = mainFrame.table();

Expand Down Expand Up @@ -123,9 +111,8 @@ public boolean test() {
}


@Parameterized.Parameters(name = "{index}: {0} : {1} : {2}")
public static Collection<Object[]> instancesToTest() {
return Arrays.asList(
public static Stream<Object[]> instancesToTest() {
return Stream.of(
new Object[]{"BibTeX", "DOI", "10.1002/9781118257517"},
new Object[]{"biblatex", "DOI", "10.1002/9781118257517"},
new Object[]{"BibTeX", "ISBN", "9780321356680"},
Expand Down
Loading

0 comments on commit a880add

Please sign in to comment.