mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 09:08:04 +01:00
chore: assert instead of printing in tests
This commit is contained in:
parent
072986374a
commit
93b29d2e83
2 changed files with 19 additions and 13 deletions
|
@ -39,8 +39,10 @@ sealed class PatchBundleLoader private constructor(
|
||||||
*
|
*
|
||||||
* @param patchBundles The path to patch bundles of JAR format.
|
* @param patchBundles The path to patch bundles of JAR format.
|
||||||
*/
|
*/
|
||||||
class Jar(vararg patchBundles: File) :
|
class Jar(vararg patchBundles: File) : PatchBundleLoader(
|
||||||
PatchBundleLoader(with(URLClassLoader(patchBundles.map { it.toURI().toURL() }.toTypedArray())) {
|
with(
|
||||||
|
URLClassLoader(patchBundles.map { it.toURI().toURL() }.toTypedArray())
|
||||||
|
) {
|
||||||
patchBundles.flatMap { patchBundle ->
|
patchBundles.flatMap { patchBundle ->
|
||||||
// Get the names of all classes in the DEX file.
|
// Get the names of all classes in the DEX file.
|
||||||
|
|
||||||
|
@ -55,15 +57,17 @@ sealed class PatchBundleLoader private constructor(
|
||||||
* A [PatchBundleLoader] for [Dex] files.
|
* A [PatchBundleLoader] for [Dex] files.
|
||||||
*
|
*
|
||||||
* @param patchBundles The path to patch bundles of DEX format.
|
* @param patchBundles The path to patch bundles of DEX format.
|
||||||
|
* @param optimizedDexDirectory The directory to store optimized DEX files in.
|
||||||
|
* This parameter is deprecated and has no effect since API level 26.
|
||||||
*/
|
*/
|
||||||
class Dex(vararg patchBundles: File) : PatchBundleLoader(with(
|
class Dex(vararg patchBundles: File, optimizedDexDirectory: File? = null) : PatchBundleLoader(
|
||||||
DexClassLoader(
|
with(
|
||||||
patchBundles.joinToString(File.pathSeparator) { it.absolutePath },
|
DexClassLoader(
|
||||||
null,
|
patchBundles.joinToString(File.pathSeparator) { it.absolutePath }, optimizedDexDirectory?.absolutePath,
|
||||||
null,
|
null,
|
||||||
PatchBundleLoader::class.java.classLoader
|
PatchBundleLoader::class.java.classLoader
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
patchBundles
|
patchBundles
|
||||||
.flatMap {
|
.flatMap {
|
||||||
MultiDexIO.readDexFile(true, it, BasicDexFileNamer(), null, null).classes
|
MultiDexIO.readDexFile(true, it, BasicDexFileNamer(), null, null).classes
|
||||||
|
|
|
@ -3,7 +3,9 @@ package app.revanced.patcher.patch
|
||||||
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotEquals
|
import kotlin.test.assertNotEquals
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
internal class PatchOptionsTest {
|
internal class PatchOptionsTest {
|
||||||
private val options = ExampleBytecodePatch.options
|
private val options = ExampleBytecodePatch.options
|
||||||
|
@ -23,14 +25,14 @@ internal class PatchOptionsTest {
|
||||||
is PatchOption.StringListOption -> {
|
is PatchOption.StringListOption -> {
|
||||||
option.value = option.options.first()
|
option.value = option.options.first()
|
||||||
for (choice in option.options) {
|
for (choice in option.options) {
|
||||||
println(choice)
|
assertNotNull(choice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is PatchOption.IntListOption -> {
|
is PatchOption.IntListOption -> {
|
||||||
option.value = option.options.first()
|
option.value = option.options.first()
|
||||||
for (choice in option.options) {
|
for (choice in option.options) {
|
||||||
println(choice)
|
assertNotNull(choice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,9 +40,9 @@ internal class PatchOptionsTest {
|
||||||
val option = options.get<String>("key1")
|
val option = options.get<String>("key1")
|
||||||
// or: val option: String? by options["key1"]
|
// or: val option: String? by options["key1"]
|
||||||
// then you won't need `.value` every time
|
// then you won't need `.value` every time
|
||||||
println(option.value)
|
assertEquals("Hello World", option.value)
|
||||||
options["key1"] = "Hello, world!"
|
options["key1"] = "Hello, world!"
|
||||||
println(option.value)
|
assertEquals("Hello, world!", option.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -101,7 +103,7 @@ internal class PatchOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
fun `should fail because getting a non-initialized option is illegal`() {
|
fun `should fail because getting a non-initialized option is illegal`() {
|
||||||
assertThrows<RequirementNotMetException> {
|
assertThrows<RequirementNotMetException> {
|
||||||
println(options["key5"].value)
|
options["key5"].value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue