Skip to content

Commit

Permalink
catch fetcher exception in test
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhex committed Oct 26, 2021
1 parent 8259ffc commit 4aa20bc
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.jabref.logic.bibtex.FieldContentFormatterPreferences;
import org.jabref.logic.importer.CompositeIdFetcher;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
Expand All @@ -16,8 +17,11 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

Expand All @@ -26,6 +30,7 @@
* IdBasedFetcher interface are a prerequisite. Excluding TitleFetcher.
*/
class CompositeIdFetcherTest {
private final static Logger LOGGER = LoggerFactory.getLogger(CompositeIdFetcherTest.class);

private CompositeIdFetcher compositeIdFetcher;

Expand Down Expand Up @@ -100,13 +105,21 @@ void setUp() throws Exception {
@ParameterizedTest
@ValueSource(strings = "arZiv:2110.02957")
void performSearchByIdReturnsEmptyForInvalidId(String groundInvalidArXivId) {
assertEquals(Optional.empty(), compositeIdFetcher.performSearchById(groundInvalidArXivId));
try {
assertEquals(Optional.empty(), compositeIdFetcher.performSearchById(groundInvalidArXivId));
} catch (FetcherException fetcherException) {
fail("Fetcher Exception caught: %s".formatted(fetcherException.getMessage()));
}
}

@ParameterizedTest(name = "{index} {0}")
@MethodSource("provideTestData")
void performSearchByIdReturnsCorrectEntryForIdentifier(String name, BibEntry bibEntry, String identifier) {
try {
assertEquals(Optional.of(bibEntry), compositeIdFetcher.performSearchById(identifier));
} catch (FetcherException fetcherException) {
fail("Fetcher Exception caught: %s".formatted(fetcherException.getMessage()));
}
}

}

0 comments on commit 4aa20bc

Please sign in to comment.