blob: e32ba0ac6c2448e4f461f8660e70bdb6dfbccb29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/***************************************************************************************************
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
**************************************************************************************************/
package at.bitfire.ical4android
import org.junit.Assert.assertTrue
import org.junit.Test
class MiscUtilsTest {
@Test
fun testReflectionToString() {
val s = MiscUtils.reflectionToString(MiscUtilsTest.TestClass())
assertTrue(s.startsWith("TestClass=["))
assertTrue(s.contains("i=2"))
assertTrue(s.contains("large=null"))
assertTrue(s.contains("s=test"))
}
@Test
fun testReflectionToString_OOM() {
val t = MiscUtilsTest.TestClass()
t.large = object: Any() {
override fun toString(): String {
throw OutOfMemoryError("toString() causes OOM")
}
}
val s = MiscUtils.reflectionToString(t)
assertTrue(s.startsWith("TestClass=["))
assertTrue(s.contains("large=![java.lang.OutOfMemoryError"))
}
@Suppress("unused")
private class TestClass {
val i = 2
var large: Any? = null
private val s = "test"
}
}
|