2020-06-15 18:58:44 +03:00
|
|
|
package baseClassInitializationExercise3
|
2020-07-29 23:41:56 +03:00
|
|
|
import atomictest.trace
|
|
|
|
import org.junit.FixMethodOrder
|
2020-06-15 18:52:18 +03:00
|
|
|
import org.junit.Test
|
2020-07-29 23:41:56 +03:00
|
|
|
import org.junit.runners.MethodSorters
|
|
|
|
import util.*
|
|
|
|
import kotlin.reflect.full.createInstance
|
|
|
|
import kotlin.test.assertEquals
|
2020-06-15 18:52:18 +03:00
|
|
|
|
2020-07-29 23:41:56 +03:00
|
|
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
2020-12-12 00:58:47 +03:00
|
|
|
class TestBaseClassInitializationExercise3 : TestTrace() {
|
2020-07-29 23:41:56 +03:00
|
|
|
|
|
|
|
private val packageName = "baseClassInitializationExercise3"
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `#01 classes structure`() {
|
|
|
|
loadClass(packageName, "Animal").apply {
|
|
|
|
assertConstructorNumber(1)
|
|
|
|
assertParametersOfFirstConstructor(
|
|
|
|
"sound" to String::class
|
|
|
|
)
|
|
|
|
assertMemberProperty("sound", String::class)
|
|
|
|
}
|
|
|
|
loadClass(packageName, "Cat").apply {
|
|
|
|
assertInheritance("Animal")
|
|
|
|
assertConstructorNumber(1)
|
|
|
|
assertParametersOfFirstConstructor(
|
|
|
|
"sound" to String::class
|
|
|
|
)
|
|
|
|
assertNoDeclaredMemberProperty("sound")
|
2020-06-15 18:52:18 +03:00
|
|
|
}
|
2020-07-29 23:41:56 +03:00
|
|
|
loadClass(packageName, "Dog").apply {
|
|
|
|
assertInheritance("Animal")
|
|
|
|
assertConstructorNumber(1)
|
|
|
|
assertParametersOfFirstConstructor(
|
|
|
|
"sound" to String::class
|
|
|
|
)
|
|
|
|
assertNoDeclaredMemberProperty("sound")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `#02 animal sounds`() {
|
|
|
|
loadClass(packageName, "Animal").apply {
|
|
|
|
val animal = createInstance()
|
|
|
|
val sound = loadMemberProperty(this, "sound").call(animal) as String
|
|
|
|
trace(sound)
|
|
|
|
}
|
|
|
|
loadClass(packageName, "Cat").apply {
|
|
|
|
val cat = createInstance()
|
|
|
|
val sound = loadMemberProperty(this, "sound").call(cat) as String
|
|
|
|
trace(sound)
|
|
|
|
}
|
|
|
|
loadClass(packageName, "Dog").apply {
|
|
|
|
val dog = createInstance()
|
|
|
|
val sound = loadMemberProperty(this, "sound").call(dog) as String
|
|
|
|
trace(sound)
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
message = "Incorrect animal sounds",
|
|
|
|
actual = loadTraceContent(),
|
|
|
|
expected = listOf(
|
|
|
|
"???",
|
|
|
|
"meow",
|
|
|
|
"woof"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2020-06-15 18:52:18 +03:00
|
|
|
}
|