jeudi 28 juillet 2016

Test a method by changing final static variables

I have a protected Method which looks as follows.It uses final static variables from a Constants.java file.

class A {
    protected Configuration connectConfig() {
           ConfigDescriptor desc = new ConfigDescriptor.Builder().project(Constants.REMOTE_CONFIG_PROJECT_NAME)
            .name(Constants.REMOTE_CONFIG_PROJECT_CONFIG_NAME).version(Constants.REMOTE_CONFIG_PROJECT_VERSION)
            .build();

    return ConfigProvider.of(desc, getClass().getClassLoader());
    }

  public boolean process() {
      Configuration config = connectConfig();
      if(config == null) {
          return false;
      }
  }
}

Now I want to unit test this method process for the remote config to fail.

If I just test process() method it will pass since the Constants.java has proper values to connect. For testing I want to change these values so that remote config returns null;

Note : We don't want to use Mockito to mock the values.

Aucun commentaire:

Enregistrer un commentaire