Reputation: 5195
I have an issue using jOOQ's MockDataProvider
to mock a SQL JOIN in a unit test.
The JOIN implemented with jOOQ selects a single column containing UUIDs. Thus the result type is Result<Record1<UUID>>
. In the associated unit test I would like to mock this result using the MockDataProvider
, but I can't find a proper way to initialize the Result
, as I can't find a way to create a table like object I could pass to the newResult
method. I know that there are some table
methods in DSL
, but the signatures just seem to be wrong for my use case.
Also as the unit test is not runnable at this point, I'm not sure that the way I create the UUID field is correct.
This is my code:
private class MyProvider implements MockDataProvider {
@Override
public MockResult[] execute(final MockExecuteContext ctx) throws SQLException {
final MockResult[] mockResults = new MockResult[1];
final DSLContext db = DSL.using(SQLDialect.POSTGRES);
final Result<Record1<UUID>> result = db.newResult(<some table object here>);
final Field<UUID> uuidField = DSL.fieldByName(UUID.class, "uuid");
final Record1<UUID> record = db.newRecord(uuidField);
record.setValue(uuidField, ID);
result.add(record);
mockResults[0] = new MockResult(1, result);
return mockResults;
}
}
Upvotes: 1
Views: 1422
Reputation: 221115
I suspect that this is essentially the same question as the one on the jOOQ User Group here:
https://groups.google.com/forum/#!topic/jooq-user/h4pfIHjmBpo
In summary, there is a method that is going to be added to jOOQ 3.4 (with issue #3139), to help you create such Result
objects for arbitrary Record
types. In the mean time (before jOOQ 3.4 is released), you will have to resort to creating a new org.jooq.impl.ResultImpl
via reflection.
Upvotes: 1