feat: Add findParentMethod utility method (#4)

* feat: Add `findParentMethod` utitly method

* refactor: add `resolveMethod` to `MethodResolver`

added some assertions and some tests

Co-authored-by: Lucaskyy <contact@sculas.xyz>
This commit is contained in:
oSumAtrIX
2022-03-21 14:40:41 +01:00
parent b957501e70
commit bbb2c547aa
4 changed files with 88 additions and 25 deletions

View File

@@ -9,11 +9,13 @@ import net.revanced.patcher.util.ExtraTypes
import net.revanced.patcher.util.TestUtil
import net.revanced.patcher.writer.ASMWriter.insertAt
import net.revanced.patcher.writer.ASMWriter.setAt
import org.junit.jupiter.api.assertThrows
import org.objectweb.asm.Opcodes.*
import org.objectweb.asm.Type
import org.objectweb.asm.tree.*
import java.io.PrintStream
import kotlin.test.Test
import kotlin.test.assertEquals
internal class PatcherTest {
companion object {
@@ -145,4 +147,27 @@ internal class PatcherTest {
// out.close()
// testData.close()
//}
@Test()
fun `should raise an exception because opcodes is empty`() {
val sigName = "testMethod"
val e = assertThrows<IllegalArgumentException>("Should raise an exception because opcodes is empty") {
Patcher(
PatcherTest::class.java.getResourceAsStream("/test1.jar")!!,
arrayOf(
Signature(
sigName,
Type.VOID_TYPE,
ACC_PUBLIC or ACC_STATIC,
arrayOf(ExtraTypes.ArrayAny),
emptyArray() // this is not allowed for non-search signatures!
)
)
)
}
assertEquals(
"Opcode list for signature $sigName is empty. This is not allowed for non-search signatures.",
e.message
)
}
}