Well, you could easily mock the enum, as follows:
new MockUp<DatacenterEnum>() {
@Mock DatacenterEnum compareLocation() { return DatacenterEnum.LVS; }
};
However, because the JVM can only perform static initialization once for a given class/enum, the test would only work if the enum hadn't yet been loaded and initialized. So, a more robust test would be the following.
@Test
public void whenDatacenterIsNotCORPThenLocalPookStringShouldIncludeEnumName() {
new MockUp<TestUtils>() {
@Mock String getEnvironmentName() { return "production"; }
};
DatacenterEnum notCORP = DatacenterEnum.LVS;
String ss = Deencapsulation.invoke(notCORP, "toLocalPookString");
assertTrue(ss.toUpperCase().endsWith(notCORP.name()));
}
This works, but note that writing separate tests for private
methods is generally considered bad form. Ideally, tests should call public methods which would indirectly exercise the private ones. In this particular case, however, there is no such public method, so I guess it's acceptable.