Hallo zusammen ich habe mal eine generelle Frage :
Ich schreibe ein größere Anwendung und bin dabei in allen öffentlichen und teils auch in den privaten Methoden eine Parameterprüfung zu entwicklen.
Das sieht dann so aus
Da ich für jede Funktion auch einen Unit Test schreibe, bläht es den Code enorm auf. nun meine Frage ist es überhaupt sinnvoll, jeden Parameter gegen einen Null - Check zu prüfen oder einfach dann mit einem default wert weitermachen - wenn es sinnvoll ist?
Vielen Dank für eure Hilfe
Ich schreibe ein größere Anwendung und bin dabei in allen öffentlichen und teils auch in den privaten Methoden eine Parameterprüfung zu entwicklen.
Das sieht dann so aus
Java:
// throw an exception if the text is empty or null
if (url == null || url.isEmpty()) {
throw new WebContentReaderException("can't parse the text, because the text parameter is empty or null");
}
// throw an exception if the patternList is null or empty
if (patternList == null || patternList.isEmpty()) {
throw new WebContentReaderException("can't parse the text, because the text parameter is empty or null");
}
// throw an exception if the matcherGroupIndex < 0
if (matcherGroupIndex < 0) {
throw new WebContentReaderException("can't parse the text, because the text parameter is empty or null");
}
Da ich für jede Funktion auch einen Unit Test schreibe, bläht es den Code enorm auf. nun meine Frage ist es überhaupt sinnvoll, jeden Parameter gegen einen Null - Check zu prüfen oder einfach dann mit einem default wert weitermachen - wenn es sinnvoll ist?
Vielen Dank für eure Hilfe
Zuletzt bearbeitet von einem Moderator: