Emma flags inaccessible private constructor as untested
Brought to you by:
vlad_r
Some people consider it a good practice, when you have
a utility class made only of static methods, to create
a private empty constructor to prevent people from
needlessly instantiating it. Checkstyle for instance
has a check for it.
The constructor being private, it is never run through
by unit tests, and Emma ends up flagging the
constructor as not tested. In my view, that is "not
testable" code, and not "untested" code, so it should
not be flagged.
Logged In: YES
user_id=1610582
Originator: NO
If anything Emma should flag if an empty private constructor *is* called.
BTW: I have seen this unfortunately.
public class MyUtilityClass {
// DO NOT CALL THIS. (They actually explained why the private constructor has been added, and then called it anyway)
private MyUtilityClass() {
}
public static int square(int num) {
return num * num;
}
public static class MyInner {
public static int cube(int num) {
return new MyUtilityClass().square(num);
}
}
}