settings: decouple
Decouple the settings god object into feature-specific settings. This should make testing settings-dependent code much easier, as it no longer requires a context.
This commit is contained in:
@@ -126,8 +126,8 @@ class DateTest {
|
||||
|
||||
@Test
|
||||
fun date_fromYearDate() {
|
||||
assertEquals("2016", Date.from(2016).toString())
|
||||
assertEquals("2016", Date.from("2016").toString())
|
||||
assertEquals("2016-08-16", Date.from(20160816).toString())
|
||||
assertEquals("2016-08-16", Date.from("20160816").toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.music
|
||||
|
||||
import org.oxycblt.auxio.music.storage.MusicDirectories
|
||||
|
||||
interface FakeMusicSettings : MusicSettings {
|
||||
override var musicDirs: MusicDirectories
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
override val excludeNonMusic: Boolean
|
||||
get() = throw NotImplementedError()
|
||||
override val shouldBeObserving: Boolean
|
||||
get() = throw NotImplementedError()
|
||||
override var multiValueSeparators: String
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
override var songSort: Sort
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
override var albumSort: Sort
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
override var artistSort: Sort
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
override var genreSort: Sort
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
override var albumSongSort: Sort
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
override var artistSongSort: Sort
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
override var genreSongSort: Sort
|
||||
get() = throw NotImplementedError()
|
||||
set(_) = throw NotImplementedError()
|
||||
}
|
||||
@@ -19,22 +19,27 @@ package org.oxycblt.auxio.music.parsing
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.oxycblt.auxio.music.FakeMusicSettings
|
||||
|
||||
class ParsingUtilTest {
|
||||
@Test
|
||||
fun parseMultiValue_single() {
|
||||
assertEquals(listOf("a", "b", "c"), listOf("a,b,c").parseMultiValue(","))
|
||||
assertEquals(
|
||||
listOf("a", "b", "c"), listOf("a,b,c").parseMultiValue(SeparatorMusicSettings(",")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseMultiValue_many() {
|
||||
assertEquals(listOf("a", "b", "c"), listOf("a", "b", "c").parseMultiValue(","))
|
||||
assertEquals(
|
||||
listOf("a", "b", "c"),
|
||||
listOf("a", "b", "c").parseMultiValue(SeparatorMusicSettings(",")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseMultiValue_several() {
|
||||
assertEquals(
|
||||
listOf("a", "b", "c", "d", "e", "f"), listOf("a,b;c/d+e&f").parseMultiValue(",;/+&"))
|
||||
listOf("a", "b", "c", "d", "e", "f"),
|
||||
listOf("a,b;c/d+e&f").parseMultiValue(SeparatorMusicSettings(",;/+&")))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,37 +110,45 @@ class ParsingUtilTest {
|
||||
fun parseId3v2Genre_multi() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch").parseId3GenreNames(","))
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch")
|
||||
.parseId3GenreNames(SeparatorMusicSettings(",")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_multiId3v1() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("176", "178", "Glitch").parseId3GenreNames(","))
|
||||
listOf("176", "178", "Glitch").parseId3GenreNames(SeparatorMusicSettings(",")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_wackId3() {
|
||||
assertEquals(listOf("2941"), listOf("2941").parseId3GenreNames(","))
|
||||
assertEquals(listOf("2941"), listOf("2941").parseId3GenreNames(SeparatorMusicSettings(",")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_singleId3v23() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Remix", "Cover", "Glitch"),
|
||||
listOf("(176)(178)(RX)(CR)Glitch").parseId3GenreNames(","))
|
||||
listOf("(176)(178)(RX)(CR)Glitch").parseId3GenreNames(SeparatorMusicSettings(",")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_singleSeparated() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("Post-Rock, Shoegaze, Glitch").parseId3GenreNames(","))
|
||||
listOf("Post-Rock, Shoegaze, Glitch").parseId3GenreNames(SeparatorMusicSettings(",")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parsId3v2Genre_singleId3v1() {
|
||||
assertEquals(listOf("Post-Rock"), listOf("176").parseId3GenreNames(","))
|
||||
assertEquals(
|
||||
listOf("Post-Rock"), listOf("176").parseId3GenreNames(SeparatorMusicSettings(",")))
|
||||
}
|
||||
|
||||
class SeparatorMusicSettings(private val separators: String) : FakeMusicSettings {
|
||||
override var multiValueSeparators: String
|
||||
get() = separators
|
||||
set(_) = throw NotImplementedError()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user