File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
core-kotlin-modules/core-kotlin-advanced-4/src/test/kotlin/com/baeldung/resolvePrimaryConstructorCallExpectedIssue Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ package com.baeldung.resolvePrimaryConstructorCallExpectedIssue
2+
3+ import org.junit.jupiter.api.Assertions.assertEquals
4+ import org.junit.jupiter.api.Test
5+
6+ class resolvePrimaryConstructorCallExpectedIssueUnitTest {
7+
8+ @Test
9+ fun `correctly resolve compile error by properly defining constructors` () {
10+ val student = Student (" Martial" , 15 )
11+
12+ assertEquals(" Martial" , student.name)
13+ assertEquals(15 , student.age)
14+ }
15+
16+ @Test
17+ fun `correctly resolve compile error by properly using the secondary constructor` () {
18+ val dog = Dog (" Max" )
19+ assertEquals(" Max" , dog.species)
20+ }
21+
22+ @Test
23+ fun `correctly resolve compile error by properly using default parameters` () {
24+ val car1 = Car (" Toyota" , " Corolla" )
25+
26+ assertEquals(" Toyota" , car1.make)
27+ assertEquals(" Corolla" , car1.model)
28+
29+ }
30+ }
31+
32+ class Student (var name : String ) {
33+ var age: Int = 14
34+
35+ constructor (name: String , age: Int ) : this (name) {
36+ this .age = age
37+ }
38+
39+ fun printMsg () {
40+ println (" Name is $name . Age is $age ." )
41+ }
42+ }
43+
44+ open class Animal (val species : String )
45+
46+ class Dog (species : String ) : Animal(species)
47+
48+ class Car (val make : String , val model : String = " Unknown" )
You can’t perform that action at this time.
0 commit comments