mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Add action for nullable DB callables.
This commit is contained in:
@@ -25,7 +25,8 @@ public class DbExpectations extends Expectations {
|
|||||||
protected <R, E extends Exception> NullableDbCallable<R, E> withNullableDbCallable(
|
protected <R, E extends Exception> NullableDbCallable<R, E> withNullableDbCallable(
|
||||||
Transaction txn) {
|
Transaction txn) {
|
||||||
addParameterMatcher(any(NullableDbCallable.class));
|
addParameterMatcher(any(NullableDbCallable.class));
|
||||||
currentBuilder().setAction(new RunTransactionWithResultAction(txn));
|
currentBuilder().setAction(
|
||||||
|
new RunTransactionWithNullableResultAction(txn));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.briarproject.bramble.test;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.NullableDbCallable;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.hamcrest.Description;
|
||||||
|
import org.jmock.api.Action;
|
||||||
|
import org.jmock.api.Invocation;
|
||||||
|
|
||||||
|
public class RunTransactionWithNullableResultAction implements Action {
|
||||||
|
|
||||||
|
private final Transaction txn;
|
||||||
|
|
||||||
|
public RunTransactionWithNullableResultAction(Transaction txn) {
|
||||||
|
this.txn = txn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Invocation invocation) throws Throwable {
|
||||||
|
NullableDbCallable task =
|
||||||
|
(NullableDbCallable) invocation.getParameter(1);
|
||||||
|
return task.call(txn);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void describeTo(Description description) {
|
||||||
|
description.appendText("runs a task inside a database transaction");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user