test: refactor & add more tests

This commit is contained in:
Sculas 2022-08-02 22:00:32 +02:00
parent 4e2e772389
commit 67a5237541
No known key found for this signature in database
GPG key ID: 1530BFF96D1EEB89

View file

@ -1,13 +1,14 @@
package app.revanced.patcher.usage
package app.revanced.patcher.patch
import app.revanced.patcher.patch.PatchOption
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
import kotlin.test.Test
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
internal class PatchOptionsTest {
private val options = ExampleBytecodePatch().options
internal class PatchOptionsUsage {
@Test
fun patchOptionsUsage() {
val options = ExampleBytecodePatch().options
fun `should not throw an exception`() {
for (option in options) {
when (option) {
is PatchOption.StringOption -> {
@ -34,4 +35,25 @@ internal class PatchOptionsUsage {
options["key1"] = "Hello, world!"
println(options["key1"].value)
}
@Test
fun `should fail because the option does not exist`() {
assertThrows<NoSuchOptionException> {
options["this option does not exist"] = 123
}
}
@Test
fun `should fail because of invalid value type`() {
assertThrows<IllegalArgumentException> {
options["key1"] = 123
}
}
@Test
fun `should fail because of an illegal value`() {
assertThrows<IllegalArgumentException> {
options["key3"] = "this value is not an allowed option"
}
}
}