Basically I'm trying to mock a static class for unit testing.
Example:
class Library {
public static boolean isActivated() {
return false;
}
}
class Test {
public static void main(String[] args) {
// some magic
if (Library.isActivated()) {
System.out.println("'some magic' works!");
} else {
System.out.println("fail");
}
}
}
What would some magic
need to be, to make Library.isActivated()
return true
.
Is there some special way to do this without changing the source code of Library
?
As far as I know this is not possible in java but I'm not very familiar with Reflection I thought this might be possible with it.