| author | Da Risk <da_risk@geekorum.com> |
| Mon, 15 Sep 2025 14:00:07 -0400 | |
| changeset 1370 | 13e39ef920a8 |
| parent 1305 | ecb49cb4d40b |
| permissions | -rw-r--r-- |
|
137
5464f07a306c
Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
1 |
/* |
| 0 | 2 |
* Geekttrss is a RSS feed reader application on the Android Platform. |
3 |
* |
|
| 1370 | 4 |
* Copyright (C) 2017-2025 by Frederic-Charles Barthelery. |
| 0 | 5 |
* |
6 |
* This file is part of Geekttrss. |
|
7 |
* |
|
8 |
* Geekttrss is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* Geekttrss is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with Geekttrss. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
|
|
307
f1b40d8534be
extract htmlparsers into a new library module
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
21 |
package com.geekorum.ttrss.htmlparsers |
| 0 | 22 |
|
|
1305
ecb49cb4d40b
htmlparsers: use ksoup instead of jsoup
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
23 |
import com.fleeksoft.ksoup.Ksoup |
| 0 | 24 |
import com.google.common.truth.Truth.assertThat |
25 |
import kotlin.test.BeforeTest |
|
26 |
import kotlin.test.Test |
|
27 |
||
28 |
private const val emptyHtmlDoc = "" |
|
29 |
private const val htmlDocWithoutFeeds = "<html></html>" |
|
30 |
||
31 |
private val htmlDocWithOneRssFeed = """ |
|
32 |
<html> |
|
33 |
<head> |
|
34 |
<link rel="alternate" type="application/rss+xml" title="RSS Advisory Board" href="http://feeds.rssboard.org/rssboard" /> |
|
35 |
</head> |
|
36 |
</html> |
|
37 |
""".trimIndent() |
|
38 |
||
39 |
private val rssAdvisoryBoardFeedInfo = FeedInformation( |
|
|
307
f1b40d8534be
extract htmlparsers into a new library module
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
40 |
href = "http://feeds.rssboard.org/rssboard", |
| 0 | 41 |
type = "application/rss+xml", title = "RSS Advisory Board") |
42 |
||
43 |
private val htmlDocWithOneRelativeRssFeed = """ |
|
44 |
<html> |
|
45 |
<head> |
|
46 |
<title>RSS Advisory Board</title> |
|
47 |
<base href="http://feeds.rssboard.org/"> |
|
48 |
<link rel="alternate" type="application/rss+xml" href="rssboard"> |
|
49 |
</head> |
|
50 |
</html> |
|
51 |
""".trimIndent() |
|
52 |
||
53 |
private val rssAdvisoryBoardFeedInfoNoTitle = FeedInformation( |
|
|
307
f1b40d8534be
extract htmlparsers into a new library module
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
54 |
href = "http://feeds.rssboard.org/rssboard", |
| 0 | 55 |
type = "application/rss+xml") |
56 |
||
57 |
||
58 |
private val htmlDocWithOneAtomFeed = """ |
|
59 |
<html> |
|
60 |
<head> |
|
61 |
<link rel="dns-prefetch" href="https://user-images.githubusercontent.com/"> |
|
62 |
<meta name="viewport" content="width=device-width"> |
|
63 |
<link href="https://github.com/codepath/android_guides/commits/master.atom" rel="alternate" title="Recent Commits to android_guides:master" type="application/atom+xml"> |
|
64 |
</head> |
|
65 |
</html> |
|
66 |
""".trimIndent() |
|
67 |
||
68 |
private val githubRecentCommitsFeedInfo = |
|
69 |
FeedInformation( |
|
|
307
f1b40d8534be
extract htmlparsers into a new library module
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
70 |
href = "https://github.com/codepath/android_guides/commits/master.atom", |
| 0 | 71 |
type = "application/atom+xml", title = "Recent Commits to android_guides:master") |
72 |
||
73 |
private val htmlDocWithCombinedFeeds = """ |
|
74 |
<html> |
|
75 |
<head> |
|
76 |
<title>RSS Advisory Board</title> |
|
77 |
<link href="https://github.com/codepath/android_guides/commits/master.atom" rel="alternate" title="Recent Commits to android_guides:master" type="application/atom+xml"> |
|
78 |
<link rel="dns-prefetch" href="https://user-images.githubusercontent.com/"> |
|
79 |
<link rel="alternate" type="application/rss+xml" href="rssboard"> |
|
80 |
<base href="http://feeds.rssboard.org/"> |
|
81 |
<link rel="alternate" type="application/rss+xml" title="RSS Advisory Board" href="http://feeds.rssboard.org/rssboard" /> |
|
82 |
<meta name="viewport" content="width=device-width"> |
|
83 |
</head> |
|
84 |
</html> |
|
85 |
""".trimIndent() |
|
86 |
||
87 |
||
88 |
class FeedExtractorTest {
|
|
89 |
||
90 |
lateinit var feedExtractor: FeedExtractor |
|
91 |
||
92 |
@BeforeTest |
|
93 |
fun setUp() {
|
|
94 |
feedExtractor = FeedExtractor() |
|
95 |
} |
|
96 |
||
97 |
@Test |
|
98 |
fun testThatWhenEmptyHtmlDocReturnNoFeedInformation() {
|
|
|
1305
ecb49cb4d40b
htmlparsers: use ksoup instead of jsoup
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
99 |
val doc = Ksoup.parse(emptyHtmlDoc) |
| 0 | 100 |
val result = feedExtractor.extract(doc) |
101 |
assertThat(result).isEmpty() |
|
102 |
} |
|
103 |
||
104 |
@Test |
|
105 |
fun testThatWhenHtmlDocWithoutFeedsReturnNoFeedInformation() {
|
|
|
1305
ecb49cb4d40b
htmlparsers: use ksoup instead of jsoup
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
106 |
val doc = Ksoup.parse(htmlDocWithoutFeeds) |
| 0 | 107 |
val result = feedExtractor.extract(doc) |
108 |
assertThat(result).isEmpty() |
|
109 |
} |
|
110 |
||
111 |
@Test |
|
112 |
fun testThatWhenHtmlDocWithRssFeedsReturnCorrectFeedInfo() {
|
|
|
1305
ecb49cb4d40b
htmlparsers: use ksoup instead of jsoup
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
113 |
val doc = Ksoup.parse(htmlDocWithOneRssFeed) |
| 0 | 114 |
val result = feedExtractor.extract(doc) |
115 |
assertThat(result).containsExactly(rssAdvisoryBoardFeedInfo) |
|
116 |
} |
|
117 |
||
118 |
@Test |
|
119 |
fun testThatWhenHtmlDocWithAtomFeedsReturnCorrectFeedInfo() {
|
|
|
1305
ecb49cb4d40b
htmlparsers: use ksoup instead of jsoup
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
120 |
val doc = Ksoup.parse(htmlDocWithOneAtomFeed) |
| 0 | 121 |
val result = feedExtractor.extract(doc) |
122 |
assertThat(result).containsExactly(githubRecentCommitsFeedInfo) |
|
123 |
} |
|
124 |
||
125 |
@Test |
|
126 |
fun testThatWhenHtmlDocWithRelativeRssFeedsReturnCorrectFeedInfo() {
|
|
|
1305
ecb49cb4d40b
htmlparsers: use ksoup instead of jsoup
Da Risk <da_risk@geekorum.com>
parents:
1174
diff
changeset
|
127 |
val doc = Ksoup.parse(htmlDocWithOneRelativeRssFeed) |
| 0 | 128 |
val result = feedExtractor.extract(doc) |
129 |
assertThat(result).containsExactly(rssAdvisoryBoardFeedInfoNoTitle) |
|
130 |
} |
|
131 |
||
132 |
@Test |
|
133 |
fun testThatWhenHtmlDocWithCombinedFeedsReturnCorrectFeedInfo() {
|
|
134 |
val result = feedExtractor.extract(htmlDocWithCombinedFeeds) |
|
135 |
assertThat(result).containsExactly(rssAdvisoryBoardFeedInfoNoTitle, |
|
136 |
rssAdvisoryBoardFeedInfo, |
|
137 |
githubRecentCommitsFeedInfo) |
|
138 |
} |
|
139 |
||
140 |
} |