Skip to content

Commit 9345a00

Browse files
naoussinappy29
andauthored
added unit test (#1152)
Co-authored-by: nappy29 <[email protected]>
1 parent 7d86f04 commit 9345a00

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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")

0 commit comments

Comments
 (0)