forked from Archives/Athou_commafeed
add coverage for in-page url fallback
This commit is contained in:
@@ -16,7 +16,10 @@ import com.commafeed.backend.Digests;
|
|||||||
import com.commafeed.backend.HttpGetter;
|
import com.commafeed.backend.HttpGetter;
|
||||||
import com.commafeed.backend.HttpGetter.HttpResult;
|
import com.commafeed.backend.HttpGetter.HttpResult;
|
||||||
import com.commafeed.backend.HttpGetter.NotModifiedException;
|
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;
|
||||||
|
import com.commafeed.backend.feed.parser.FeedParser.FeedParsingException;
|
||||||
|
import com.commafeed.backend.feed.parser.FeedParserResult;
|
||||||
import com.commafeed.backend.urlprovider.FeedURLProvider;
|
import com.commafeed.backend.urlprovider.FeedURLProvider;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
@@ -29,13 +32,33 @@ class FeedFetcherTest {
|
|||||||
private HttpGetter getter;
|
private HttpGetter getter;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private List<FeedURLProvider> urlProviders;
|
private FeedURLProvider urlProvider;
|
||||||
|
|
||||||
private FeedFetcher fetcher;
|
private FeedFetcher fetcher;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init() {
|
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
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user