mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
StorageProfileManager test
This commit is contained in:
parent
1943a9f331
commit
60036f7f9a
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.config.profile.storage
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.minosoft.config.profile.test.TestProfile
|
||||
|
||||
class ProfileIOManagerTest {
|
||||
|
||||
|
||||
companion object {
|
||||
private val SAVE = ProfileIOManager::class.java.getDeclaredField("save").apply { isAccessible = true }
|
||||
|
||||
fun ProfileIOManager.isSaveQueued(storage: FileStorage): Boolean {
|
||||
val queue = SAVE.get(ProfileIOManager).unsafeCast<MutableSet<FileStorage>>()
|
||||
storage.invalid = false
|
||||
return queue.remove(storage)
|
||||
}
|
||||
|
||||
fun TestProfile.isSaveQueued(): Boolean {
|
||||
return ProfileIOManager.isSaveQueued(this.storage.unsafeCast())
|
||||
}
|
||||
}
|
||||
}
|
@ -13,10 +13,11 @@
|
||||
|
||||
package de.bixilon.minosoft.config.profile.storage
|
||||
|
||||
import de.bixilon.minosoft.config.profile.storage.ProfileIOManagerTest.Companion.isSaveQueued
|
||||
import de.bixilon.minosoft.config.profile.test.TestProfileManager
|
||||
import de.bixilon.minosoft.protocol.ProtocolUtil.encodeNetwork
|
||||
import de.bixilon.minosoft.terminal.RunConfiguration
|
||||
import org.testng.Assert.assertEquals
|
||||
import org.testng.Assert.*
|
||||
import org.testng.annotations.Test
|
||||
import java.io.FileOutputStream
|
||||
|
||||
@ -33,14 +34,44 @@ class StorageProfileManagerTest {
|
||||
stream.close()
|
||||
}
|
||||
|
||||
fun `load dumped profiles`() {
|
||||
val profile = """{"version": "1", "key_old": 123}"""
|
||||
dump("Dumped", profile)
|
||||
fun `load unmigrated profile`() {
|
||||
val profile = """{"version": 2, "key": 123}"""
|
||||
dump("Dumped1", profile)
|
||||
|
||||
val manager = TestProfileManager()
|
||||
assertEquals(manager["Dumped"], null)
|
||||
assertEquals(manager["Dumped1"], null)
|
||||
manager.load()
|
||||
val dumped = manager["Dumped"]!!
|
||||
val dumped = manager["Dumped1"]!!
|
||||
assertFalse(dumped.isSaveQueued())
|
||||
assertEquals(dumped.key, 123)
|
||||
base.toFile().deleteRecursively()
|
||||
}
|
||||
|
||||
fun `load migrated profile`() {
|
||||
val profile = """{"version": 1, "key_old": 123}"""
|
||||
dump("Dumped2", profile)
|
||||
|
||||
val manager = TestProfileManager()
|
||||
assertEquals(manager["Dumped2"], null)
|
||||
manager.load()
|
||||
val dumped = manager["Dumped2"]!!
|
||||
assertTrue(dumped.isSaveQueued()) // profile was migrated
|
||||
assertEquals(dumped.key, 123)
|
||||
base.toFile().deleteRecursively()
|
||||
}
|
||||
|
||||
fun `create and verify save is queued`() {
|
||||
val manager = TestProfileManager()
|
||||
val profile = manager.create("Dumped3")
|
||||
assertTrue(profile.isSaveQueued())
|
||||
}
|
||||
|
||||
fun `queue save on change`() {
|
||||
val manager = TestProfileManager()
|
||||
val profile = manager.create("Dumped4")
|
||||
assertTrue(profile.isSaveQueued())
|
||||
assertFalse(profile.isSaveQueued()) // save flag really removed
|
||||
profile.key = 999
|
||||
assertTrue(profile.isSaveQueued())
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ object ProfileIOManager {
|
||||
ignoreAll { delete() }
|
||||
ignoreAll { save() }
|
||||
ignoreAll { reload() }
|
||||
ignoreAll { selected() }
|
||||
|
||||
|
||||
lock.unlock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user