In this case, you need to use partial bullying so that JMockit does not override everything in the System class. The following test will pass:
@Test
public void mockSystemGetenvMethod()
{
new Expectations()
{
@Mocked("getenv") System mockedSystem;
{
System.getenv("envVar"); returns(".");
}
};
assertEquals(".", System.getenv("envVar"));
}
, , JRE. 0.992 0.993.