diff --git a/bramble-core/src/test/java/org/briarproject/bramble/sync/SimplexOutgoingSessionTest.java b/bramble-core/src/test/java/org/briarproject/bramble/sync/SimplexOutgoingSessionTest.java index 580b97006445fe958bfac8bb717ca24c5d0ea0b0..4aa5cd36b26f319220c3c2b38dfab52deecc4128 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/sync/SimplexOutgoingSessionTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/sync/SimplexOutgoingSessionTest.java @@ -8,11 +8,9 @@ import org.briarproject.bramble.api.sync.Ack; import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.SyncRecordWriter; import org.briarproject.bramble.api.transport.StreamWriter; -import org.briarproject.bramble.test.BrambleTestCase; +import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.ImmediateExecutor; -import org.briarproject.bramble.test.TestUtils; import org.jmock.Expectations; -import org.jmock.Mockery; import org.junit.Test; import java.util.Arrays; @@ -20,36 +18,26 @@ import java.util.Collections; import java.util.concurrent.Executor; import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS; +import static org.briarproject.bramble.test.TestUtils.getRandomId; -// TODO: Convert to BrambleMockTestCase -public class SimplexOutgoingSessionTest extends BrambleTestCase { +public class SimplexOutgoingSessionTest extends BrambleMockTestCase { - private final Mockery context; - private final DatabaseComponent db; - private final Executor dbExecutor; - private final EventBus eventBus; - private final ContactId contactId; - private final MessageId messageId; - private final int maxLatency; - private final StreamWriter streamWriter; - private final SyncRecordWriter recordWriter; + private static final int MAX_LATENCY = Integer.MAX_VALUE; - public SimplexOutgoingSessionTest() { - context = new Mockery(); - db = context.mock(DatabaseComponent.class); - dbExecutor = new ImmediateExecutor(); - eventBus = context.mock(EventBus.class); - streamWriter = context.mock(StreamWriter.class); - recordWriter = context.mock(SyncRecordWriter.class); - contactId = new ContactId(234); - messageId = new MessageId(TestUtils.getRandomId()); - maxLatency = Integer.MAX_VALUE; - } + private final DatabaseComponent db = context.mock(DatabaseComponent.class); + private final EventBus eventBus = context.mock(EventBus.class); + private final StreamWriter streamWriter = context.mock(StreamWriter.class); + private final SyncRecordWriter recordWriter = + context.mock(SyncRecordWriter.class); + + private final Executor dbExecutor = new ImmediateExecutor(); + private final ContactId contactId = new ContactId(234); + private final MessageId messageId = new MessageId(getRandomId()); @Test public void testNothingToSend() throws Exception { SimplexOutgoingSession session = new SimplexOutgoingSession(db, - dbExecutor, eventBus, contactId, maxLatency, streamWriter, + dbExecutor, eventBus, contactId, MAX_LATENCY, streamWriter, recordWriter); Transaction noAckTxn = new Transaction(null, false); Transaction noMsgTxn = new Transaction(null, false); @@ -68,7 +56,7 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase { oneOf(db).startTransaction(false); will(returnValue(noMsgTxn)); oneOf(db).generateBatch(with(noMsgTxn), with(contactId), - with(any(int.class)), with(maxLatency)); + with(any(int.class)), with(MAX_LATENCY)); will(returnValue(null)); oneOf(db).commitTransaction(noMsgTxn); oneOf(db).endTransaction(noMsgTxn); @@ -79,8 +67,6 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase { }}); session.run(); - - context.assertIsSatisfied(); } @Test @@ -88,7 +74,7 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase { Ack ack = new Ack(Collections.singletonList(messageId)); byte[] raw = new byte[1234]; SimplexOutgoingSession session = new SimplexOutgoingSession(db, - dbExecutor, eventBus, contactId, maxLatency, streamWriter, + dbExecutor, eventBus, contactId, MAX_LATENCY, streamWriter, recordWriter); Transaction ackTxn = new Transaction(null, false); Transaction noAckTxn = new Transaction(null, false); @@ -110,7 +96,7 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase { oneOf(db).startTransaction(false); will(returnValue(msgTxn)); oneOf(db).generateBatch(with(msgTxn), with(contactId), - with(any(int.class)), with(maxLatency)); + with(any(int.class)), with(MAX_LATENCY)); will(returnValue(Arrays.asList(raw))); oneOf(db).commitTransaction(msgTxn); oneOf(db).endTransaction(msgTxn); @@ -126,7 +112,7 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase { oneOf(db).startTransaction(false); will(returnValue(noMsgTxn)); oneOf(db).generateBatch(with(noMsgTxn), with(contactId), - with(any(int.class)), with(maxLatency)); + with(any(int.class)), with(MAX_LATENCY)); will(returnValue(null)); oneOf(db).commitTransaction(noMsgTxn); oneOf(db).endTransaction(noMsgTxn); @@ -137,7 +123,5 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase { }}); session.run(); - - context.assertIsSatisfied(); } }