I have a requirement in which I have to invoke a private method of an abstract class.
Let's say the abstract class looks like below:-
public abstract class Base {
protected abstract String getName();
private String getHi(String v) {
return "Hi " + v;
}
}
Can some let me know is there a way I can call getHi
(may be via Reflection
or some other means) so that I can test it out? I am using Junit 4.12
and Java 8
I have gone through this question but here the methods are not private in the abstract class.
I have also gone through this question even this one does not talk about private method in abstract class.
I am not asking here whether we should test the private method or not or what is the best strategy for testing private methods. There are lot of resources available in the web regarding this. I am just trying to ask how should we invoke a private method of an abstract class in java.