[#3595] Add MockResult<init>(Record data) convenience constructor
This commit is contained in:
parent
e46450c793
commit
587155ab1f
@ -40,9 +40,15 @@
|
||||
*/
|
||||
package org.jooq.tools.jdbc;
|
||||
|
||||
import static org.jooq.impl.DSL.using;
|
||||
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.jooq.AttachableInternal;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.impl.DefaultConfiguration;
|
||||
|
||||
/**
|
||||
* A mock result.
|
||||
@ -85,6 +91,17 @@ public class MockResult {
|
||||
*/
|
||||
public final Result<?> data;
|
||||
|
||||
/**
|
||||
* Create a new <code>MockResult</code>.
|
||||
* <p>
|
||||
* This is a convenience constructor creating a <code>MockResult</code> with exactly one record.
|
||||
*
|
||||
* @param data The single record in this result.
|
||||
*/
|
||||
public MockResult(Record data) {
|
||||
this(1, result(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new <code>MockResult</code>.
|
||||
*
|
||||
@ -96,6 +113,17 @@ public class MockResult {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
private static final Result<?> result(Record data) {
|
||||
Configuration configuration = data instanceof AttachableInternal
|
||||
? ((AttachableInternal) data).configuration()
|
||||
: new DefaultConfiguration();
|
||||
|
||||
Result<Record> result = using(configuration).newResult(data.fields());
|
||||
result.add(data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (data != null) ? data.toString() : ("" + rows);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user