add coverage for in-page url fallback

This commit is contained in:
Athou
2025-09-28 07:30:28 +02:00
parent 85acea7e64
commit 1e6195d74c

View File

@@ -16,7 +16,10 @@ import com.commafeed.backend.Digests;
import com.commafeed.backend.HttpGetter;
import com.commafeed.backend.HttpGetter.HttpResult;
import com.commafeed.backend.HttpGetter.NotModifiedException;
import com.commafeed.backend.feed.FeedFetcher.FeedFetcherResult;
import com.commafeed.backend.feed.parser.FeedParser;
import com.commafeed.backend.feed.parser.FeedParser.FeedParsingException;
import com.commafeed.backend.feed.parser.FeedParserResult;
import com.commafeed.backend.urlprovider.FeedURLProvider;
@ExtendWith(MockitoExtension.class)
@@ -29,13 +32,33 @@ class FeedFetcherTest {
private HttpGetter getter;
@Mock
private List<FeedURLProvider> urlProviders;
private FeedURLProvider urlProvider;
private FeedFetcher fetcher;
@BeforeEach
void init() {
fetcher = new FeedFetcher(parser, getter, urlProviders);
fetcher = new FeedFetcher(parser, getter, List.of(urlProvider));
}
@Test
void findsUrlInPage() throws Exception {
String htmlUrl = "https://aaa.com";
byte[] html = "html".getBytes();
Mockito.when(getter.get(HttpGetter.HttpRequest.builder(htmlUrl).build()))
.thenReturn(new HttpResult(html, "text/html", null, null, htmlUrl, Duration.ZERO));
Mockito.when(parser.parse(htmlUrl, html)).thenThrow(new FeedParsingException("invalid feed"));
String feedUrl = "https://bbb.com/feed";
byte[] feed = "feed".getBytes();
Mockito.when(getter.get(HttpGetter.HttpRequest.builder(feedUrl).build()))
.thenReturn(new HttpResult(feed, "application/atom+xml", null, null, feedUrl, Duration.ZERO));
Mockito.when(parser.parse(feedUrl, feed)).thenReturn(new FeedParserResult("title", "link", null, null, null, null));
Mockito.when(urlProvider.get(htmlUrl, new String(html))).thenReturn(List.of(feedUrl));
FeedFetcherResult result = fetcher.fetch(htmlUrl, true, null, null, null, null);
Assertions.assertEquals("title", result.feed().title());
}
@Test