Skip to content

Commit 8fa6af0

Browse files
authored
Migrate to native gradle test task (#3987)
* Migrate to native gradle test task * Run correct test report task on build * Fix build * More detailed output about failed tests * Fix tests
1 parent 9b79ef5 commit 8fa6af0

File tree

14 files changed

+124
-138
lines changed

14 files changed

+124
-138
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ script:
5050
- if [ "$TEST_SUITE" != "guiTest" ] && [ "$TEST_SUITE" != "checkstyle" ] && [ "$TEST_SUITE" != "codecov" ]; then ./gradlew $TEST_SUITE $OPTIONS --scan; fi
5151
- if [ "$TEST_SUITE" == "checkstyle" ]; then ./gradlew checkstyleMain checkstyleTest checkstyleJmh; fi
5252
- if [ "$TEST_SUITE" == "guiTest" ]; then ./buildres/gui-tests.sh; fi
53-
- if [ "$TEST_SUITE" == "codecov" ]; then ./gradlew jacocoJunit5TestReport; bash <(curl -s https://codecov.io/bash); fi
53+
- if [ "$TEST_SUITE" == "codecov" ]; then ./gradlew jacocoTestReport; bash <(curl -s https://codecov.io/bash); fi
5454
- if [ "$DEPENDENCY_UPDATES" == "check" ]; then ./gradlew -q checkOutdatedDependencies; fi
5555

5656
after_failure:

build.gradle

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ buildscript {
1212
url 'https://oss.sonatype.org/content/groups/public'
1313
}
1414
}
15-
dependencies {
16-
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.2.0-M1'
17-
}
1815
}
1916

2017
plugins {
@@ -41,7 +38,6 @@ apply plugin: 'jacoco'
4138
apply plugin: 'install4j'
4239
apply plugin: 'me.champeau.gradle.jmh'
4340
apply plugin: 'checkstyle'
44-
apply plugin: 'org.junit.platform.gradle.plugin'
4541

4642
apply from: 'eclipse.gradle'
4743
apply from: 'localization.gradle'
@@ -154,10 +150,10 @@ dependencies {
154150
compile group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.0.2'
155151
compile group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '2.0.2'
156152

157-
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0-RC1'
153+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0-RC1'
158154
testCompile 'org.junit.jupiter:junit-jupiter-params:5.2.0-RC1'
159-
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0-RC1'
160-
testRuntime 'org.junit.vintage:junit-vintage-engine:5.2.0-RC1'
155+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0-RC1'
156+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.2.0-RC1'
161157
testCompile 'org.junit.platform:junit-platform-launcher:1.2.0-RC1'
162158
testRuntime 'org.apache.logging.log4j:log4j-core:2.11.0'
163159
testRuntime 'org.apache.logging.log4j:log4j-jul:2.11.0'
@@ -311,14 +307,16 @@ javadoc {
311307
}
312308

313309
// Test tasks
314-
junitPlatform {
315-
filters {
316-
tags {
317-
exclude 'DatabaseTest', 'FetcherTest', 'GUITest', 'org.jabref.testutils.category.FetcherTest', 'org.jabref.testutils.category.GUITest'
318-
}
310+
test {
311+
useJUnitPlatform {
312+
excludeTags 'DatabaseTest', 'FetcherTest', 'GUITest', 'org.jabref.testutils.category.FetcherTest', 'org.jabref.testutils.category.GUITest'
313+
}
314+
315+
testLogging {
316+
// set options for log level LIFECYCLE
317+
events "failed"
318+
exceptionFormat "full"
319319
}
320-
321-
logManager 'org.apache.logging.log4j.jul.LogManager'
322320
}
323321

324322
task databaseTest(type: Test) {
@@ -355,8 +353,8 @@ tasks.withType(Test) {
355353
}
356354

357355
task jacocoMerge(type: JacocoMerge) {
358-
executionData file("$buildDir/jacoco/junitPlatformTest.exec"), file("$buildDir/jacoco/databaseTest.exec"), file("$buildDir/jacoco/fetcherTest.exec")
359-
dependsOn junitPlatformTest, databaseTest, fetcherTest
356+
executionData file("$buildDir/jacoco/test.exec"), file("$buildDir/jacoco/databaseTest.exec"), file("$buildDir/jacoco/fetcherTest.exec")
357+
dependsOn test, databaseTest, fetcherTest
360358
}
361359

362360
jacocoTestReport {
@@ -369,27 +367,6 @@ jacocoTestReport {
369367
}
370368
}
371369

372-
afterEvaluate {
373-
def junitPlatformTest = tasks.junitPlatformTest
374-
375-
jacoco {
376-
applyTo(junitPlatformTest)
377-
}
378-
379-
task jacocoJunit5TestReport(type: JacocoReport) {
380-
executionData jacocoMerge.destinationFile
381-
dependsOn jacocoMerge
382-
sourceSets sourceSets.main
383-
sourceDirectories = files(sourceSets.main.allSource.srcDirs)
384-
classDirectories = files(sourceSets.main.output)
385-
386-
reports {
387-
xml.enabled true
388-
html.enabled true
389-
}
390-
}
391-
}
392-
393370
// Code quality tasks
394371
checkstyle {
395372
// do not use other packages for checkstyle, excluding gen(erated) sources

src/main/java/org/jabref/logic/importer/fetcher/IacrEprintFetcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.jabref.logic.net.URLDownload;
2626
import org.jabref.model.entry.BibEntry;
2727
import org.jabref.model.entry.FieldName;
28+
import org.jabref.model.strings.StringUtil;
2829
import org.jabref.model.util.DummyFileUpdateMonitor;
2930

30-
import org.apache.commons.lang3.StringUtils;
3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
3333

@@ -179,7 +179,7 @@ private String getHtml(String url) throws FetcherException {
179179
}
180180

181181
private String getRequiredValueBetween(String from, String to, String haystack) throws FetcherException {
182-
String value = StringUtils.substringBetween(haystack, from, to);
182+
String value = StringUtil.substringBetween(haystack, from, to);
183183
if (value == null) {
184184
throw new FetcherException(Localization.lang("Entry from %0 could not be parsed.", "IACR"));
185185
} else {

src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
4949
List<BibEntry> bibitems = new ArrayList<>();
5050

5151
//use optional here, so that no exception will be thrown if the file is empty
52-
Optional<String> OptionalLines = reader.lines().reduce((line, nextline) -> line + "\n" + nextline);
53-
String linesAsString = OptionalLines.isPresent() ? OptionalLines.get() : "";
52+
String linesAsString = reader.lines().reduce((line, nextline) -> line + "\n" + nextline).orElse("");
5453

5554
String[] entries = linesAsString.replace("\u2013", "-").replace("\u2014", "--").replace("\u2015", "--")
5655
.split("ER -.*\\n");
@@ -207,7 +206,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
207206
}
208207
} else if ("U1".equals(tag) || "U2".equals(tag) || "N1".equals(tag)) {
209208
if (!comment.isEmpty()) {
210-
comment = comment + " ";
209+
comment = comment + OS.NEWLINE;
211210
}
212211
comment = comment + value;
213212
} else if ("M3".equals(tag) || "DO".equals(tag)) {
@@ -269,7 +268,7 @@ else if ("AV".equals(tag)) {
269268
BibEntry entry = new BibEntry(type);
270269
entry.setField(fields);
271270
// month has a special treatment as we use the separate method "setMonth" of BibEntry instead of directly setting the value
272-
month.ifPresent(parsedMonth -> entry.setMonth(parsedMonth));
271+
month.ifPresent(entry::setMonth);
273272
bibitems.add(entry);
274273

275274
}

src/main/java/org/jabref/model/entry/Month.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import org.jabref.model.strings.StringUtil;
1010

11-
import org.apache.commons.lang3.StringUtils;
12-
1311
/**
1412
* Represents a Month of the Year.
1513
*/
@@ -124,8 +122,8 @@ private static Optional<Month> parseGermanShortMonth(String value) {
124122
}
125123

126124
try {
127-
YearMonth yearMonth = YearMonth.parse("1969-" + StringUtils.capitalize(value),
128-
DateTimeFormatter.ofPattern("yyyy-MMM", Locale.GERMAN));
125+
YearMonth yearMonth = YearMonth.parse("1969-" + StringUtil.capitalizeFirst(value),
126+
DateTimeFormatter.ofPattern("yyyy-MMM", Locale.GERMAN));
129127
return Month.getMonthByNumber(yearMonth.getMonthValue());
130128
} catch (DateTimeParseException e) {
131129
return Optional.empty();

src/main/java/org/jabref/model/strings/StringUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ public static String stripAccents(String searchQuery) {
691691
}
692692

693693
/**
694-
* Make first character of String uppercase, and the
695-
* rest lowercase.
694+
* Make first character of String uppercase, and the rest lowercase.
696695
*/
697696
public static String capitalizeFirst(String toCapitalize) {
698697
if (toCapitalize.length() > 1) {
@@ -719,4 +718,8 @@ public static List<String> getStringAsWords(String text) {
719718
public static boolean containsIgnoreCase(String text, String searchString) {
720719
return StringUtils.containsIgnoreCase(text, searchString);
721720
}
721+
722+
public static String substringBetween(String str, String open, String close) {
723+
return StringUtils.substringBetween(str, open, close);
724+
}
722725
}

src/test/java/org/jabref/architecture/MainArchitectureTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class MainArchitectureTests {
3939
private static Map<String, List<String>> exceptions;
4040

4141
@BeforeAll
42-
public static void setUp() {
42+
static void setUp() {
4343
exceptions = new HashMap<>();
4444
// Add exceptions for the architectural test here
4545
// Note that bending the architectural constraints should not be done inconsiderately
@@ -61,7 +61,7 @@ public static void setUp() {
6161
exceptions.put(PACKAGE_ORG_JABREF_MODEL, modelExceptions);
6262
}
6363

64-
public static Stream<Arguments> getPackages() {
64+
private static Stream<Arguments> getPackages() {
6565

6666
return Stream.of(
6767
Arguments.of(PACKAGE_ORG_JABREF_LOGIC, PACKAGE_JAVA_AWT),
@@ -80,7 +80,7 @@ public static Stream<Arguments> getPackages() {
8080

8181
@ParameterizedTest(name = "{index} -- is {0} independent of {1}?")
8282
@MethodSource("getPackages")
83-
public void firstPackageIsIndependentOfSecondPackage(String firstPackage, String secondPackage) throws IOException {
83+
void firstPackageIsIndependentOfSecondPackage(String firstPackage, String secondPackage) throws IOException {
8484
Predicate<String> isExceptionPackage = (s) -> (s.startsWith("import " + secondPackage)
8585
|| s.startsWith("import static " + secondPackage))
8686
&& exceptions.getOrDefault(firstPackage, Collections.emptyList())

src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,40 @@
1616
import static org.mockito.Mockito.mock;
1717
import static org.mockito.Mockito.when;
1818

19-
public class ImportFormatReaderTestParameterless {
19+
class ImportFormatReaderTestParameterless {
2020

2121
private ImportFormatReader reader;
2222
private final FileUpdateMonitor fileMonitor = new DummyFileUpdateMonitor();
2323

2424
@BeforeEach
25-
public void setUp() {
25+
void setUp() {
2626
reader = new ImportFormatReader();
2727
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
2828
when(importFormatPreferences.getEncoding()).thenReturn(StandardCharsets.UTF_8);
2929
reader.resetImportFormats(importFormatPreferences, mock(XmpPreferences.class), fileMonitor);
3030
}
3131

3232
@Test
33-
public void importUnknownFormatThrowsExceptionIfNoMatchingImporterWasFound() throws Exception {
33+
void importUnknownFormatThrowsExceptionIfNoMatchingImporterWasFound() throws Exception {
3434
Path file = Paths.get(ImportFormatReaderTestParameterless.class.getResource("fileformat/emptyFile.xml").toURI());
35-
assertThrows(NullPointerException.class, () -> reader.importUnknownFormat(file, fileMonitor));
35+
assertThrows(ImportException.class, () -> reader.importUnknownFormat(file, fileMonitor));
3636
}
3737

3838
@Test
39-
public void testNullImportUnknownFormatPath() throws Exception {
39+
void importUnknownFormatThrowsExceptionIfPathIsNull() throws Exception {
4040
assertThrows(NullPointerException.class, () -> reader.importUnknownFormat(null, fileMonitor));
4141

4242
}
4343

4444
@Test
45-
public void testNullImportUnknownFormatString() throws Exception {
45+
void importUnknownFormatThrowsExceptionIfDataIsNull() throws Exception {
4646
assertThrows(NullPointerException.class, () -> reader.importUnknownFormat(null));
4747

4848
}
4949

5050
@Test
51-
public void importFromFileWithUnknownFormatThrowsException() throws Exception {
52-
assertThrows(NullPointerException.class, () -> reader.importFromFile("someunknownformat", Paths.get("somepath")));
51+
void importFromFileWithUnknownFormatThrowsException() throws Exception {
52+
assertThrows(ImportException.class, () -> reader.importFromFile("someunknownformat", Paths.get("somepath")));
5353
}
5454

5555
}

src/test/java/org/jabref/logic/importer/fileformat/ModsImporterTestFiles.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,39 @@
66

77
import org.jabref.logic.importer.ImportFormatPreferences;
88

9+
import org.junit.jupiter.api.BeforeEach;
910
import org.junit.jupiter.params.ParameterizedTest;
1011
import org.junit.jupiter.params.provider.MethodSource;
1112
import org.mockito.Answers;
1213

1314
import static org.mockito.Mockito.mock;
15+
import static org.mockito.Mockito.when;
1416

15-
public class ModsImporterTestFiles {
17+
class ModsImporterTestFiles {
1618

1719
private static final String FILE_ENDING = ".xml";
20+
private ImportFormatPreferences importFormatPreferences;
1821

1922
private static Stream<String> fileNames() throws IOException {
20-
Predicate<String> fileName = name -> name.startsWith("MODS")
21-
&& name.endsWith(FILE_ENDING);
23+
Predicate<String> fileName = name -> name.startsWith("MODS") && name.endsWith(FILE_ENDING);
2224
return ImporterTestEngine.getTestFiles(fileName).stream();
2325
}
2426

27+
@BeforeEach
28+
void setUp() {
29+
importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
30+
when(importFormatPreferences.getKeywordSeparator()).thenReturn(',');
31+
}
32+
2533
@ParameterizedTest
2634
@MethodSource("fileNames")
27-
public void testIsRecognizedFormat(String fileName) throws IOException {
28-
ImporterTestEngine.testIsRecognizedFormat(new ModsImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)), fileName);
35+
void testIsRecognizedFormat(String fileName) throws IOException {
36+
ImporterTestEngine.testIsRecognizedFormat(new ModsImporter(importFormatPreferences), fileName);
2937
}
3038

3139
@ParameterizedTest
3240
@MethodSource("fileNames")
33-
public void testImportEntries(String fileName) throws Exception {
34-
ImporterTestEngine.testImportEntries(new ModsImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)
35-
), fileName, FILE_ENDING);
41+
void testImportEntries(String fileName) throws Exception {
42+
ImporterTestEngine.testImportEntries(new ModsImporter(importFormatPreferences), fileName, FILE_ENDING);
3643
}
3744
}

src/test/java/org/jabref/logic/importer/fileformat/RISImporterTestFiles.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.junit.jupiter.params.ParameterizedTest;
88
import org.junit.jupiter.params.provider.MethodSource;
99

10-
public class RISImporterTestFiles {
10+
class RISImporterTestFiles {
1111

1212
private static final String FILE_ENDING = ".ris";
1313

@@ -18,13 +18,13 @@ private static Stream<String> fileNames() throws IOException {
1818

1919
@ParameterizedTest
2020
@MethodSource("fileNames")
21-
public void testIsRecognizedFormat(String fileName) throws IOException {
21+
void testIsRecognizedFormat(String fileName) throws IOException {
2222
ImporterTestEngine.testIsRecognizedFormat(new RisImporter(), fileName);
2323
}
2424

2525
@ParameterizedTest
2626
@MethodSource("fileNames")
27-
public void testImportEntries(String fileName) throws Exception {
27+
void testImportEntries(String fileName) throws Exception {
2828
ImporterTestEngine.testImportEntries(new RisImporter(), fileName, FILE_ENDING);
2929
}
3030
}

0 commit comments

Comments
 (0)