Commit 92dea21c authored by akwizgran's avatar akwizgran

Run commit actions in unit tests.

parent 82a52638
......@@ -7,7 +7,7 @@ import org.jmock.api.Invocation;
public class RunAction implements Action {
@Override
public Object invoke(Invocation invocation) throws Throwable {
public Object invoke(Invocation invocation) {
Runnable task = (Runnable) invocation.getParameter(0);
task.run();
return null;
......
package org.briarproject.bramble.test;
import org.briarproject.bramble.api.db.CommitAction;
import org.briarproject.bramble.api.db.DbRunnable;
import org.briarproject.bramble.api.db.TaskAction;
import org.briarproject.bramble.api.db.Transaction;
import org.hamcrest.Description;
import org.jmock.api.Action;
import org.jmock.api.Invocation;
public class RunTransactionAction implements Action {
class RunTransactionAction implements Action {
private final Transaction txn;
@SuppressWarnings("WeakerAccess")
public RunTransactionAction(Transaction txn) {
RunTransactionAction(Transaction txn) {
this.txn = txn;
}
......@@ -19,6 +20,10 @@ public class RunTransactionAction implements Action {
public Object invoke(Invocation invocation) throws Throwable {
DbRunnable task = (DbRunnable) invocation.getParameter(1);
task.run(txn);
for (CommitAction action : txn.getActions()) {
if (action instanceof TaskAction)
((TaskAction) action).getTask().run();
}
return null;
}
......@@ -26,5 +31,4 @@ public class RunTransactionAction implements Action {
public void describeTo(Description description) {
description.appendText("runs a task inside a database transaction");
}
}
package org.briarproject.bramble.test;
import org.briarproject.bramble.api.db.CommitAction;
import org.briarproject.bramble.api.db.NullableDbCallable;
import org.briarproject.bramble.api.db.TaskAction;
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 {
class RunTransactionWithNullableResultAction implements Action {
private final Transaction txn;
public RunTransactionWithNullableResultAction(Transaction txn) {
RunTransactionWithNullableResultAction(Transaction txn) {
this.txn = txn;
}
......@@ -18,7 +20,12 @@ public class RunTransactionWithNullableResultAction implements Action {
public Object invoke(Invocation invocation) throws Throwable {
NullableDbCallable task =
(NullableDbCallable) invocation.getParameter(1);
return task.call(txn);
Object result = task.call(txn);
for (CommitAction action : txn.getActions()) {
if (action instanceof TaskAction)
((TaskAction) action).getTask().run();
}
return result;
}
@Override
......
package org.briarproject.bramble.test;
import org.briarproject.bramble.api.db.CommitAction;
import org.briarproject.bramble.api.db.DbCallable;
import org.briarproject.bramble.api.db.TaskAction;
import org.briarproject.bramble.api.db.Transaction;
import org.hamcrest.Description;
import org.jmock.api.Action;
import org.jmock.api.Invocation;
public class RunTransactionWithResultAction implements Action {
class RunTransactionWithResultAction implements Action {
private final Transaction txn;
public RunTransactionWithResultAction(Transaction txn) {
RunTransactionWithResultAction(Transaction txn) {
this.txn = txn;
}
@Override
public Object invoke(Invocation invocation) throws Throwable {
DbCallable task = (DbCallable) invocation.getParameter(1);
return task.call(txn);
Object result = task.call(txn);
for (CommitAction action : txn.getActions()) {
if (action instanceof TaskAction)
((TaskAction) action).getTask().run();
}
return result;
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment