mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Merge branch 'use-synchroniser-for-mock-tests' into 'master'
Use Synchroniser for all mock tests See merge request briar/briar!1550
This commit is contained in:
@@ -1,12 +1,17 @@
|
|||||||
package org.briarproject.bramble.test;
|
package org.briarproject.bramble.test;
|
||||||
|
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
|
import org.jmock.lib.concurrent.Synchroniser;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
|
||||||
public abstract class BrambleMockTestCase extends BrambleTestCase {
|
public abstract class BrambleMockTestCase extends BrambleTestCase {
|
||||||
|
|
||||||
protected final Mockery context = new Mockery();
|
protected final Mockery context = new Mockery();
|
||||||
|
|
||||||
|
public BrambleMockTestCase() {
|
||||||
|
context.setThreadingPolicy(new Synchroniser());
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void checkExpectations() {
|
public void checkExpectations() {
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.DbExpectations;
|
import org.briarproject.bramble.test.DbExpectations;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -53,9 +52,8 @@ import static org.junit.Assert.assertArrayEquals;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class ClientHelperImplTest extends BrambleTestCase {
|
public class ClientHelperImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
private final Mockery context = new Mockery();
|
|
||||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
private final MessageFactory messageFactory =
|
private final MessageFactory messageFactory =
|
||||||
context.mock(MessageFactory.class);
|
context.mock(MessageFactory.class);
|
||||||
@@ -100,7 +98,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
clientHelper.addLocalMessage(message, dictionary, shared);
|
clientHelper.addLocalMessage(message, dictionary, shared);
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -112,7 +109,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
clientHelper.createMessage(groupId, timestamp, list);
|
clientHelper.createMessage(groupId, timestamp, list);
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -127,7 +123,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
clientHelper.getMessageAsList(messageId);
|
clientHelper.getMessageAsList(messageId);
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -144,7 +139,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
|
|
||||||
assertEquals(dictionary,
|
assertEquals(dictionary,
|
||||||
clientHelper.getGroupMetadataAsDictionary(groupId));
|
clientHelper.getGroupMetadataAsDictionary(groupId));
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -161,7 +155,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
|
|
||||||
assertEquals(dictionary,
|
assertEquals(dictionary,
|
||||||
clientHelper.getMessageMetadataAsDictionary(messageId));
|
clientHelper.getMessageMetadataAsDictionary(messageId));
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -179,7 +172,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
assertEquals(map, clientHelper.getMessageMetadataAsDictionary(groupId));
|
assertEquals(map, clientHelper.getMessageMetadataAsDictionary(groupId));
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -204,7 +196,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
|
|
||||||
assertEquals(map,
|
assertEquals(map,
|
||||||
clientHelper.getMessageMetadataAsDictionary(groupId, query));
|
clientHelper.getMessageMetadataAsDictionary(groupId, query));
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -219,7 +210,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
clientHelper.mergeGroupMetadata(groupId, dictionary);
|
clientHelper.mergeGroupMetadata(groupId, dictionary);
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -234,7 +224,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
clientHelper.mergeMessageMetadata(messageId, dictionary);
|
clientHelper.mergeMessageMetadata(messageId, dictionary);
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -242,7 +231,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
byte[] bytes = expectToByteArray(list);
|
byte[] bytes = expectToByteArray(list);
|
||||||
|
|
||||||
assertArrayEquals(bytes, clientHelper.toByteArray(list));
|
assertArrayEquals(bytes, clientHelper.toByteArray(list));
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -250,7 +238,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
expectToList(true);
|
expectToList(true);
|
||||||
|
|
||||||
assertEquals(list, clientHelper.toList(getRandomBytes(123)));
|
assertEquals(list, clientHelper.toList(getRandomBytes(123)));
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -262,7 +249,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
fail();
|
fail();
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
// expected
|
// expected
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,7 +265,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
|
|
||||||
assertArrayEquals(signature,
|
assertArrayEquals(signature,
|
||||||
clientHelper.sign(label, list, privateKey));
|
clientHelper.sign(label, list, privateKey));
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -295,7 +280,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
clientHelper.verifySignature(signature, label, list, publicKey);
|
clientHelper.verifySignature(signature, label, list, publicKey);
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -315,7 +299,6 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
|||||||
fail();
|
fail();
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException e) {
|
||||||
// expected
|
// expected
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.briarproject.bramble.test.BrambleTestCase;
|
|||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.auto.Mock;
|
import org.jmock.auto.Mock;
|
||||||
import org.jmock.integration.junit4.JUnitRuleMockery;
|
import org.jmock.integration.junit4.JUnitRuleMockery;
|
||||||
|
import org.jmock.lib.concurrent.Synchroniser;
|
||||||
import org.jmock.lib.legacy.ClassImposteriser;
|
import org.jmock.lib.legacy.ClassImposteriser;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -35,6 +36,7 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
public JUnitRuleMockery context = new JUnitRuleMockery() {{
|
public JUnitRuleMockery context = new JUnitRuleMockery() {{
|
||||||
// So we can mock concrete classes like KeyAgreementTransport
|
// So we can mock concrete classes like KeyAgreementTransport
|
||||||
setImposteriser(ClassImposteriser.INSTANCE);
|
setImposteriser(ClassImposteriser.INSTANCE);
|
||||||
|
setThreadingPolicy(new Synchroniser());
|
||||||
}};
|
}};
|
||||||
|
|
||||||
private final PublicKey alicePubKey = getAgreementPublicKey();
|
private final PublicKey alicePubKey = getAgreementPublicKey();
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
|||||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
|
||||||
import org.jmock.lib.concurrent.Synchroniser;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -24,13 +22,10 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
|
|
||||||
public class PluginManagerImplTest extends BrambleTestCase {
|
public class PluginManagerImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartAndStop() throws Exception {
|
public void testStartAndStop() throws Exception {
|
||||||
Mockery context = new Mockery() {{
|
|
||||||
setThreadingPolicy(new Synchroniser());
|
|
||||||
}};
|
|
||||||
Executor ioExecutor = Executors.newSingleThreadExecutor();
|
Executor ioExecutor = Executors.newSingleThreadExecutor();
|
||||||
EventBus eventBus = context.mock(EventBus.class);
|
EventBus eventBus = context.mock(EventBus.class);
|
||||||
PluginConfig pluginConfig = context.mock(PluginConfig.class);
|
PluginConfig pluginConfig = context.mock(PluginConfig.class);
|
||||||
@@ -116,7 +111,5 @@ public class PluginManagerImplTest extends BrambleTestCase {
|
|||||||
// Two plugins should be started and stopped
|
// Two plugins should be started and stopped
|
||||||
p.startService();
|
p.startService();
|
||||||
p.stopService();
|
p.stopService();
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
package org.briarproject.bramble.transport;
|
package org.briarproject.bramble.transport;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.StreamDecrypter;
|
import org.briarproject.bramble.api.crypto.StreamDecrypter;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class StreamReaderImplTest extends BrambleTestCase {
|
public class StreamReaderImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyFramesAreSkipped() throws Exception {
|
public void testEmptyFramesAreSkipped() throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
||||||
@@ -30,13 +28,11 @@ public class StreamReaderImplTest extends BrambleTestCase {
|
|||||||
assertEquals(0, r.read()); // Read another byte
|
assertEquals(0, r.read()); // Read another byte
|
||||||
assertEquals(-1, r.read()); // Skip the second empty frame, reach EOF
|
assertEquals(-1, r.read()); // Skip the second empty frame, reach EOF
|
||||||
assertEquals(-1, r.read()); // Still at EOF
|
assertEquals(-1, r.read()); // Still at EOF
|
||||||
context.assertIsSatisfied();
|
|
||||||
r.close();
|
r.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyFramesAreSkippedWithBuffer() throws Exception {
|
public void testEmptyFramesAreSkippedWithBuffer() throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
||||||
@@ -56,13 +52,11 @@ public class StreamReaderImplTest extends BrambleTestCase {
|
|||||||
assertEquals(-1, r.read(buf));
|
assertEquals(-1, r.read(buf));
|
||||||
// Still at EOF
|
// Still at EOF
|
||||||
assertEquals(-1, r.read(buf));
|
assertEquals(-1, r.read(buf));
|
||||||
context.assertIsSatisfied();
|
|
||||||
r.close();
|
r.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleReadsPerFrame() throws Exception {
|
public void testMultipleReadsPerFrame() throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
||||||
@@ -78,13 +72,11 @@ public class StreamReaderImplTest extends BrambleTestCase {
|
|||||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf));
|
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf));
|
||||||
// Reach EOF
|
// Reach EOF
|
||||||
assertEquals(-1, r.read(buf, 0, buf.length));
|
assertEquals(-1, r.read(buf, 0, buf.length));
|
||||||
context.assertIsSatisfied();
|
|
||||||
r.close();
|
r.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleReadsPerFrameWithOffsets() throws Exception {
|
public void testMultipleReadsPerFrameWithOffsets() throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
||||||
@@ -102,7 +94,6 @@ public class StreamReaderImplTest extends BrambleTestCase {
|
|||||||
MAX_PAYLOAD_LENGTH / 2));
|
MAX_PAYLOAD_LENGTH / 2));
|
||||||
// Reach EOF
|
// Reach EOF
|
||||||
assertEquals(-1, r.read(buf, 0, buf.length));
|
assertEquals(-1, r.read(buf, 0, buf.length));
|
||||||
context.assertIsSatisfied();
|
|
||||||
r.close();
|
r.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
package org.briarproject.bramble.transport;
|
package org.briarproject.bramble.transport;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.StreamEncrypter;
|
import org.briarproject.bramble.api.crypto.StreamEncrypter;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class StreamWriterImplTest extends BrambleTestCase {
|
public class StreamWriterImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloseWithoutWritingWritesFinalFrame() throws Exception {
|
public void testCloseWithoutWritingWritesFinalFrame() throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Write an empty final frame
|
// Write an empty final frame
|
||||||
@@ -24,13 +22,11 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
|||||||
}});
|
}});
|
||||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||||
w.close();
|
w.close();
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlushWithoutBufferedDataWritesFrameAndFlushes()
|
public void testFlushWithoutBufferedDataWritesFrameAndFlushes()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -51,13 +47,11 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
|||||||
oneOf(encrypter).flush();
|
oneOf(encrypter).flush();
|
||||||
}});
|
}});
|
||||||
w.close();
|
w.close();
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlushWithBufferedDataWritesFrameAndFlushes()
|
public void testFlushWithBufferedDataWritesFrameAndFlushes()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -79,12 +73,10 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
|||||||
oneOf(encrypter).flush();
|
oneOf(encrypter).flush();
|
||||||
}});
|
}});
|
||||||
w.close();
|
w.close();
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleByteWritesWriteFullFrame() throws Exception {
|
public void testSingleByteWritesWriteFullFrame() throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -103,12 +95,10 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
|||||||
oneOf(encrypter).flush();
|
oneOf(encrypter).flush();
|
||||||
}});
|
}});
|
||||||
w.close();
|
w.close();
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiByteWritesWriteFullFrames() throws Exception {
|
public void testMultiByteWritesWriteFullFrames() throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -134,12 +124,10 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
|||||||
oneOf(encrypter).flush();
|
oneOf(encrypter).flush();
|
||||||
}});
|
}});
|
||||||
w.close();
|
w.close();
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLargeMultiByteWriteWritesFullFrames() throws Exception {
|
public void testLargeMultiByteWriteWritesFullFrames() throws Exception {
|
||||||
Mockery context = new Mockery();
|
|
||||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -157,6 +145,5 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
|||||||
w.write(b);
|
w.write(b);
|
||||||
// There should be one byte left in the buffer
|
// There should be one byte left in the buffer
|
||||||
w.close();
|
w.close();
|
||||||
context.assertIsSatisfied();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.briarproject.bramble.api.identity.LocalAuthor;
|
|||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
||||||
import org.briarproject.briar.api.blog.BlogFactory;
|
import org.briarproject.briar.api.blog.BlogFactory;
|
||||||
@@ -28,9 +29,7 @@ import org.briarproject.briar.api.blog.BlogPostHeader;
|
|||||||
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
|
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
import org.briarproject.briar.test.BriarTestCase;
|
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_SHARE;
|
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_SHARE;
|
||||||
@@ -65,9 +64,8 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class BlogManagerImplTest extends BriarTestCase {
|
public class BlogManagerImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
private final Mockery context = new Mockery();
|
|
||||||
private final BlogManagerImpl blogManager;
|
private final BlogManagerImpl blogManager;
|
||||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
private final AuthorManager authorManager =
|
private final AuthorManager authorManager =
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ import org.briarproject.bramble.api.sync.MessageFactory;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.system.SystemClock;
|
import org.briarproject.bramble.system.SystemClock;
|
||||||
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
import org.briarproject.briar.api.blog.BlogFactory;
|
import org.briarproject.briar.api.blog.BlogFactory;
|
||||||
import org.briarproject.briar.test.BriarTestCase;
|
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -47,9 +46,8 @@ import static org.briarproject.briar.api.blog.MessageType.WRAPPED_POST;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
public class BlogPostValidatorTest extends BriarTestCase {
|
public class BlogPostValidatorTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
private final Mockery context = new Mockery();
|
|
||||||
private final Blog blog, rssBlog;
|
private final Blog blog, rssBlog;
|
||||||
private final BdfList authorList;
|
private final BdfList authorList;
|
||||||
private final byte[] descriptor;
|
private final byte[] descriptor;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.feed;
|
|||||||
import org.briarproject.bramble.api.identity.Identity;
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.test.TestDatabaseConfigModule;
|
import org.briarproject.bramble.test.TestDatabaseConfigModule;
|
||||||
import org.briarproject.bramble.test.TestUtils;
|
import org.briarproject.bramble.test.TestUtils;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
@@ -10,7 +11,6 @@ import org.briarproject.briar.api.blog.BlogManager;
|
|||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||||
import org.briarproject.briar.api.feed.Feed;
|
import org.briarproject.briar.api.feed.Feed;
|
||||||
import org.briarproject.briar.api.feed.FeedManager;
|
import org.briarproject.briar.api.feed.FeedManager;
|
||||||
import org.briarproject.briar.test.BriarTestCase;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class FeedManagerIntegrationTest extends BriarTestCase {
|
public class FeedManagerIntegrationTest extends BrambleTestCase {
|
||||||
|
|
||||||
private LifecycleManager lifecycleManager;
|
private LifecycleManager lifecycleManager;
|
||||||
private FeedManager feedManager;
|
private FeedManager feedManager;
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
import org.briarproject.briar.api.forum.ForumPost;
|
import org.briarproject.briar.api.forum.ForumPost;
|
||||||
import org.briarproject.briar.api.forum.ForumPostFactory;
|
import org.briarproject.briar.api.forum.ForumPostFactory;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||||
import org.briarproject.briar.test.BriarTestCase;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@@ -41,7 +41,7 @@ import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVAT
|
|||||||
import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT;
|
import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class MessageSizeIntegrationTest extends BriarTestCase {
|
public class MessageSizeIntegrationTest extends BrambleTestCase {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CryptoComponent crypto;
|
CryptoComponent crypto;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.sync.event.MessageStateChangedEvent;
|
import org.briarproject.bramble.api.sync.event.MessageStateChangedEvent;
|
||||||
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
|
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
|
||||||
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.test.TestDatabaseConfigModule;
|
import org.briarproject.bramble.test.TestDatabaseConfigModule;
|
||||||
import org.briarproject.bramble.test.TestTransportConnectionReader;
|
import org.briarproject.bramble.test.TestTransportConnectionReader;
|
||||||
import org.briarproject.bramble.test.TestTransportConnectionWriter;
|
import org.briarproject.bramble.test.TestTransportConnectionWriter;
|
||||||
@@ -23,7 +24,6 @@ import org.briarproject.briar.api.messaging.PrivateMessage;
|
|||||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||||
import org.briarproject.briar.api.messaging.event.AttachmentReceivedEvent;
|
import org.briarproject.briar.api.messaging.event.AttachmentReceivedEvent;
|
||||||
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
|
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
|
||||||
import org.briarproject.briar.test.BriarTestCase;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -44,7 +44,7 @@ import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
|
|||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
public class SimplexMessagingIntegrationTest extends BrambleTestCase {
|
||||||
|
|
||||||
private static final int TIMEOUT_MS = 5_000;
|
private static final int TIMEOUT_MS = 5_000;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package org.briarproject.briar.test;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
|
||||||
|
|
||||||
public abstract class BriarTestCase extends BrambleTestCase {
|
|
||||||
|
|
||||||
public BriarTestCase() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user