Skip to content

Commit

Permalink
fix some more tests
Browse files Browse the repository at this point in the history
convert architecture test to junit5
  • Loading branch information
Siedlerchr committed Feb 9, 2018
1 parent e7f245a commit 276f549
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 68 deletions.
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 final 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
6 changes: 3 additions & 3 deletions src/test/java/org/jabref/gui/ClipBoardManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.jabref.logic.importer.ParserResult;
import org.jabref.model.entry.BibEntry;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;

import static org.junit.Assert.*;
Expand All @@ -26,7 +26,7 @@ public class ClipBoardManagerTest {
private Transferable content;
private ImportFormatReader importFormatReader;

@Before
@BeforeEach
public void setUp() throws Exception {
importFormatReader = mock(ImportFormatReader.class);

Expand Down
31 changes: 11 additions & 20 deletions src/test/java/org/jabref/gui/UpdateTimestampListenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.JabRefPreferences;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
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 UpdateTimestampListenerTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

private BibDatabase database;
private BibEntry bibEntry;

private JabRefPreferences preferencesMock;
private TimestampPreferences timestampPreferencesMock;

@Before
public void setUp(){
@BeforeEach
public void setUp() {
database = new BibDatabase();
bibEntry = new BibEntry();

Expand All @@ -41,7 +36,7 @@ public void setUp(){
}

@Test
public void updateTimestampEnabled(){
public void updateTimestampEnabled() {
final String timestampField = "timestamp";
final String baseDate = "2000-1-1";
final String newDate = "2000-1-2";
Expand All @@ -54,19 +49,17 @@ public void updateTimestampEnabled(){

bibEntry.setField(timestampField, baseDate);

assertEquals("Initial timestamp not set correctly",
Optional.of(baseDate), bibEntry.getField(timestampField));
assertEquals(Optional.of(baseDate), bibEntry.getField(timestampField), "Initial timestamp not set correctly");

database.registerListener(new UpdateTimestampListener(preferencesMock));

bibEntry.setField("test", "some value");

assertEquals("Timestamp not set correctly after entry changed",
Optional.of(newDate), bibEntry.getField(timestampField));
assertEquals(Optional.of(newDate), bibEntry.getField(timestampField), "Timestamp not set correctly after entry changed");
}

@Test
public void updateTimestampDisabled(){
public void updateTimestampDisabled() {
final String timestampField = "timestamp";
final String baseDate = "2000-1-1";
final String newDate = "2000-1-2";
Expand All @@ -79,14 +72,12 @@ public void updateTimestampDisabled(){

bibEntry.setField(timestampField, baseDate);

assertEquals("Initial timestamp not set correctly",
Optional.of(baseDate), bibEntry.getField(timestampField));
assertEquals(Optional.of(baseDate), bibEntry.getField(timestampField), "Initial timestamp not set correctly");

database.registerListener(new UpdateTimestampListener(preferencesMock));

bibEntry.setField("test", "some value");

assertEquals("New timestamp set after entry changed even though updates were disabled",
Optional.of(baseDate), bibEntry.getField(timestampField));
assertEquals(Optional.of(baseDate), bibEntry.getField(timestampField), "New timestamp set after entry changed even though updates were disabled");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class DefaultAutoCompleterTest {

private WordSuggestionProvider autoCompleter;

@Test
public void initAutoCompleterWithNullFieldThrowsException() {
assertThrows(NullPointerException.class, () -> new WordSuggestionProvider(null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ public void trimFieldContents() throws IOException {
assertEquals(expected, actual);
}

public void writeThrowsErrorIfFieldContainsUnbalancedBraces() throws IOException {
@Test
public void writeThrowsErrorIfFieldContainsUnbalancedBraces() {
StringWriter stringWriter = new StringWriter();

BibEntry entry = new BibEntry("article");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public class BibTeXMLImporterTestFiles {

private static final String FILE_ENDING = ".xml";

@SuppressWarnings("unused")
private static Stream<String> fileNames() throws IOException {
Predicate<String> fileName = name -> name.startsWith("BibTeXMLImporterTest")
&& name.endsWith(FILE_ENDING);
return ImporterTestEngine.getTestFiles(fileName).stream();
}

@SuppressWarnings("unused")
private static Stream<String> nonBibTeXMLfileNames() throws IOException {
Predicate<String> fileName = name -> !name.startsWith("BibTeXMLImporterTest");
return ImporterTestEngine.getTestFiles(fileName).stream();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jabref/logic/net/MimeTypeDetectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import static org.junit.Assert.assertTrue;

public class MimeTypeDetectorTest {
@Rule
public WireMockRule wireMockRule = new WireMockRule();

@Rule public WireMockRule wireMockRule = new WireMockRule();

@Test
public void handlePermanentRedirections() throws IOException {
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class DBMSProcessorTest {
private DBMSConnection dbmsConnection;
private DBMSProcessor dbmsProcessor;

@Parameter
public DBMSType dbmsType;
@Parameter public DBMSType dbmsType;

@BeforeEach
public void setUp() throws SQLException, InvalidDBMSConnectionPropertiesException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jabref.logic.util;

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;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/jabref/model/TreeNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void setUp() {
subscriber = mock(Consumer.class);
}

@Test
public void constructorChecksThatClassImplementsCorrectInterface() {
assertThrows(UnsupportedOperationException.class, () -> new WrongTreeNodeImplementation());

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jabref/model/entry/FieldNameTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jabref.model.entry;

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

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

Expand Down

0 comments on commit 276f549

Please sign in to comment.