I have a class that looks like this:
public class MyClass {
private final SimpleJdbcCall simpleJdbcCall;
public MyClass(final DataSource dataSource) {
this(new JdbcTemplate(dataSource));
}
public MyClass(final JdbcTemplate template) {
simpleJdbcCall = new SimpleJdbcCall(template)
.withoutProcedureColumnMetaDataAccess()
.withCatalogName("MY_ORACLE_PACKAGE")
.withFunctionName("GET_VALUE")
.withReturnValue()
.declareParameters(
new SqlOutParameter("RESULT", Types.VARCHAR))
.declareParameters(
new SqlParameter("P_VAR1_NAME", Types.VARCHAR))
.declareParameters(
new SqlParameter("P_VAR2_NAME", Types.VARCHAR))
.useInParameterNames("P_VAR1_NAME", "P_VAR2_NAME");
}
private String getValue(final String input) {
final SqlParameterSource params = new MapSqlParameterSource()
.addValue("P_VAR1_NAME", input, Types.VARCHAR)
.addValue("P_VAR2_NAME", null, Types.VARCHAR);
return simpleJdbcCall.executeFunction(String.class, params);
}
}
It works as expected, but I want to write a unit test for it, and it drives me crazy. I tried to taunt JdbcTemplate (Mockito), but this leads to mocking connections, metadata, etc., and I am lost in the time when called statement factories are included in the game.
I think I could write it so that SimpleJdbcCall is passed as a parameter to the new constructor and then mock it, but it seems hacky. I would prefer that the test does not affect the class if it does not improve it.
API SimpleJdbcCall. SQL , SQL Java, , 1000 . - ?