I'm unable to mock the below local objects - env
, service
, creds
. These are classes from imported cloud foundry dependencies.
How do I write a test case covering all conditions for below Groovy
code using Spock
or Junit 4
without refactoring the code?
import io.pivotal.cfenv.core.cfEnv
import io.pivotal.cfenv.core.cfCredentials
import io.pivotal.cfenv.core.cfService
class Test {
public String getPropertyValue() {
CfEnv env = new CfEnv();
CfService service = new CfService();
String propName = "test-name";
try {
service = env.findServiceByName(propName);
} catch (Exception e) {
return null;
}
CfCredentials creds = new CfCredentials();
Map<String, Object> props = service.getMap();
return props.get("prop.name").toString();
}
}