vendredi 7 décembre 2018

Test Config class with multiple private final fields

How would you suggest to "fix" this class for better testing?

public class Config {
    private final ComplexA complexA;
    private final ComplexB complexB;
    (...)

    Config(String[] args) {
         complexA = privateMethodCalculatesA(args);
         complexB = privateMethodCalculatesB(args);
         (...)
    }
}

Now, all methods that calculate complexA/B/... are intended to fail-fast if user inserts non-existing or wrong parameters with a System.exit. The issue here is that Config becomes mangled with methods that should be tested in isolation.

Nonetheless same methods should not be publicly exposed and result should be cached as calculation may be expensive.

Just hit the bullet and declare said methods static protected and test them in isolation?

What would be the proper way to do this?

Aucun commentaire:

Enregistrer un commentaire