-
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/test/java/me/ash/reader/infrastructure/rss/RssHelperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package me.ash.reader.infrastructure.rss | ||
|
||
import android.content.Context | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import okhttp3.OkHttpClient | ||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.mockito.kotlin.mock | ||
|
||
const val enclosureUrlString1: String = "https://example.com/enclosure.jpg" | ||
const val enclosureUrlString2: String = "https://github.blog/wp-content/uploads/2024/03/github_copilot_header.png" | ||
const val imageUrlString: String = "https://example.com/image.jpg" | ||
const val enclosureHtmlCase1: String = """ | ||
<enclosure url="$enclosureUrlString1" type="image/jpeg"/> | ||
<img src="$imageUrlString"/> | ||
""" | ||
const val enclosureHtmlCase2: String = """ | ||
<img src="$imageUrlString"/> | ||
<enclosure url="$enclosureUrlString1" type="image/jpeg"/> | ||
<img src="$imageUrlString"/> | ||
""" | ||
const val enclosureHtmlCase3: String = """ | ||
<img src="$imageUrlString"/> | ||
<enclosure url="$enclosureUrlString2" type="image/png"/> | ||
<img src="$imageUrlString"/> | ||
""" | ||
const val imageHtmlCase1: String = """ | ||
<img src="$enclosureUrlString1"/> | ||
<img src="$imageUrlString"/> | ||
""" | ||
const val imageHtmlCase2: String = """ | ||
<img src="$imageUrlString"/> | ||
<img src="$enclosureUrlString1"/> | ||
<img src="$enclosureUrlString1"/> | ||
""" | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
class RssHelperTest { | ||
|
||
@Mock | ||
private lateinit var mockContext: Context | ||
|
||
@Mock | ||
private lateinit var mockIODispatcher: CoroutineDispatcher | ||
|
||
@Mock | ||
private lateinit var mockOkHttpClient: OkHttpClient | ||
|
||
private lateinit var rssHelper: RssHelper | ||
|
||
@Before | ||
fun setUp() { | ||
mockContext = mock<Context> { } | ||
mockIODispatcher = mock<CoroutineDispatcher> {} | ||
mockOkHttpClient = mock<OkHttpClient> {} | ||
rssHelper = RssHelper(mockContext, mockIODispatcher, mockOkHttpClient) | ||
} | ||
|
||
@Test | ||
fun testFindThumbnail() { | ||
Assert.assertNull(rssHelper.findThumbnail("")) | ||
Assert.assertNull(rssHelper.findThumbnail(" ")) | ||
Assert.assertNull(rssHelper.findThumbnail(null)) | ||
Assert.assertEquals(enclosureUrlString1, rssHelper.findThumbnail(enclosureHtmlCase1)) | ||
Assert.assertEquals(enclosureUrlString1, rssHelper.findThumbnail(enclosureHtmlCase2)) | ||
Assert.assertEquals(enclosureUrlString2, rssHelper.findThumbnail(enclosureHtmlCase3)) | ||
Assert.assertEquals(enclosureUrlString1, rssHelper.findThumbnail(imageHtmlCase1)) | ||
Assert.assertEquals(imageUrlString, rssHelper.findThumbnail(imageHtmlCase2)) | ||
} | ||
} |