Improve RegistryToolEnvironment setup behavior

Here's an alternate approach that I think simplifies the existing
code quite a bit.  Now instead of doing:

  RegistryToolEnvironment.loadFromArgs(args);
  RegistryToolEnvironment.get().setup();

You just do one chained call:

  RegistryToolEnvironment.parseFromArgs(args).setup();

or call setup() on a known environment constant:

  RegistryToolEnvironment.ALPHA.setup();

This avoids having loadFromArgs() implicitly set the active env
(but *not* do setup) and then having setup() *not* set the active
env, both of which were confusing.  Now parseFromArgs() is only
responsible for parsing from args, and setup() both sets the env
as the active one and does the environment variable setup (which
also ensures that the RegistryToolEnvironment.instance field
doesn't get out of sync with the RegistryEnvironment value).

In addition, this CL adds a runCommandInEnvironment() method to
CommandTestCase and ensures that the UNITTEST environment is always
set before constructing the default command instance.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117492978
This commit is contained in:
nickfelt 2016-03-17 15:37:58 -07:00 committed by Justine Tunney
parent 14c794aa45
commit 5174c1c63f
7 changed files with 60 additions and 36 deletions

View file

@ -50,8 +50,7 @@ public class RegistryToolTest {
@Before
public void init() {
RegistryToolEnvironment.loadFromArgs(new String[] { "-e", "alpha" });
RegistryToolEnvironment.get().setup();
RegistryToolEnvironment.UNITTEST.setup();
}
@Test