Creating unit test of kotlin logic that checks for a specific constraint name
val exception = assertThrows {
dao.addEntity(dbEntity1SameName)
}
val psqlException = exception.cause as? PSQLException
val constraintName = psqlException?.serverErrorMessage?.constraint
val violatingValues = psqlException?.serverErrorMessage?.detail
val rootCauseMessage = exception.rootCause?.message
the constraintName value has the specific text, how can I mock a DuplicateKeyException accordingly?