Refactor delegation unit tests.

This commit is contained in:
Ilya Gorbunov
2015-06-23 21:44:29 +03:00
parent d04e94c826
commit 9caf5baf34
4 changed files with 132 additions and 261 deletions
@@ -4,53 +4,30 @@ import org.junit.Test as test
import kotlin.test.* import kotlin.test.*
import kotlin.properties.* import kotlin.properties.*
interface WithBox { class NotNullVarTest() {
fun box(): String test fun doTest() {
} NotNullVarTestGeneric("a", "b").doTest()
abstract class DelegationTestBase {
fun doTest(klass: WithBox) {
assertEquals("OK", klass.box())
} }
} }
class DelegationTest(): DelegationTestBase() { private class NotNullVarTestGeneric<T>(val a1: String, val b1: T) {
test fun testNotNullVar() {
doTest(TestNotNullVar("a", "b"))
}
test fun testObservablePropertyInChangeSupport() {
doTest(TestObservablePropertyInChangeSupport())
}
test fun testObservableProperty() {
doTest(TestObservableProperty())
}
test fun testVetoableProperty() {
doTest(TestVetoableProperty())
}
}
public class TestNotNullVar<T>(val a1: String, val b1: T): WithBox {
var a: String by Delegates.notNull() var a: String by Delegates.notNull()
var b by Delegates.notNull<T>() var b by Delegates.notNull<T>()
override fun box(): String { public fun doTest() {
a = a1 a = a1
b = b1 b = b1
if (a != "a") return "fail: a shouuld be a, but was $a" assertTrue(a == "a", "fail: a should be a, but was $a")
if (b != "b") return "fail: b should be b, but was $b" assertTrue(b == "b", "fail: b should be b, but was $b")
return "OK"
} }
} }
class TestObservablePropertyInChangeSupport: WithBox, ChangeSupport() { class ObservablePropertyInChangeSupportTest: ChangeSupport() {
var b by property(init = 2) var b by property(init = 2)
var c by property(3) var c by property(3)
override fun box(): String { test fun doTest() {
var result = false var result = false
addChangeListener("b", object: ChangeListener { addChangeListener("b", object: ChangeListener {
public override fun onPropertyChange(event: ChangeEvent) { public override fun onPropertyChange(event: ChangeEvent) {
@@ -63,39 +40,36 @@ class TestObservablePropertyInChangeSupport: WithBox, ChangeSupport() {
} }
}) })
b = 4 b = 4
if (b != 4) return "fail: b != 4" assertTrue(b == 4, "fail: b != 4")
if (!result) return "fail: result should be true" assertTrue(result, "fail: result should be true")
return "OK"
} }
} }
class TestObservableProperty: WithBox { class ObservablePropertyTest {
var result = false var result = false
var b by Delegates.observable(1, { pd, o, n -> result = true}) var b by Delegates.observable(1, { pd, o, n -> result = true})
override fun box(): String { test fun doTest() {
b = 4 b = 4
if (b != 4) return "fail: b != 4" assertTrue(b == 4, "fail: b != 4")
if (!result) return "fail: result should be true" assertTrue(result, "fail: result should be true")
return "OK"
} }
} }
class A(val p: Boolean) class A(val p: Boolean)
class TestVetoableProperty: WithBox { class VetoablePropertyTest {
var result = false var result = false
var b by Delegates.vetoable(A(true), { pd, o, n -> result = n.p == true; result}) var b by Delegates.vetoable(A(true), { pd, o, n -> result = n.p == true; result})
override fun box(): String { test fun doTest() {
val firstValue = A(true) val firstValue = A(true)
b = firstValue b = firstValue
if (b != firstValue) return "fail1: b should be firstValue = A(true)" assertTrue(b == firstValue, "fail1: b should be firstValue = A(true)")
if (!result) return "fail2: result should be true" assertTrue(result, "fail2: result should be true")
b = A(false) b = A(false)
if (b != firstValue) return "fail3: b should be firstValue = A(true)" assertTrue(b == firstValue, "fail3: b should be firstValue = A(true)")
if (result) return "fail4: result should be false" assertFalse(result, "fail4: result should be false")
return "OK"
} }
} }
@@ -1,4 +1,4 @@
package test.properties.delegation package test.properties.delegation.map
import java.util.* import java.util.*
import kotlin.properties.* import kotlin.properties.*
@@ -1,228 +1,175 @@
package test.properties.delegation package test.properties.delegation.map
import org.junit.Test as test import org.junit.Test as test
import java.util.HashMap import java.util.HashMap
import kotlin.properties.* import kotlin.properties.*
import kotlin.test.* import kotlin.test.*
class MapDelegationTest(): DelegationTestBase() {
test fun testMapPropertyString() {
doTest(TestMapPropertyString())
}
test fun testMapValWithDifferentTypes() {
doTest(TestMapValWithDifferentTypes())
}
test fun testMapVarWithDifferentTypes() {
doTest(TestMapVarWithDifferentTypes())
}
test fun testNullableKey() {
doTest(TestNullableKey())
}
test fun testMapPropertyKey() {
doTest(TestMapPropertyKey())
}
test fun testMapPropertyFunction() {
doTest(TestMapPropertyFunction())
}
test fun testMapPropertyCustom() {
doTest(TestMapPropertyCustom())
}
test fun testMapValWithDefault() {
doTest(TestMapValWithDefault())
}
test fun testMapVarWithDefault() {
doTest(TestMapVarWithDefault())
}
test fun testMapPropertyCustomWithDefault() {
doTest(TestMapPropertyCustomWithDefault())
}
}
data class B(val a: Int) data class B(val a: Int)
class TestMapValWithDifferentTypes(): WithBox { class MapValWithDifferentTypesTest() {
val map = hashMapOf("a" to "a", "b" to 1, "c" to B(1), "d" to null) val map = hashMapOf("a" to "a", "b" to 1, "c" to B(1), "d" to null)
val a by Delegates.mapVal<String>(map) val a by Delegates.mapVal<String>(map)
val b by Delegates.mapVal<Int>(map) val b by Delegates.mapVal<Int>(map)
val c by Delegates.mapVal<Any>(map) val c by Delegates.mapVal<Any>(map)
val d by Delegates.mapVal<Int?>(map) val d by Delegates.mapVal<Int?>(map)
override fun box(): String { test fun doTest() {
if (a != "a") return "fail at 'a'" assertTrue(a == "a", "fail at 'a'")
if (b != 1) return "fail at 'b'" assertTrue(b == 1, "fail at 'b'")
if (c != B(1)) return "fail at 'c'" assertTrue(c == B(1), "fail at 'c'")
if (d != null) return "fail at 'd'" assertTrue(d == null, "fail at 'd'")
return "OK"
} }
} }
class TestMapVarWithDifferentTypes(): WithBox { class MapVarWithDifferentTypesTest() {
val map: HashMap<String, Any?> = hashMapOf("a" to "a", "b" to 1, "c" to B(1), "d" to "d") val map: HashMap<String, Any?> = hashMapOf("a" to "a", "b" to 1, "c" to B(1), "d" to "d")
var a: String by Delegates.mapVar(map) var a: String by Delegates.mapVar(map)
var b: Int by Delegates.mapVar(map) var b: Int by Delegates.mapVar(map)
var c by Delegates.mapVar<Any>(map) var c by Delegates.mapVar<Any>(map)
var d by Delegates.mapVar<String?>(map) var d by Delegates.mapVar<String?>(map)
override fun box(): String { test fun doTest() {
a = "aa" a = "aa"
b = 11 b = 11
c = B(11) c = B(11)
d = null d = null
if (a != "aa") return "fail at 'a'" assertTrue(a == "aa", "fail at 'a'")
if (b != 11) return "fail at 'b'" assertTrue(b == 11, "fail at 'b'")
if (c != B(11)) return "fail at 'c'" assertTrue(c == B(11), "fail at 'c'")
if (d != null) return "fail at 'd'" assertTrue(d == null, "fail at 'd'")
map["a"] = null map["a"] = null
a // fails { a } // does not fail due to KT-8135 a // fails { a } // does not fail due to KT-8135
return "OK"
} }
} }
class TestNullableKey: WithBox { class MapNullableKeyTest {
val map = hashMapOf(null:Any? to "null": Any?) val map = hashMapOf<Any?, Any?>(null to "null")
var a by FixedMapVar<Any?, Any?, Any?>(map, key = { desc -> null }, default = {ref, desc -> null}) var a by FixedMapVar<Any?, Any?, Any?>(map, key = { desc -> null }, default = {ref, desc -> null})
override fun box(): String { test fun doTest() {
if (a != "null") return "fail at 'a'" assertTrue(a == "null", "fail at 'a'")
a = "foo" a = "foo"
if (a != "foo") return "fail at 'a' after set" assertTrue(a == "foo", "fail at 'a' after set")
return "OK"
} }
} }
class TestMapPropertyString(): WithBox { class MapPropertyStringTest() {
val map = hashMapOf("a" to "a", "b" to "b", "c" to "c":Any?) val map = hashMapOf<String, Any?>("a" to "a", "b" to "b", "c" to "c")
val a: String by Delegates.mapVal(map) val a: String by Delegates.mapVal(map)
var b by Delegates.mapVar<String>(map) var b by Delegates.mapVar<String>(map)
val c by Delegates.mapVal<String>(map) val c by Delegates.mapVal<String>(map)
override fun box(): String { test fun doTest() {
b = "newB" b = "newB"
if (a != "a") return "fail at 'a'" assertTrue(a == "a", "fail at 'a'")
if (b != "newB") return "fail at 'b'" assertTrue(b == "newB", "fail at 'b'")
if (c != "c") return "fail at 'c'" assertTrue(c == "c", "fail at 'c'")
return "OK"
} }
} }
class TestMapValWithDefault(): WithBox { class MapValWithDefaultTest() {
val map = hashMapOf<String, String>() val map = hashMapOf<String, String>()
val a: String by Delegates.mapVal(map, default = { ref, desc -> "aDefault" }) val a: String by Delegates.mapVal(map, default = { ref, desc -> "aDefault" })
val b: String by FixedMapVal(map, default = { ref: TestMapValWithDefault, desc: String -> "bDefault" }, key = {"b"}) val b: String by FixedMapVal(map, default = { ref: MapValWithDefaultTest, desc: String -> "bDefault" }, key = {"b"})
val c: String by FixedMapVal(map, default = { ref: TestMapValWithDefault, desc: String -> "cDefault" }, key = { desc -> desc.name }) val c: String by FixedMapVal(map, default = { ref: MapValWithDefaultTest, desc: String -> "cDefault" }, key = { desc -> desc.name })
override fun box(): String { test fun doTest() {
if (a != "aDefault") return "fail at 'a'" assertTrue(a == "aDefault", "fail at 'a'")
if (b != "bDefault") return "fail at 'b'" assertTrue(b == "bDefault", "fail at 'b'")
if (c != "cDefault") return "fail at 'c'" assertTrue(c == "cDefault", "fail at 'c'")
return "OK"
} }
} }
class TestMapVarWithDefault(): WithBox { class MapVarWithDefaultTest() {
val map = hashMapOf<String, Any?>() val map = hashMapOf<String, Any?>()
var a: String by Delegates.mapVar(map, default = {ref, desc -> "aDefault" }) var a: String by Delegates.mapVar(map, default = {ref, desc -> "aDefault" })
var b: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "bDefault" }, key = {"b"}) var b: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "bDefault" }, key = {"b"})
var c: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "cDefault" }, key = { desc -> desc.name }) var c: String by FixedMapVar(map, default = {ref: Any?, desc: String -> "cDefault" }, key = { desc -> desc.name })
override fun box(): String { test fun doTest() {
if (a != "aDefault") return "fail at 'a'" assertTrue(a == "aDefault", "fail at 'a'")
if (b != "bDefault") return "fail at 'b'" assertTrue(b == "bDefault", "fail at 'b'")
if (c != "cDefault") return "fail at 'c'" assertTrue(c == "cDefault", "fail at 'c'")
a = "a" a = "a"
b = "b" b = "b"
c = "c" c = "c"
if (a != "a") return "fail at 'a' after set" assertTrue(a == "a", "fail at 'a' after set")
if (b != "b") return "fail at 'b' after set" assertTrue(b == "b", "fail at 'b' after set")
if (c != "c") return "fail at 'c' after set" assertTrue(c == "c", "fail at 'c' after set")
return "OK"
} }
} }
class TestMapPropertyKey(): WithBox { class MapPropertyKeyTest() {
val map = hashMapOf("a" to "a", "b" to "b" : Any?) val map = hashMapOf<String, Any?>("a" to "a", "b" to "b")
val a by FixedMapVal<Any?, String, String>(map, key = {"a"}) val a by FixedMapVal<Any?, String, String>(map, key = {"a"})
var b by FixedMapVar<Any?, String, String>(map, key = {"b"}) var b by FixedMapVar<Any?, String, String>(map, key = {"b"})
override fun box(): String { test fun doTest() {
b = "c" b = "c"
if (a != "a") return "fail at 'a'" assertTrue(a == "a", "fail at 'a'")
if (b != "c") return "fail at 'b'" assertTrue(b == "c", "fail at 'b'")
return "OK"
} }
} }
class TestMapPropertyFunction(): WithBox { class MapPropertyFunctionTest() {
val map = hashMapOf("aDesc" to "a", "bDesc" to "b": Any?) val map = hashMapOf<String, Any?>("aDesc" to "a", "bDesc" to "b")
val a by FixedMapVal<Any?, String, String>(map, { desc -> "${desc.name}Desc" }) val a by FixedMapVal<Any?, String, String>(map, { desc -> "${desc.name}Desc" })
var b by FixedMapVar<Any?, String, String>(map, { desc -> "${desc.name}Desc" }) var b by FixedMapVar<Any?, String, String>(map, { desc -> "${desc.name}Desc" })
override fun box(): String { test fun doTest() {
b = "c" b = "c"
if (a != "a") return "fail at 'a'" assertTrue(a == "a", "fail at 'a'")
if (b != "c") return "fail at 'b' after set" assertTrue(b == "c", "fail at 'b' after set")
return "OK"
} }
} }
val mapVal = object: MapVal<TestMapPropertyCustom, String, String>() { val mapVal = object: MapVal<MapPropertyCustomTest, String, String>() {
override fun map(ref: TestMapPropertyCustom) = ref.map override fun map(ref: MapPropertyCustomTest) = ref.map
override fun key(desc: PropertyMetadata) = "${desc.name}Desc" override fun key(desc: PropertyMetadata) = "${desc.name}Desc"
} }
val mapVar = object : MapVar<TestMapPropertyCustom, String, String>() { val mapVar = object : MapVar<MapPropertyCustomTest, String, String>() {
override fun map(ref: TestMapPropertyCustom) = ref.map override fun map(ref: MapPropertyCustomTest) = ref.map
override fun key(desc: PropertyMetadata) = "${desc.name}Desc" override fun key(desc: PropertyMetadata) = "${desc.name}Desc"
} }
class TestMapPropertyCustom(): WithBox { class MapPropertyCustomTest() {
val map = hashMapOf("aDesc" to "a", "bDesc" to "b":Any?) val map = hashMapOf<String, Any?>("aDesc" to "a", "bDesc" to "b")
val a by mapVal val a by mapVal
var b by mapVar var b by mapVar
override fun box(): String { test fun doTest() {
b = "newB" b = "newB"
if (a != "a") return "fail at 'a'" assertTrue(a == "a", "fail at 'a'")
if (b != "newB") return "fail at 'b' after set" assertTrue(b == "newB", "fail at 'b' after set")
return "OK"
} }
} }
val mapValWithDefault = object : MapVal<TestMapPropertyCustomWithDefault, String, String>() { val mapValWithDefault = object : MapVal<MapPropertyCustomWithDefaultTest, String, String>() {
override fun map(ref: TestMapPropertyCustomWithDefault) = ref.map override fun map(ref: MapPropertyCustomWithDefaultTest) = ref.map
override fun key(desc: PropertyMetadata) = desc.name override fun key(desc: PropertyMetadata) = desc.name
override fun default(ref: TestMapPropertyCustomWithDefault, key: PropertyMetadata) = "default" override fun default(ref: MapPropertyCustomWithDefaultTest, key: PropertyMetadata) = "default"
} }
val mapVarWithDefault = object : MapVar<TestMapPropertyCustomWithDefault, String, String>() { val mapVarWithDefault = object : MapVar<MapPropertyCustomWithDefaultTest, String, String>() {
override fun map(ref: TestMapPropertyCustomWithDefault) = ref.map override fun map(ref: MapPropertyCustomWithDefaultTest) = ref.map
override fun key(desc: PropertyMetadata) = desc.name override fun key(desc: PropertyMetadata) = desc.name
override fun default(ref: TestMapPropertyCustomWithDefault, key: PropertyMetadata) = "default" override fun default(ref: MapPropertyCustomWithDefaultTest, key: PropertyMetadata) = "default"
} }
class TestMapPropertyCustomWithDefault(): WithBox { class MapPropertyCustomWithDefaultTest() {
val map = hashMapOf<String, Any?>() val map = hashMapOf<String, Any?>()
val a by mapValWithDefault val a by mapValWithDefault
var b by mapVarWithDefault var b by mapVarWithDefault
override fun box(): String { test fun doTest() {
if (a != "default") return "fail at 'a'" assertTrue(a == "default", "fail at 'a'")
if (b != "default") return "fail at 'b'" assertTrue(b == "default", "fail at 'b'")
b = "c" b = "c"
if (b != "c") return "fail at 'b' after set" assertTrue(b == "c", "fail at 'b' after set")
return "OK"
} }
} }
@@ -1,93 +1,49 @@
package test.properties.delegation.lazy package test.properties.delegation.lazy
import test.properties.delegation.WithBox
import test.properties.delegation.DelegationTestBase
import org.junit.Test as test import org.junit.Test as test
import kotlin.properties.* import kotlin.properties.*
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
class LazyValuesTest(): DelegationTestBase() { class LazyValTest {
test fun testLazyVal() {
doTest(TestLazyVal())
}
test fun testUnsafeLazyVal() {
doTest(TestUnsafeLazyVal())
}
test fun testNullableLazyVal() {
doTest(TestNullableLazyVal())
}
test fun testUnsafeNullableLazyVal() {
doTest(TestUnsafeNullableLazyVal())
}
// deprecated lazy tests
test fun testUnsafeLazyValDeprecated() {
doTest(TestUnsafeLazyValDeprecated())
}
test fun testBlockingLazyValDeprecated() {
doTest(TestBlockingLazyValDeprecated())
}
test fun testUnsafeNullableLazyValDeprecated() {
doTest(TestUnsafeNullableLazyValDeprecated())
}
test fun testBlockingNullableLazyValDeprecated() {
doTest(TestBlockingNullableLazyValDeprecated())
}
test fun testIdentityEqualsIsUsedToUnescapeLazyVal() {
doTest(TestIdentityEqualsIsUsedToUnescapeLazyVal())
}
}
class TestLazyVal: WithBox {
var result = 0 var result = 0
val a by lazy { val a by lazy {
++result ++result
} }
override fun box(): String { test fun doTest() {
a a
if (a != 1) return "fail: initializer should be invoked only once" assertTrue(a == 1, "fail: initializer should be invoked only once")
return "OK"
} }
} }
class TestUnsafeLazyVal: WithBox { class UnsafeLazyValTest {
var result = 0 var result = 0
val a by lazy(LazyThreadSafetyMode.NONE) { val a by lazy(LazyThreadSafetyMode.NONE) {
++result ++result
} }
override fun box(): String { test fun doTest() {
a a
if (a != 1) return "fail: initializer should be invoked only once" assertTrue(a == 1, "fail: initializer should be invoked only once")
return "OK"
} }
} }
class TestNullableLazyVal: WithBox { class NullableLazyValTest {
var resultA = 0 var resultA = 0
var resultB = 0 var resultB = 0
val a: Int? by lazy { resultA++; null} val a: Int? by lazy { resultA++; null}
val b by lazy { foo() } val b by lazy { foo() }
override fun box(): String { test fun doTest() {
a a
b b
if (a != null) return "fail: a should be null" assertTrue(a == null, "fail: a should be null")
if (b != null) return "fail: a should be null" assertTrue(b == null, "fail: b should be null")
if (resultA != 1) return "fail: initializer for a should be invoked only once" assertTrue(resultA == 1, "fail: initializer for a should be invoked only once")
if (resultB != 1) return "fail: initializer for b should be invoked only once" assertTrue(resultB == 1, "fail: initializer for b should be invoked only once")
return "OK"
} }
fun foo(): String? { fun foo(): String? {
@@ -96,22 +52,21 @@ class TestNullableLazyVal: WithBox {
} }
} }
class TestUnsafeNullableLazyVal: WithBox { class UnsafeNullableLazyValTest {
var resultA = 0 var resultA = 0
var resultB = 0 var resultB = 0
val a: Int? by lazy(LazyThreadSafetyMode.NONE) { resultA++; null} val a: Int? by lazy(LazyThreadSafetyMode.NONE) { resultA++; null}
val b by lazy(LazyThreadSafetyMode.NONE) { foo() } val b by lazy(LazyThreadSafetyMode.NONE) { foo() }
override fun box(): String { test fun doTest() {
a a
b b
if (a != null) return "fail: a should be null" assertTrue(a == null, "fail: a should be null")
if (b != null) return "fail: a should be null" assertTrue(b == null, "fail: a should be null")
if (resultA != 1) return "fail: initializer for a should be invoked only once" assertTrue(resultA == 1, "fail: initializer for a should be invoked only once")
if (resultB != 1) return "fail: initializer for b should be invoked only once" assertTrue(resultB == 1, "fail: initializer for b should be invoked only once")
return "OK"
} }
fun foo(): String? { fun foo(): String? {
@@ -120,48 +75,45 @@ class TestUnsafeNullableLazyVal: WithBox {
} }
} }
class TestUnsafeLazyValDeprecated: WithBox { class UnsafeLazyValDeprecatedTest {
var result = 0 var result = 0
val a by Delegates.lazy { val a by Delegates.lazy {
++result ++result
} }
override fun box(): String { test fun doTest() {
a a
if (a != 1) return "fail: initializer should be invoked only once" assertTrue(a == 1, "fail: initializer should be invoked only once")
return "OK"
} }
} }
class TestBlockingLazyValDeprecated: WithBox { class BlockingLazyValDeprecatedTest {
var result = 0 var result = 0
val a by Delegates.blockingLazy { val a by Delegates.blockingLazy {
++result ++result
} }
override fun box(): String { test fun doTest() {
a a
if (a != 1) return "fail: initializer should be invoked only once" assertTrue(a == 1, "fail: initializer should be invoked only once")
return "OK"
} }
} }
class TestUnsafeNullableLazyValDeprecated : WithBox { class UnsafeNullableLazyValDeprecatedTest {
var resultA = 0 var resultA = 0
var resultB = 0 var resultB = 0
val a: Int? by Delegates.lazy { resultA++; null} val a: Int? by Delegates.lazy { resultA++; null}
val b by Delegates.lazy { foo() } val b by Delegates.lazy { foo() }
override fun box(): String { test fun doTest() {
a a
b b
if (a != null) return "fail: a should be null" assertTrue(a == null, "fail: a should be null")
if (b != null) return "fail: a should be null" assertTrue(b == null, "fail: b should be null")
if (resultA != 1) return "fail: initializer for a should be invoked only once" assertTrue(resultA == 1, "fail: initializer for a should be invoked only once")
if (resultB != 1) return "fail: initializer for b should be invoked only once" assertTrue(resultB == 1, "fail: initializer for b should be invoked only once")
return "OK"
} }
fun foo(): String? { fun foo(): String? {
@@ -170,22 +122,21 @@ class TestUnsafeNullableLazyValDeprecated : WithBox {
} }
} }
class TestBlockingNullableLazyValDeprecated: WithBox { class BlockingNullableLazyValDeprecatedTest {
var resultA = 0 var resultA = 0
var resultB = 0 var resultB = 0
val a: Int? by Delegates.blockingLazy { resultA++; null} val a: Int? by Delegates.blockingLazy { resultA++; null}
val b by Delegates.blockingLazy { foo() } val b by Delegates.blockingLazy { foo() }
override fun box(): String { test fun doTest() {
a a
b b
if (a != null) return "fail: a should be null" assertTrue(a == null, "fail: a should be null")
if (b != null) return "fail: a should be null" assertTrue(b == null, "fail: a should be null")
if (resultA != 1) return "fail: initializer for a should be invoked only once" assertTrue(resultA == 1, "fail: initializer for a should be invoked only once")
if (resultB != 1) return "fail: initializer for b should be invoked only once" assertTrue(resultB == 1, "fail: initializer for b should be invoked only once")
return "OK"
} }
fun foo(): String? { fun foo(): String? {
@@ -194,15 +145,14 @@ class TestBlockingNullableLazyValDeprecated: WithBox {
} }
} }
class TestIdentityEqualsIsUsedToUnescapeLazyVal: WithBox { class IdentityEqualsIsUsedToUnescapeLazyValTest {
var equalsCalled = 0 var equalsCalled = 0
val a by lazy { ClassWithCustomEquality { equalsCalled++ } } val a by lazy { ClassWithCustomEquality { equalsCalled++ } }
override fun box(): String { test fun doTest() {
a a
a a
if (equalsCalled > 0) return "fail: equals called $equalsCalled times." assertTrue(equalsCalled == 0, "fail: equals called $equalsCalled times.")
return "OK"
} }
} }