Hi!

I've been trying to write a mocked test that "proves" the correctness of a 
query.

The query looks like this:

dslContext.select(TBL_TASK.STATE) //
        .from(TBL_TASK) //
        .where(TBL_TASK.ID.eq(taskId)) //
        .fetchOne(TBL_TASK.STATE);


And the test looks like this:

int taskState = 5;
int taskId = 8;

MockDataProvider provider = context -> {
    DSLContext create = DSL.using(SQLDialect.MYSQL);
    MockResult[] mock = new MockResult[1];

    Result<Record1<Integer>> result = create.newResult(TBL_TASK.STATE);
    result.add(create.newRecord(TBL_TASK.STATE).values(taskState));
    mock[0] = new MockResult(1, result);
    return mock;
};

Connection connection = new MockConnection(provider);
DSLContext create = DSL.using(connection, SQLDialect.MYSQL);
Assert.assertEquals(taskState, getTaskState(create, taskId));



This seems to work fine when you try for example try to 
"fetchOne(TBL_TASK.ID)" or try to "select(TBL_TASK.ID)"

But this:

dslContext.select(TBL_TASK.ID) //
        .from(TBL_TASK) //
        .where(TBL_TASK.ID.eq(taskId)) //
        .fetchOne(TBL_TASK.ID);


Also works fine for some reason, even though the mock returns a record 
containing a state-field? Maybe I'm doing something wrong or have the wrong 
expectations about how mocking works, but it looks like the 
fetchOne-function doesn't care about the field name?

Like I said, the test can prove that the query itself is written wrong 
(selecting state but fetching id), but it can't prove that you aren't 
trying to correctly access a completely different column (selecting and 
fetching id-column when mock returns state-column).

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to