AndroidUnwrapTest.kt 1008 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * Copyright 2019-2021 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  8. */
  9. package net.mamoe.mirai.utils
  10. import kotlin.test.Test
  11. import kotlin.test.assertIs
  12. class AndroidUnwrapTest {
  13. @Test
  14. fun test() {
  15. val e =
  16. IllegalStateException(
  17. OutOfMemoryError().initCause(VerifyError()).apply { addSuppressed(UnsatisfiedLinkError()) }
  18. )
  19. val unwrapped = e.unwrap<IllegalStateException>()
  20. unwrapped.printStackTrace()
  21. assertIs<OutOfMemoryError>(unwrapped)
  22. assertIs<VerifyError>(unwrapped.cause)
  23. assertIs<UnsatisfiedLinkError>(unwrapped.suppressed.first())
  24. assertIs<StacktraceException>(unwrapped.suppressed[1])
  25. }
  26. }