This change makes it easier to test components using CfEnv to parse a given VCAP_SERVICES string.
As can be seen in CfEnv's tests, it is possible to mock System.getenv with JMockit, but patching globally scoped objects is quite invasive and also requires configuring a Java agent.
This change adds a second constructor to CfEnv, so that the VCAP_SERVICES value can simply be passed in.
A Spring Configuration class like the following...
@Configuration
class FooConfiguration {
public FooConfiguration(Environment environment) {
this.environment = environment;
}
@Bean
public Foo foo() {
CfEnv cfEnv = new CfEnv(environment.get("VCAP_APPLICATION"), environment.get("VCAP_SERVICES"));
...
}
}
...can then be easily tested using MockEnvironment.
This change makes it easier to test components using CfEnv to parse a given VCAP_SERVICES string.
As can be seen in CfEnv's tests, it is possible to mock
System.getenv
with JMockit, but patching globally scoped objects is quite invasive and also requires configuring a Java agent.This change adds a second constructor to CfEnv, so that the VCAP_SERVICES value can simply be passed in.
A Spring Configuration class like the following...
...can then be easily tested using
MockEnvironment
.