Testing custom exceptions in Kotlin with JUnit
I have the following class
data class CarDefects(
private val _carModel: CarModel,
private val _affectedYearsOfIssue: List,
private val _defectCode: String
) {
init {
validateDefectCode(_defectCode)
}
}
Validating function
fun validateDefectCode(defectCode: String) {
val pattern = Pattern.compile("^[a-zA-Z0-9-]*\$")
val m = pattern.matcher(defectCode)
if (defectCode.length !in 4..4) {
throw InvalidDefectCodeException(defectCode, "Defect code...