Skip to content

Commit

Permalink
Fix medline and convert some fetchers to junit5 where possible (JabRe…
Browse files Browse the repository at this point in the history
…f#3668)

* Fix medline and conver some fetchers to junit5 where possible

* add missing test annotation to medline
Convert rest of fetcher tests to junit5

* fix isbn fetcher fest
  • Loading branch information
Siedlerchr authored and tobiasdiez committed Jan 28, 2018
1 parent 25c883d commit 9b52a39
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

import org.jabref.model.entry.BibEntry;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
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;

public class FulltextFetchersTest {
private BibEntry entry;

@Before
@BeforeEach
public void setUp() {
entry = new BibEntry();
}

@After
@AfterEach
public void tearDown() {
entry = null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/jabref/logic/importer/WebFetchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import org.jabref.logic.importer.fetcher.IsbnViaEbookDeFetcher;
import org.jabref.logic.importer.fetcher.MrDLibFetcher;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.reflections.Reflections;

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

public class WebFetchersTest {

Reflections reflections = new Reflections("org.jabref");
ImportFormatPreferences importFormatPreferences;

@Before
@BeforeEach
public void setUp() throws Exception {
importFormatPreferences = mock(ImportFormatPreferences.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

import org.jabref.logic.importer.FetcherException;
import org.jabref.model.entry.BibEntry;
import org.jabref.testutils.category.FetcherTest;

import org.junit.jupiter.api.Test;

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

@FetcherTest
public abstract class AbstractIsbnFetcherTest {

protected AbstractIsbnFetcher fetcher;
Expand Down
29 changes: 11 additions & 18 deletions src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@
import org.jabref.model.entry.identifier.ArXivIdentifier;
import org.jabref.testutils.category.FetcherTest;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

@Category(FetcherTest.class)
@FetcherTest
public class ArXivTest {

@Rule public ExpectedException expectedException = ExpectedException.none();
private ArXiv finder;
private BibEntry entry;
private BibEntry sliceTheoremPaper;

@Before
@BeforeEach
public void setUp() {
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class);
when(importFormatPreferences.getKeywordSeparator()).thenReturn(',');
Expand All @@ -57,10 +53,10 @@ public void findFullTextForEmptyEntryResultsEmptyOptional() throws IOException {
assertEquals(Optional.empty(), finder.findFullText(entry));
}

@Test(expected = NullPointerException.class)
public void findFullTextRejectsNullParameter() throws IOException {
finder.findFullText(null);
Assert.fail();

assertThrows(NullPointerException.class, () -> finder.findFullText(null));

}

@Test
Expand Down Expand Up @@ -127,7 +123,6 @@ public void findFullTextByDOINotAvailableInCatalog() throws IOException {
entry.setField(FieldName.DOI, "10.1016/0370-2693(77)90015-6");
entry.setField(FieldName.TITLE, "Superspace formulation of supergravity");


assertEquals(Optional.empty(), finder.findFullText(entry));
}

Expand Down Expand Up @@ -186,9 +181,7 @@ public void searchEntryByIdWith5Digits() throws Exception {

@Test
public void searchWithMalformedIdThrowsException() throws Exception {
expectedException.expect(FetcherException.class);
expectedException.expectMessage("incorrect id format");
finder.performSearchById("123412345");
assertThrows(FetcherException.class, () -> finder.performSearchById("123412345"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
import org.jabref.model.entry.FieldName;
import org.jabref.testutils.category.FetcherTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@Category(FetcherTest.class)
@FetcherTest
public class AstrophysicsDataSystemTest {

private AstrophysicsDataSystem fetcher;
private BibEntry diezSliceTheoremEntry, famaeyMcGaughEntry, sunWelchEntry, xiongSunEntry, ingersollPollardEntry, luceyPaulEntry;

@Before
@BeforeEach
public void setUp() throws Exception {
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class);
when(importFormatPreferences.getFieldContentParserPreferences()).thenReturn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.testutils.category.FetcherTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
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;

@Category(FetcherTest.class)
@FetcherTest
public class CrossRefTest {

private CrossRef fetcher;
private BibEntry barrosEntry;

@Before
@BeforeEach
public void setUp() throws Exception {
fetcher = new CrossRef();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
import org.jabref.model.entry.FieldName;
import org.jabref.testutils.category.FetcherTest;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

@Category(FetcherTest.class)
@FetcherTest
public class DBLPFetcherTest {

private DBLPFetcher dblpFetcher;
private BibEntry entry;

@Before
@BeforeEach
public void setUp() {
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class);
when(importFormatPreferences.getFieldContentParserPreferences())
Expand Down Expand Up @@ -54,15 +53,15 @@ public void findSingleEntry() throws FetcherException {
String query = "Process Engine Benchmarking with Betsy in the Context of {ISO/IEC} Quality Standards";
List<BibEntry> result = dblpFetcher.performSearch(query);

Assert.assertEquals(Collections.singletonList(entry), result);
assertEquals(Collections.singletonList(entry), result);
}

@Test
public void findSingleEntryUsingComplexOperators() throws FetcherException {
String query = "geiger harrer betsy$ softw.trends"; //-wirtz Negative operators do no longer work, see issue https://github.com/JabRef/jabref/issues/2890
List<BibEntry> result = dblpFetcher.performSearch(query);

Assert.assertEquals(Collections.singletonList(entry), result);
assertEquals(Collections.singletonList(entry), result);
}

}
15 changes: 7 additions & 8 deletions src/test/java/org/jabref/logic/importer/fetcher/DiVATest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.testutils.category.FetcherTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;

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;
import static org.mockito.Mockito.mock;

@Category(FetcherTest.class)
@FetcherTest
public class DiVATest {

private DiVA fetcher;

@Before
@BeforeEach
public void setUp() {
fetcher = new DiVA(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS));
}
Expand Down
26 changes: 11 additions & 15 deletions src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@
import org.jabref.model.entry.BiblatexEntryTypes;
import org.jabref.testutils.category.FetcherTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

@Category(FetcherTest.class)
@FetcherTest
public class DoiFetcherTest {

private DoiFetcher fetcher;
private BibEntry bibEntryBurd2011, bibEntryDecker2007;

@Before
@BeforeEach
public void setUp() {
fetcher = new DoiFetcher(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS));

Expand Down Expand Up @@ -71,15 +70,12 @@ public void testPerformSearchDecker2007() throws FetcherException {
assertEquals(Optional.of(bibEntryDecker2007), fetchedEntry);
}

@Test(expected = FetcherException.class)
public void testPerformSearchEmptyDOI() throws FetcherException {
Optional<BibEntry> fetchedEntry = fetcher.performSearchById("");
assertEquals(Optional.empty(), fetchedEntry);
public void testPerformSearchEmptyDOI() {
assertThrows(FetcherException.class, () -> fetcher.performSearchById(""));
}

@Test(expected = FetcherException.class)
public void testPerformSearchInvalidDOI() throws FetcherException {
fetcher.performSearchById("10.1002/9781118257517F");
fail();
public void testPerformSearchInvalidDOI() {
assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
import org.jabref.model.entry.BiblatexEntryTypes;
import org.jabref.testutils.category.FetcherTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

@Category(FetcherTest.class)
@FetcherTest
public class GvkFetcherTest {

private GvkFetcher fetcher;
private BibEntry bibEntryPPN591166003;
private BibEntry bibEntryPPN66391437X;

@Before
@BeforeEach
public void setUp() {
fetcher = new GvkFetcher();

Expand Down Expand Up @@ -68,7 +67,7 @@ public void testGetHelpPage() {
}

@Test
public void simpleSearchQueryStringCorrect() throws FetcherException {
public void simpleSearchQueryStringCorrect() {
String query = "java jdk";
String result = fetcher.getSearchQueryString(query);
assertEquals("pica.all=java jdk", result);
Expand All @@ -82,7 +81,7 @@ public void simpleSearchQueryURLCorrect() throws MalformedURLException, URISynta
}

@Test
public void complexSearchQueryStringCorrect() throws FetcherException {
public void complexSearchQueryStringCorrect() {
String query = "kon java tit jdk";
String result = fetcher.getSearchQueryString(query);
assertEquals("pica.kon=java and pica.tit=jdk", result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Answers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public void setUp() {
bibEntry.setType(BiblatexEntryTypes.BOOK);
bibEntry.setField("bibtexkey", "9780134685991");
bibEntry.setField("title", "Effective Java");
bibEntry.setField("publisher", "Addison Wesley");
bibEntry.setField("publisher", "ADDISON WESLEY PUB CO INC");
bibEntry.setField("pagetotal", "416");
bibEntry.setField("year", "2018");
bibEntry.setField("author", "Bloch, Joshua");
bibEntry.setField("date", "2018-01-11");
bibEntry.setField("date", "2018-01-06");
bibEntry.setField("ean", "9780134685991");
bibEntry.setField("isbn", "0134685997");
bibEntry.setField("url", "http://www.ebook.de/de/product/28983211/joshua_bloch_effective_java.html");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public void setUp() {
bibEntry.setType(BiblatexEntryTypes.BOOK);
bibEntry.setField("bibtexkey", "9780134685991");
bibEntry.setField("title", "Effective Java");
bibEntry.setField("publisher", "Addison Wesley");
bibEntry.setField("publisher", "ADDISON WESLEY PUB CO INC");
bibEntry.setField("pagetotal", "416");
bibEntry.setField("year", "2018");
bibEntry.setField("author", "Bloch, Joshua");
bibEntry.setField("date", "2018-01-11");
bibEntry.setField("date", "2018-01-06");
bibEntry.setField("ean", "9780134685991");
bibEntry.setField("isbn", "0134685997");
bibEntry.setField("url", "http://www.ebook.de/de/product/28983211/joshua_bloch_effective_java.html");
Expand Down
Loading

0 comments on commit 9b52a39

Please sign in to comment.