From d3ff0193543c81b721ffa22932e0a17cb0bc5a44 Mon Sep 17 00:00:00 2001 From: nappy29 Date: Thu, 28 Nov 2024 13:26:06 +0100 Subject: [PATCH] added unit test --- ...aryConstructorCallExpectedIssueUnitTest.kt | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-advanced-4/src/test/kotlin/com/baeldung/resolvePrimaryConstructorCallExpectedIssue/resolvePrimaryConstructorCallExpectedIssueUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-advanced-4/src/test/kotlin/com/baeldung/resolvePrimaryConstructorCallExpectedIssue/resolvePrimaryConstructorCallExpectedIssueUnitTest.kt b/core-kotlin-modules/core-kotlin-advanced-4/src/test/kotlin/com/baeldung/resolvePrimaryConstructorCallExpectedIssue/resolvePrimaryConstructorCallExpectedIssueUnitTest.kt new file mode 100644 index 000000000..6fbeebe02 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-advanced-4/src/test/kotlin/com/baeldung/resolvePrimaryConstructorCallExpectedIssue/resolvePrimaryConstructorCallExpectedIssueUnitTest.kt @@ -0,0 +1,48 @@ +package com.baeldung.resolvePrimaryConstructorCallExpectedIssue + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class resolvePrimaryConstructorCallExpectedIssueUnitTest { + + @Test + fun `correctly resolve compile error by properly defining constructors`() { + val student = Student("Martial", 15) + + assertEquals("Martial", student.name) + assertEquals(15, student.age) + } + + @Test + fun `correctly resolve compile error by properly using the secondary constructor`() { + val dog = Dog("Max") + assertEquals("Max", dog.species) + } + + @Test + fun `correctly resolve compile error by properly using default parameters`() { + val car1 = Car("Toyota", "Corolla") + + assertEquals("Toyota", car1.make) + assertEquals("Corolla", car1.model) + + } +} + +class Student(var name: String) { + var age: Int = 14 + + constructor(name: String, age: Int) : this(name) { + this.age = age + } + + fun printMsg() { + println("Name is $name. Age is $age.") + } +} + +open class Animal(val species: String) + +class Dog(species: String) : Animal(species) + +class Car(val make: String, val model: String = "Unknown")