I've the following class. It has the code to connect to SAP in its constructor. There is an abstract method(the subclasses define the implementation) which I want to mock.
public abstract class BapiExecutor {
...
public BapiExecutor(final SapConnectionInfo connectionInfo)
throws java.lang.Exception {
if (!validConnectorData()) {
throw new IllegalArgumentException(
"Does not have valid data to connect to SAP");
}
initializeState(connectionInfo);
}
public abstract Object execute() throws Exception ;
....
}
The unit I want to test is :
I want to mock the call to execute()
method.
private String invokeBapiToAddAssociation(Map associationMap,
SapConnectionInfo connectionInfo) {
EidCcBapiExecutor executor = null;
String bapiExecutionResult = null;
try {
executor = new EidCcBapiExecutor(connectionInfo, associationMap);
bapiExecutionResult = (String) executor.execute();
} catch (Exception e) {
e.printStackTrace();
throw new CcGenericException(
"Exception occurred while invoking the EID-CC Association BAPI executor!",
e);
}
return bapiExecutionResult;
}
Any frameworks in Java that supports the mocking of parametrized constructors?
i just want to avoid connecting to SAP in the constructor.