TestEagleConfig is not a valid test case because it assumes that it can
initialize EagleConfigFactory, but when we execute multiple test cases,
this may not work as EagleConfigFactory may already be initialized before
this test case is executed. So setting "config.resource" will not have any
effect.

I suggest we remote TestEagleConfig, and also going forward we can need
refactor EagleConfigFactor to be not a singleton but use
com.typesafe.config.Config as constructor parameter.

Thanks
Edward

On Tue, Aug 16, 2016 at 4:26 AM, Chang Chen <[email protected]> wrote:

> 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
>

Reply via email to