mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-12 15:24:33 -05:00
Switch to a new Ktlint Formatter (#705)
* Switch to new Ktlint plugin * Add ktlintCheck to PR builds * Run formatter * Put ktlint version in libs toml * Fix lint * Use Zip4Java from libs.toml
This commit is contained in:
@@ -36,7 +36,7 @@ class CategoryControllerTest : ApplicationTest() {
|
||||
@AfterEach
|
||||
internal fun tearDown() {
|
||||
clearTables(
|
||||
CategoryTable
|
||||
CategoryTable,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,7 @@ internal class UpdateControllerTest : ApplicationTest() {
|
||||
assertEquals(3, updater.status.value.numberOfJobs)
|
||||
}
|
||||
|
||||
private fun createLibraryManga(
|
||||
_title: String
|
||||
): Int {
|
||||
private fun createLibraryManga(_title: String): Int {
|
||||
return transaction {
|
||||
MangaTable.insertAndGetId {
|
||||
it[title] = _title
|
||||
@@ -81,7 +79,7 @@ internal class UpdateControllerTest : ApplicationTest() {
|
||||
clearTables(
|
||||
CategoryMangaTable,
|
||||
MangaTable,
|
||||
CategoryTable
|
||||
CategoryTable,
|
||||
)
|
||||
val updater by DI.global.instance<IUpdater>()
|
||||
runBlocking { updater.reset() }
|
||||
|
||||
@@ -33,36 +33,36 @@ class CategoryMangaTest : ApplicationTest() {
|
||||
assertEquals(
|
||||
0,
|
||||
CategoryManga.getCategoryMangaList(DEFAULT_CATEGORY_ID)[0].unreadCount,
|
||||
"Manga should not have any unread chapters"
|
||||
"Manga should not have any unread chapters",
|
||||
)
|
||||
createChapters(mangaId, 10, false)
|
||||
assertEquals(
|
||||
10,
|
||||
CategoryManga.getCategoryMangaList(DEFAULT_CATEGORY_ID)[0].unreadCount,
|
||||
"Manga should have unread chapters"
|
||||
"Manga should have unread chapters",
|
||||
)
|
||||
|
||||
val categoryId = Category.createCategory("Old")
|
||||
assertEquals(
|
||||
0,
|
||||
CategoryManga.getCategoryMangaList(categoryId).size,
|
||||
"Newly created category shouldn't have any Mangas"
|
||||
"Newly created category shouldn't have any Mangas",
|
||||
)
|
||||
CategoryManga.addMangaToCategory(mangaId, categoryId)
|
||||
assertEquals(
|
||||
1,
|
||||
CategoryManga.getCategoryMangaList(categoryId).size,
|
||||
"Manga should been moved"
|
||||
"Manga should been moved",
|
||||
)
|
||||
assertEquals(
|
||||
10,
|
||||
CategoryManga.getCategoryMangaList(categoryId)[0].unreadCount,
|
||||
"Manga should keep it's unread count in moved category"
|
||||
"Manga should keep it's unread count in moved category",
|
||||
)
|
||||
assertEquals(
|
||||
0,
|
||||
CategoryManga.getCategoryMangaList(DEFAULT_CATEGORY_ID).size,
|
||||
"Manga shouldn't be member of default category after moving"
|
||||
"Manga shouldn't be member of default category after moving",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class CategoryMangaTest : ApplicationTest() {
|
||||
ChapterTable,
|
||||
CategoryMangaTable,
|
||||
MangaTable,
|
||||
CategoryTable
|
||||
CategoryTable,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,24 +33,24 @@ class MangaTest : ApplicationTest() {
|
||||
assertEquals(
|
||||
1,
|
||||
Manga.getMangaMetaMap(metaManga).size,
|
||||
"Manga meta should still only have one pair"
|
||||
"Manga meta should still only have one pair",
|
||||
)
|
||||
assertEquals(
|
||||
"newValue",
|
||||
Manga.getMangaMetaMap(metaManga)["test"],
|
||||
"Manga meta with key 'test' should use the value `newValue`"
|
||||
"Manga meta with key 'test' should use the value `newValue`",
|
||||
)
|
||||
|
||||
Manga.modifyMangaMeta(metaManga, "test2", "value2")
|
||||
assertEquals(
|
||||
2,
|
||||
Manga.getMangaMetaMap(metaManga).size,
|
||||
"Manga Meta should have an additional pair"
|
||||
"Manga Meta should have an additional pair",
|
||||
)
|
||||
assertEquals(
|
||||
"value2",
|
||||
Manga.getMangaMetaMap(metaManga)["test2"],
|
||||
"Manga Meta for key 'test2' should be 'value2'"
|
||||
"Manga Meta for key 'test2' should be 'value2'",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class MangaTest : ApplicationTest() {
|
||||
internal fun tearDown() {
|
||||
clearTables(
|
||||
MangaMetaTable,
|
||||
MangaTable
|
||||
MangaTable,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@ import suwayomi.tachidesk.test.ApplicationTest
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class PageTest : ApplicationTest() {
|
||||
|
||||
@Test
|
||||
fun testGetPageName() {
|
||||
val tests = listOf(0, 1, 2, 100)
|
||||
|
||||
val testResults = tests.map {
|
||||
getPageName(it)
|
||||
}
|
||||
val testResults =
|
||||
tests.map {
|
||||
getPageName(it)
|
||||
}
|
||||
|
||||
assertEquals(testResults[0], "001")
|
||||
assertEquals(testResults[1], "002")
|
||||
|
||||
@@ -39,7 +39,11 @@ class SearchTest : ApplicationTest() {
|
||||
var mangas: List<SManga> = emptyList()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getSearchManga"))
|
||||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
|
||||
override fun fetchSearchManga(
|
||||
page: Int,
|
||||
query: String,
|
||||
filters: FilterList,
|
||||
): Observable<MangasPage> {
|
||||
return Observable.just(MangasPage(mangas, false))
|
||||
}
|
||||
}
|
||||
@@ -57,9 +61,10 @@ class SearchTest : ApplicationTest() {
|
||||
|
||||
@Test
|
||||
fun searchWorks() {
|
||||
val searchResults = runBlocking {
|
||||
sourceSearch(sourceId, "all the mangas", 1)
|
||||
}
|
||||
val searchResults =
|
||||
runBlocking {
|
||||
sourceSearch(sourceId, "all the mangas", 1)
|
||||
}
|
||||
|
||||
assertEquals(mangasCount, searchResults.mangaList.size, "should return all the mangas")
|
||||
}
|
||||
@@ -89,39 +94,45 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
assertEquals(
|
||||
0,
|
||||
filterList.size
|
||||
filterList.size,
|
||||
)
|
||||
}
|
||||
|
||||
class FilterListSource(id: Long) : EmptyFilterListSource(id) {
|
||||
class SelectFilter(name: String, values: Array<String>) : Filter.Select<String>(name, values)
|
||||
|
||||
class TextFilter(name: String) : Filter.Text(name)
|
||||
|
||||
class TestCheckBox(name: String) : Filter.CheckBox(name, false)
|
||||
|
||||
class TriState(name: String, state: Int) : Filter.TriState(name, state)
|
||||
|
||||
class Group(name: String, state: List<TestCheckBox>) : Filter.Group<TestCheckBox>(name, state)
|
||||
|
||||
class Sort(name: String, values: Array<String>, state: Selection) : Filter.Sort(name, values, state)
|
||||
|
||||
override var mFilterList = FilterList(
|
||||
Filter.Header("This is a header"),
|
||||
Filter.Separator(),
|
||||
SelectFilter("Select one of these:", arrayOf("this", "that", "none of them")),
|
||||
TextFilter("text filter"),
|
||||
TestCheckBox("check this or else!"),
|
||||
TriState("wanna hook up?", Filter.TriState.STATE_IGNORE),
|
||||
Group(
|
||||
"my Todo",
|
||||
listOf(
|
||||
TestCheckBox("Write Tests"),
|
||||
TestCheckBox("Write More Tests"),
|
||||
TestCheckBox("Write Even More Tests")
|
||||
)
|
||||
),
|
||||
Sort(
|
||||
"Sort",
|
||||
arrayOf("Alphabetic", "Date published", "Rating"),
|
||||
Filter.Sort.Selection(2, false)
|
||||
override var mFilterList =
|
||||
FilterList(
|
||||
Filter.Header("This is a header"),
|
||||
Filter.Separator(),
|
||||
SelectFilter("Select one of these:", arrayOf("this", "that", "none of them")),
|
||||
TextFilter("text filter"),
|
||||
TestCheckBox("check this or else!"),
|
||||
TriState("wanna hook up?", Filter.TriState.STATE_IGNORE),
|
||||
Group(
|
||||
"my Todo",
|
||||
listOf(
|
||||
TestCheckBox("Write Tests"),
|
||||
TestCheckBox("Write More Tests"),
|
||||
TestCheckBox("Write Even More Tests"),
|
||||
),
|
||||
),
|
||||
Sort(
|
||||
"Sort",
|
||||
arrayOf("Alphabetic", "Date published", "Rating"),
|
||||
Filter.Sort.Selection(2, false),
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,27 +142,27 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
assertEquals(
|
||||
FilterObject("Header", source.mFilterList[0]),
|
||||
filterList[0]
|
||||
filterList[0],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("Separator", source.mFilterList[1]),
|
||||
filterList[1]
|
||||
filterList[1],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("Select", source.mFilterList[2]),
|
||||
filterList[2]
|
||||
filterList[2],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("Text", source.mFilterList[3]),
|
||||
filterList[3]
|
||||
filterList[3],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("CheckBox", source.mFilterList[4]),
|
||||
filterList[4]
|
||||
filterList[4],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("TriState", source.mFilterList[5]),
|
||||
filterList[5]
|
||||
filterList[5],
|
||||
)
|
||||
assertEquals(
|
||||
filterList[6],
|
||||
@@ -162,14 +173,14 @@ class FilterListTest : ApplicationTest() {
|
||||
listOf(
|
||||
FilterObject("CheckBox", (source.mFilterList[6].state as List<Filter<*>>)[0]),
|
||||
FilterObject("CheckBox", (source.mFilterList[6].state as List<Filter<*>>)[1]),
|
||||
FilterObject("CheckBox", (source.mFilterList[6].state as List<Filter<*>>)[2])
|
||||
)
|
||||
)
|
||||
)
|
||||
FilterObject("CheckBox", (source.mFilterList[6].state as List<Filter<*>>)[2]),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("Sort", source.mFilterList[7]),
|
||||
filterList[7]
|
||||
filterList[7],
|
||||
)
|
||||
|
||||
// make sure that we can convert this to json
|
||||
@@ -182,24 +193,24 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(0, "change!")
|
||||
FilterChange(0, "change!"),
|
||||
)
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(1, "change!")
|
||||
FilterChange(1, "change!"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[0].filter.state,
|
||||
0
|
||||
0,
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
filterList[1].filter.state,
|
||||
0
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -209,14 +220,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(2, "1")
|
||||
FilterChange(2, "1"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[2].filter.state,
|
||||
1
|
||||
1,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -226,14 +237,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(3, "I'm a changed man!")
|
||||
FilterChange(3, "I'm a changed man!"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[3].filter.state,
|
||||
"I'm a changed man!"
|
||||
"I'm a changed man!",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -243,14 +254,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(4, "true")
|
||||
FilterChange(4, "true"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[4].filter.state,
|
||||
true
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -260,14 +271,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(5, "1")
|
||||
FilterChange(5, "1"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[5].filter.state,
|
||||
Filter.TriState.STATE_INCLUDE
|
||||
Filter.TriState.STATE_INCLUDE,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -277,14 +288,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(6, """{"position":0,"state":"true"}""")
|
||||
FilterChange(6, """{"position":0,"state":"true"}"""),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
(filterList[6].filter.state as List<FilterObject>)[0].filter.state,
|
||||
true
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -294,14 +305,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(7, """{"index":1,"ascending":"true"}""")
|
||||
FilterChange(7, """{"index":1,"ascending":"true"}"""),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[7].filter.state,
|
||||
Filter.Sort.Selection(1, true)
|
||||
Filter.Sort.Selection(1, true),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ package suwayomi.tachidesk.manga.model
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import suwayomi.tachidesk.manga.model.dataclass.PAGINATION_FACTOR
|
||||
import suwayomi.tachidesk.manga.model.dataclass.PaginatedList
|
||||
import suwayomi.tachidesk.manga.model.dataclass.PaginationFactor
|
||||
import suwayomi.tachidesk.manga.model.dataclass.paginatedFrom
|
||||
import suwayomi.tachidesk.test.ApplicationTest
|
||||
|
||||
@@ -21,85 +21,88 @@ class PaginatedListTest : ApplicationTest() {
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(emptyList<Int>(), false),
|
||||
paginated
|
||||
paginated,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `size smaller than PaginationFactor`() {
|
||||
val paginated = paginatedFrom(0) { listIndicesOf(0, PaginationFactor - 1) }
|
||||
val paginated = paginatedFrom(0) { listIndicesOf(0, PAGINATION_FACTOR - 1) }
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(0, PaginationFactor - 1), false),
|
||||
paginated
|
||||
PaginatedList(listIndicesOf(0, PAGINATION_FACTOR - 1), false),
|
||||
paginated,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `one less than two times PaginationFactor`() {
|
||||
val masterLister = { listIndicesOf(0, PaginationFactor * 2 - 1) }
|
||||
val masterLister = { listIndicesOf(0, PAGINATION_FACTOR * 2 - 1) }
|
||||
|
||||
val firstPage = paginatedFrom(0, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(0, PaginationFactor), true),
|
||||
firstPage
|
||||
PaginatedList(listIndicesOf(0, PAGINATION_FACTOR), true),
|
||||
firstPage,
|
||||
)
|
||||
|
||||
val secondPage = paginatedFrom(1, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(PaginationFactor, PaginationFactor * 2 - 1), false),
|
||||
secondPage
|
||||
PaginatedList(listIndicesOf(PAGINATION_FACTOR, PAGINATION_FACTOR * 2 - 1), false),
|
||||
secondPage,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `two times PaginationFactor`() {
|
||||
val masterLister = { listIndicesOf(0, PaginationFactor * 2) }
|
||||
val masterLister = { listIndicesOf(0, PAGINATION_FACTOR * 2) }
|
||||
|
||||
val firstPage = paginatedFrom(0, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(0, PaginationFactor), true),
|
||||
firstPage
|
||||
PaginatedList(listIndicesOf(0, PAGINATION_FACTOR), true),
|
||||
firstPage,
|
||||
)
|
||||
|
||||
val secondPage = paginatedFrom(1, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(PaginationFactor, PaginationFactor * 2), false),
|
||||
secondPage
|
||||
PaginatedList(listIndicesOf(PAGINATION_FACTOR, PAGINATION_FACTOR * 2), false),
|
||||
secondPage,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `one more than two times PaginationFactor`() {
|
||||
val masterLister = { listIndicesOf(0, PaginationFactor * 2 + 1) }
|
||||
val masterLister = { listIndicesOf(0, PAGINATION_FACTOR * 2 + 1) }
|
||||
|
||||
val firstPage = paginatedFrom(0, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(0, PaginationFactor), true),
|
||||
firstPage
|
||||
PaginatedList(listIndicesOf(0, PAGINATION_FACTOR), true),
|
||||
firstPage,
|
||||
)
|
||||
|
||||
val secondPage = paginatedFrom(1, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(PaginationFactor, PaginationFactor * 2), true),
|
||||
secondPage
|
||||
PaginatedList(listIndicesOf(PAGINATION_FACTOR, PAGINATION_FACTOR * 2), true),
|
||||
secondPage,
|
||||
)
|
||||
|
||||
val thirdPage = paginatedFrom(2, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(PaginationFactor * 2, PaginationFactor * 2 + 1), false),
|
||||
thirdPage
|
||||
PaginatedList(listIndicesOf(PAGINATION_FACTOR * 2, PAGINATION_FACTOR * 2 + 1), false),
|
||||
thirdPage,
|
||||
)
|
||||
}
|
||||
|
||||
private fun listIndicesOf(first: Int, last: Int): List<Int> {
|
||||
private fun listIndicesOf(
|
||||
first: Int,
|
||||
last: Int,
|
||||
): List<Int> {
|
||||
return (first until last).toList()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user