From 4aa20bc484946a08bca0afe985330fa053f9c213 Mon Sep 17 00:00:00 2001 From: colinhex Date: Tue, 26 Oct 2021 21:19:07 +0200 Subject: [PATCH] catch fetcher exception in test --- .../importer/fetcher/CompositeIdFetcherTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java index 9d795704182..04a136e0a13 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java @@ -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; @@ -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; @@ -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; @@ -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())); + } } }