java - How can I test a final class with private constructor? -
how can test class (see code below)?
public final class { public static final string first = "1st"; public static final string second = "2nd"; private a() { // nop } }
for coverage tools constructor isn't covered tests. tests on this:
assertequals(a.first, "1st"); assertequals(a.second, "2nd");
how can test class?
upd
this code solved problem.
@test public void magic() throws nosuchmethodexception, illegalaccessexception, invocationtargetexception, instantiationexception { constructor<a> constructor = a.class.getdeclaredconstructor(); constructor.setaccessible(true); instance = constructor.newinstance(); assertnotnull(instance); }
yes, agree isn't best solution. works :)
reflection way go: how test class has private methods, fields or inner classes?
by way, possibly duplicate of question in link provided.
alternatively, create wrapper method protected
forwards calls private
method?
Comments
Post a Comment