Hi Guys
In the middle of writing UT for Eagle, we found it is difficult to mock
EagleConfigFactory, since it has static method. The current workaround is
introducing powermock, so that we can set manager to mock object , i.e.
Whitebox.setInternalState(EagleConfigFactory.class, "manager",
eagleConfigFactory);
This is OK in most cases, but TestEagleConfig.testInit could be failed,
because manager only initialized at first time and EagleConfigFactory's
Constructor is private:
private static EagleConfigFactory manager = new EagleConfigFactory();
EagleConfigFactory actually has two roles, one is factory and another is
configuration. I propose refactoring EagleConfigFactory and distinguish
these two roles:
public class EagleConfigImpl implements EagleConfig{
}
public class EagleConfigFactory {
public static EagleConfig load(){}
public static void reset(EagleConfig config){
if (config == null) {
//default
}else{
}
}
}
However doing so, we need call EagleConfigFactory.reset at the beginning of
eagle start.
Any ideas?
Thanks
Chang