diff --git a/Object-Oriented Programming/Composition/Exercise 1/test/Tests.kt b/Object-Oriented Programming/Composition/Exercise 1/test/Tests.kt index 2167d44b..6c4dcb3b 100644 --- a/Object-Oriented Programming/Composition/Exercise 1/test/Tests.kt +++ b/Object-Oriented Programming/Composition/Exercise 1/test/Tests.kt @@ -23,7 +23,7 @@ class TestCompositionExercise1 { "radius" to Int::class, "color" to String::class ) - assertInheritance(this, listOf("Shape")) + assertInheritance("Shape") } loadClass(packageName, "Rectangle").apply { assertConstructorNumber(1) @@ -32,7 +32,7 @@ class TestCompositionExercise1 { "width" to Int::class, "color" to String::class ) - assertInheritance(this, listOf("Shape")) + assertInheritance("Shape") } } diff --git a/Object-Oriented Programming/Polymorphism/Exercise 1/test/Tests.kt b/Object-Oriented Programming/Polymorphism/Exercise 1/test/Tests.kt index d5b647f3..ed7b26e0 100644 --- a/Object-Oriented Programming/Polymorphism/Exercise 1/test/Tests.kt +++ b/Object-Oriented Programming/Polymorphism/Exercise 1/test/Tests.kt @@ -13,48 +13,48 @@ import kotlin.test.assertEquals @FixMethodOrder(MethodSorters.NAME_ASCENDING) class TestPolymorphismExercise1 { - private val packageName = "polymorphismExercise1" + private val packageName = "polymorphismExercise1" - @Test - fun `#01 classes structure`() { - loadClass(packageName, "Warrior").apply { - assertConstructorNumber(1) - assertInheritance(this, listOf("Character", "Fighter")) - } - loadClass(packageName, "Elf").apply { - assertConstructorNumber(1) - assertInheritance(this, listOf("Character", "Magician")) - } - loadClass(packageName, "FightingElf").apply { - assertConstructorNumber(1) - assertInheritance(this, listOf("Elf", "Fighter")) - } - loadClass(packageName, "Wizard").apply { - assertConstructorNumber(1) - assertInheritance(this, listOf("Character", "Magician", "Flyer")) - } - loadClass(packageName, "Dragon").apply { - assertConstructorNumber(1) - assertInheritance(this, listOf("Character", "Flyer")) - } + @Test + fun `#01 classes structure`() { + loadClass(packageName, "Warrior").apply { + assertConstructorNumber(1) + assertInheritance("Character", "Fighter") } + loadClass(packageName, "Elf").apply { + assertConstructorNumber(1) + assertInheritance("Character", "Magician") + } + loadClass(packageName, "FightingElf").apply { + assertConstructorNumber(1) + assertInheritance("Elf", "Fighter") + } + loadClass(packageName, "Wizard").apply { + assertConstructorNumber(1) + assertInheritance("Character", "Magician", "Flyer") + } + loadClass(packageName, "Dragon").apply { + assertConstructorNumber(1) + assertInheritance("Character", "Flyer") + } + } - @Test - fun `#02 what do the characters`() { - listOf("Warrior", "Elf", "FightingElf", "Dragon", "Wizard") - .map { loadClass(packageName, it).createInstance() as Character } - .forEach { c -> c.playTurn() } + @Test + fun `#02 what do the characters`() { + listOf("Warrior", "Elf", "FightingElf", "Dragon", "Wizard") + .map { loadClass(packageName, it).createInstance() as Character } + .forEach { c -> c.playTurn() } - assertEquals( - message = "Incorrect result of playTurn() for all characters", - actual = loadTraceContent(), - expected = listOf( - "Warrior: Fight!", - "Elf: Magic!", - "FightingElf: Magic!Fight!", - "Dragon: Fly!", - "Magician: Magic!Fly!" - ) + assertEquals( + message = "Incorrect result of playTurn() for all characters", + actual = loadTraceContent(), + expected = listOf( + "Warrior: Fight!", + "Elf: Magic!", + "FightingElf: Magic!Fight!", + "Dragon: Fly!", + "Magician: Magic!Fly!" ) - } + ) + } } diff --git a/Object-Oriented Programming/Polymorphism/Exercise 2/test/Tests.kt b/Object-Oriented Programming/Polymorphism/Exercise 2/test/Tests.kt index d3dddfdd..f7cb7155 100644 --- a/Object-Oriented Programming/Polymorphism/Exercise 2/test/Tests.kt +++ b/Object-Oriented Programming/Polymorphism/Exercise 2/test/Tests.kt @@ -22,7 +22,7 @@ class TestPolymorphismExercise2 { } loadClass(packageName, "Frog").apply { assertConstructorNumber(1) - assertInheritance(this, listOf("Animal")) + assertInheritance("Animal") } } diff --git a/Object-Oriented Programming/Sealed Classes/Exercise 1/test/Tests.kt b/Object-Oriented Programming/Sealed Classes/Exercise 1/test/Tests.kt index 561e469b..b4db3fc4 100644 --- a/Object-Oriented Programming/Sealed Classes/Exercise 1/test/Tests.kt +++ b/Object-Oriented Programming/Sealed Classes/Exercise 1/test/Tests.kt @@ -30,7 +30,7 @@ class TestSealedClassesExercise1 { mainParameterName to String::class, "capacity" to Int::class ) - assertInheritance(this, listOf("Transport")) + assertInheritance("Transport") } } diff --git a/util/test/util.kt b/util/test/util.kt index bfb43e03..0342e588 100644 --- a/util/test/util.kt +++ b/util/test/util.kt @@ -141,15 +141,15 @@ fun assertInheritance(derivedClass: KClass<*>, baseClass: KClass<*>) { ) } -fun assertInheritance(derivedClass: KClass<*>, baseClassNames: List) { - val packageName = derivedClass.qualifiedName!! - .removeSuffix(derivedClass.simpleName!!) +fun KClass<*>.assertInheritance(vararg baseClassNames: String) { + val packageName = qualifiedName!! + .removeSuffix(simpleName!!) .removeSuffix(".") baseClassNames.forEach { className -> val baseClass = loadClass(packageName, className) assertTrue( - actual = derivedClass.supertypes.contains(baseClass.createType()), - message = "${derivedClass.simpleName} should inherit ${baseClass.simpleName}" + actual = supertypes.contains(baseClass.createType()), + message = "$simpleName should inherit ${baseClass.simpleName}" ) } }