Minimise use of message constructor.

This commit is contained in:
akwizgran
2018-08-24 11:27:53 +01:00
parent d4a4351786
commit 27a169c6e2
18 changed files with 283 additions and 359 deletions

View File

@@ -32,10 +32,9 @@ import org.junit.Test;
import static org.briarproject.bramble.api.identity.Author.Status.NONE;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
@@ -75,9 +74,9 @@ public class BlogManagerImplTest extends BriarTestCase {
private final LocalAuthor localAuthor1, localAuthor2, rssLocalAuthor;
private final BdfList authorList1, authorList2, rssAuthorList;
private final Blog blog1, blog2, rssBlog;
private final long timestamp, timeReceived;
private final MessageId messageId, rssMessageId;
private final Message message, rssMessage;
private final MessageId messageId, rssMessageId;
private final long timestamp, timeReceived;
private final String comment;
public BlogManagerImplTest() {
@@ -94,14 +93,12 @@ public class BlogManagerImplTest extends BriarTestCase {
blog1 = createBlog(localAuthor1, false);
blog2 = createBlog(localAuthor2, false);
rssBlog = createBlog(rssLocalAuthor, true);
timestamp = System.currentTimeMillis();
message = getMessage(blog1.getId());
rssMessage = getMessage(rssBlog.getId());
messageId = message.getId();
rssMessageId = rssMessage.getId();
timestamp = message.getTimestamp();
timeReceived = timestamp + 1;
messageId = new MessageId(getRandomId());
rssMessageId = new MessageId(getRandomId());
message = new Message(messageId, blog1.getId(), timestamp,
getRandomBytes(MAX_MESSAGE_LENGTH));
rssMessage = new Message(rssMessageId, rssBlog.getId(), timestamp,
getRandomBytes(MAX_MESSAGE_LENGTH));
comment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
}
@@ -372,9 +369,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
MessageId commentId = new MessageId(getRandomId());
Message commentMsg = new Message(commentId, blog1.getId(),
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
Message commentMsg = getMessage(blog1.getId());
MessageId commentId = commentMsg.getId();
BdfDictionary commentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, comment),
@@ -457,9 +453,8 @@ public class BlogManagerImplTest extends BriarTestCase {
// The post was originally posted to blog 1, then reblogged to
// blog 2 with a comment
BdfList originalPostBody = BdfList.of("originalPostBody");
MessageId wrappedPostId = new MessageId(getRandomId());
Message wrappedPostMsg = new Message(wrappedPostId, blog2.getId(),
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
Message wrappedPostMsg = getMessage(blog2.getId());
MessageId wrappedPostId = wrappedPostMsg.getId();
BdfDictionary wrappedPostMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, false),
@@ -468,9 +463,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
MessageId commentId = new MessageId(getRandomId());
Message commentMsg = new Message(commentId, blog2.getId(),
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
Message commentMsg = getMessage(blog2.getId());
MessageId commentId = commentMsg.getId();
BdfDictionary commentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, comment),
@@ -568,9 +562,8 @@ public class BlogManagerImplTest extends BriarTestCase {
// The post was originally posted to the RSS blog, then reblogged to
// blog 1 with a comment
BdfList originalPostBody = BdfList.of("originalPostBody");
MessageId wrappedPostId = new MessageId(getRandomId());
Message wrappedPostMsg = new Message(wrappedPostId, blog1.getId(),
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
Message wrappedPostMsg = getMessage(blog1.getId());
MessageId wrappedPostId = wrappedPostMsg.getId();
BdfDictionary wrappedPostMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, true),
@@ -579,9 +572,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
MessageId commentId = new MessageId(getRandomId());
Message commentMsg = new Message(commentId, blog1.getId(),
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
Message commentMsg = getMessage(blog1.getId());
MessageId commentId = commentMsg.getId();
BdfDictionary commentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, comment),
@@ -681,9 +673,8 @@ public class BlogManagerImplTest extends BriarTestCase {
MessageId originalCommentId = new MessageId(getRandomId());
BdfList originalCommentBody = BdfList.of("originalCommentBody");
// The post and comment were reblogged to blog 2 with another comment
MessageId rewrappedPostId = new MessageId(getRandomId());
Message rewrappedPostMsg = new Message(rewrappedPostId,
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
Message rewrappedPostMsg = getMessage(blog2.getId());
MessageId rewrappedPostId = rewrappedPostMsg.getId();
BdfDictionary rewrappedPostMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, true),
@@ -692,9 +683,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
MessageId wrappedCommentId = new MessageId(getRandomId());
Message wrappedCommentMsg = new Message(wrappedCommentId,
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
Message wrappedCommentMsg = getMessage(blog2.getId());
MessageId wrappedCommentId = wrappedCommentMsg.getId();
BdfDictionary wrappedCommentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, WRAPPED_COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, comment),
@@ -705,9 +695,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
String localComment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
MessageId localCommentId = new MessageId(getRandomId());
Message localCommentMsg = new Message(localCommentId,
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
Message localCommentMsg = getMessage(blog2.getId());
MessageId localCommentId = localCommentMsg.getId();
BdfDictionary localCommentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, localComment),

View File

@@ -25,6 +25,7 @@ import java.security.GeneralSecurityException;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -74,17 +75,12 @@ public class BlogPostValidatorTest extends BriarTestCase {
);
blog = new Blog(group, author, false);
rssBlog = new Blog(group, author, true);
MessageId messageId = new MessageId(getRandomId());
long timestamp = System.currentTimeMillis();
byte[] raw = getRandomBytes(123);
message = new Message(messageId, group.getId(), timestamp, raw);
message = getMessage(group.getId());
MetadataEncoder metadataEncoder = context.mock(MetadataEncoder.class);
Clock clock = new SystemClock();
validator =
new BlogPostValidator(groupFactory, messageFactory, blogFactory,
clientHelper, metadataEncoder, clock);
validator = new BlogPostValidator(groupFactory, messageFactory,
blogFactory, clientHelper, metadataEncoder, clock);
context.assertIsSatisfied();
}
@@ -117,8 +113,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
}
@Test(expected = FormatException.class)
public void testValidateBlogPostWithoutAttachments()
throws IOException, GeneralSecurityException {
public void testValidateBlogPostWithoutAttachments() throws IOException {
BdfList content = BdfList.of(null, null, body);
BdfList m = BdfList.of(POST.getInt(), content, null);
@@ -126,8 +121,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
}
@Test(expected = FormatException.class)
public void testValidateBlogPostWithoutSignature()
throws IOException, GeneralSecurityException {
public void testValidateBlogPostWithoutSignature() throws IOException {
BdfList content = BdfList.of(null, null, body, null);
BdfList m = BdfList.of(POST.getInt(), content, null);

View File

@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.ImmediateExecutor;
@@ -39,8 +38,7 @@ import okhttp3.Dns;
import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEEDS;
import static org.briarproject.briar.api.feed.FeedManager.CLIENT_ID;
import static org.briarproject.briar.api.feed.FeedManager.MAJOR_VERSION;
@@ -109,8 +107,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
entry.setUpdatedDate(new Date());
entries.add(entry);
String body = "<p> (" + entry.getUpdatedDate().toString() + ")</p>";
Message msg = new Message(new MessageId(getRandomId()), blogGroupId, 0,
getRandomBytes(42));
Message msg = getMessage(blogGroupId);
BlogPost post = new BlogPost(msg, null, localAuthor);
context.checking(new Expectations() {{
@@ -118,9 +115,8 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
will(returnValue(txn));
oneOf(clock).currentTimeMillis();
will(returnValue(42L));
oneOf(blogPostFactory)
.createBlogPost(feed.getBlogId(), 42L, null, localAuthor,
body);
oneOf(blogPostFactory).createBlogPost(feed.getBlogId(), 42L, null,
localAuthor, body);
will(returnValue(post));
oneOf(blogManager).addLocalPost(txn, post);
oneOf(db).commitTransaction(txn);

View File

@@ -11,8 +11,11 @@ import org.briarproject.bramble.test.BrambleMockTestCase;
import org.jmock.Expectations;
import org.junit.Test;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
@@ -27,9 +30,9 @@ public class MessageEncoderTest extends BrambleMockTestCase {
new MessageEncoderImpl(clientHelper, messageFactory);
private final GroupId groupId = new GroupId(getRandomId());
private final Message message = getMessage(groupId);
private final Message message = getMessage(groupId, MAX_MESSAGE_LENGTH);
private final long timestamp = message.getTimestamp();
private final byte[] body = message.getRaw();
private final byte[] body = getRandomBytes(MAX_MESSAGE_BODY_LENGTH);
private final Author author = getAuthor();
private final BdfList authorList = new BdfList();
private final String text = getRandomString(MAX_REQUEST_MESSAGE_LENGTH);
@@ -43,8 +46,8 @@ public class MessageEncoderTest extends BrambleMockTestCase {
expectCreateMessage(
BdfList.of(REQUEST.getValue(), null, authorList, text));
messageEncoder
.encodeRequestMessage(groupId, timestamp, null, author, text);
messageEncoder.encodeRequestMessage(groupId, timestamp, null,
author, text);
}
private void expectCreateMessage(BdfList bodyList) throws FormatException {

View File

@@ -44,7 +44,7 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
@Inject
ForumPostFactory forumPostFactory;
public MessageSizeIntegrationTest() throws Exception {
public MessageSizeIntegrationTest() {
MessageSizeIntegrationTestComponent component =
DaggerMessageSizeIntegrationTestComponent.builder().build();
component.inject(this);
@@ -60,9 +60,9 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
PrivateMessage message = privateMessageFactory.createPrivateMessage(
groupId, timestamp, body);
// Check the size of the serialised message
int length = message.getMessage().getRaw().length;
assertTrue(
length > UniqueId.LENGTH + 8 + MAX_PRIVATE_MESSAGE_BODY_LENGTH);
int length = message.getMessage().getLength();
assertTrue(length > UniqueId.LENGTH + 8
+ MAX_PRIVATE_MESSAGE_BODY_LENGTH);
assertTrue(length <= MAX_RECORD_PAYLOAD_BYTES);
}
@@ -83,7 +83,7 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
ForumPost post = forumPostFactory.createPost(groupId,
timestamp, parent, author, body);
// Check the size of the serialised message
int length = post.getMessage().getRaw().length;
int length = post.getMessage().getLength();
assertTrue(length > UniqueId.LENGTH + 8 + UniqueId.LENGTH + 4
+ MAX_AUTHOR_NAME_LENGTH + MAX_PUBLIC_KEY_LENGTH
+ MAX_FORUM_POST_BODY_LENGTH);

View File

@@ -29,6 +29,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -44,94 +45,83 @@ import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
import static org.briarproject.briar.privategroup.invitation.MessageType.LEAVE;
import static org.junit.Assert.assertEquals;
public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
protected final DatabaseComponent db =
context.mock(DatabaseComponent.class);
protected final ClientHelper clientHelper =
context.mock(ClientHelper.class);
protected final ClientVersioningManager clientVersioningManager =
final DatabaseComponent db = context.mock(DatabaseComponent.class);
final ClientHelper clientHelper = context.mock(ClientHelper.class);
final ClientVersioningManager clientVersioningManager =
context.mock(ClientVersioningManager.class);
protected final PrivateGroupFactory privateGroupFactory =
final PrivateGroupFactory privateGroupFactory =
context.mock(PrivateGroupFactory.class);
protected final PrivateGroupManager privateGroupManager =
final PrivateGroupManager privateGroupManager =
context.mock(PrivateGroupManager.class);
protected final MessageParser messageParser =
context.mock(MessageParser.class);
protected final GroupMessageFactory groupMessageFactory =
final MessageParser messageParser = context.mock(MessageParser.class);
final GroupMessageFactory groupMessageFactory =
context.mock(GroupMessageFactory.class);
protected final IdentityManager identityManager =
context.mock(IdentityManager.class);
protected final MessageEncoder messageEncoder =
context.mock(MessageEncoder.class);
protected final MessageTracker messageTracker =
context.mock(MessageTracker.class);
protected final Clock clock = context.mock(Clock.class);
final IdentityManager identityManager = context.mock(IdentityManager.class);
final MessageEncoder messageEncoder = context.mock(MessageEncoder.class);
final MessageTracker messageTracker = context.mock(MessageTracker.class);
final Clock clock = context.mock(Clock.class);
protected final Transaction txn = new Transaction(null, false);
protected final GroupId contactGroupId = new GroupId(getRandomId());
protected final Group privateGroupGroup =
getGroup(CLIENT_ID, MAJOR_VERSION);
protected final GroupId privateGroupId = privateGroupGroup.getId();
protected final Author author = getAuthor();
protected final PrivateGroup privateGroup =
new PrivateGroup(privateGroupGroup,
getRandomString(MAX_GROUP_NAME_LENGTH), author,
getRandomBytes(GROUP_SALT_LENGTH));
protected final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH);
protected final MessageId lastLocalMessageId = new MessageId(getRandomId());
protected final MessageId lastRemoteMessageId =
new MessageId(getRandomId());
protected final long localTimestamp = 3L;
protected final long inviteTimestamp = 6L;
protected final long messageTimestamp = inviteTimestamp + 1;
protected final MessageId messageId = new MessageId(getRandomId());
protected final Message message = new Message(messageId, contactGroupId,
messageTimestamp, getRandomBytes(42));
final Transaction txn = new Transaction(null, false);
final GroupId contactGroupId = new GroupId(getRandomId());
final Group privateGroupGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
final GroupId privateGroupId = privateGroupGroup.getId();
final Author author = getAuthor();
final PrivateGroup privateGroup = new PrivateGroup(privateGroupGroup,
getRandomString(MAX_GROUP_NAME_LENGTH), author,
getRandomBytes(GROUP_SALT_LENGTH));
final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH);
final MessageId lastLocalMessageId = new MessageId(getRandomId());
final MessageId lastRemoteMessageId = new MessageId(getRandomId());
final Message message = getMessage(contactGroupId);
final MessageId messageId = message.getId();
final long messageTimestamp = message.getTimestamp();
final long inviteTimestamp = messageTimestamp - 1;
final long localTimestamp = inviteTimestamp - 1;
private final BdfDictionary meta =
BdfDictionary.of(new BdfEntry("me", "ta"));
protected final ContactId contactId = new ContactId(5);
protected final Contact contact = new Contact(contactId, author,
final ContactId contactId = new ContactId(5);
final Contact contact = new Contact(contactId, author,
new AuthorId(getRandomId()), true, true);
protected final InviteMessage inviteMessage =
final InviteMessage inviteMessage =
new InviteMessage(new MessageId(getRandomId()), contactGroupId,
privateGroupId, 0L, privateGroup.getName(),
privateGroup.getCreator(), privateGroup.getSalt(),
getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH),
signature);
protected final JoinMessage joinMessage =
final JoinMessage joinMessage =
new JoinMessage(new MessageId(getRandomId()), contactGroupId,
privateGroupId, 0L, lastRemoteMessageId);
protected final LeaveMessage leaveMessage =
final LeaveMessage leaveMessage =
new LeaveMessage(new MessageId(getRandomId()), contactGroupId,
privateGroupId, 0L, lastRemoteMessageId);
protected final AbortMessage abortMessage =
final AbortMessage abortMessage =
new AbortMessage(messageId, contactGroupId, privateGroupId,
inviteTimestamp + 1);
protected void assertSessionConstantsUnchanged(Session s1, Session s2) {
void assertSessionConstantsUnchanged(Session s1, Session s2) {
assertEquals(s1.getRole(), s2.getRole());
assertEquals(s1.getContactGroupId(), s2.getContactGroupId());
assertEquals(s1.getPrivateGroupId(), s2.getPrivateGroupId());
}
protected void assertSessionRecordedSentMessage(Session s) {
void assertSessionRecordedSentMessage(Session s) {
assertEquals(messageId, s.getLastLocalMessageId());
assertEquals(lastRemoteMessageId, s.getLastRemoteMessageId());
assertEquals(messageTimestamp, s.getLocalTimestamp());
assertEquals(inviteTimestamp, s.getInviteTimestamp());
}
protected void expectGetLocalTimestamp(long time) {
void expectGetLocalTimestamp(long time) {
context.checking(new Expectations() {{
oneOf(clock).currentTimeMillis();
will(returnValue(time));
}});
}
protected void expectSendInviteMessage(String msg)
throws Exception {
void expectSendInviteMessage(String msg) throws Exception {
context.checking(new Expectations() {{
oneOf(messageEncoder)
.encodeInviteMessage(contactGroupId, privateGroupId,
@@ -142,7 +132,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
expectSendMessage(INVITE, true);
}
protected void expectSendJoinMessage(JoinMessage m, boolean visible)
void expectSendJoinMessage(JoinMessage m, boolean visible)
throws Exception {
expectGetLocalTimestamp(messageTimestamp);
context.checking(new Expectations() {{
@@ -154,7 +144,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
expectSendMessage(JOIN, visible);
}
protected void expectSendLeaveMessage(boolean visible) throws Exception {
void expectSendLeaveMessage(boolean visible) throws Exception {
expectGetLocalTimestamp(messageTimestamp);
context.checking(new Expectations() {{
oneOf(messageEncoder)
@@ -165,7 +155,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
expectSendMessage(LEAVE, visible);
}
protected void expectSendAbortMessage() throws Exception {
void expectSendAbortMessage() throws Exception {
expectGetLocalTimestamp(messageTimestamp);
context.checking(new Expectations() {{
oneOf(messageEncoder)
@@ -186,8 +176,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}});
}
protected void expectSetPrivateGroupVisibility(Visibility v)
throws Exception {
void expectSetPrivateGroupVisibility(Visibility v) throws Exception {
expectGetContactId();
context.checking(new Expectations() {{
oneOf(clientVersioningManager).getClientVisibility(txn, contactId,
@@ -197,7 +186,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}});
}
protected void expectGetContactId() throws Exception {
void expectGetContactId() throws Exception {
BdfDictionary groupMeta = BdfDictionary
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
context.checking(new Expectations() {{
@@ -207,8 +196,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}});
}
protected void expectIsSubscribedPrivateGroup()
throws Exception {
void expectIsSubscribedPrivateGroup() throws Exception {
context.checking(new Expectations() {{
oneOf(db).containsGroup(txn, privateGroupId);
will(returnValue(true));
@@ -217,19 +205,17 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}});
}
protected void expectIsNotSubscribedPrivateGroup()
throws Exception {
void expectIsNotSubscribedPrivateGroup() throws Exception {
context.checking(new Expectations() {{
oneOf(db).containsGroup(txn, privateGroupId);
will(returnValue(false));
}});
}
protected void expectMarkMessageVisibleInUi(MessageId m, boolean visible)
throws Exception {
void expectMarkMessageVisibleInUi(MessageId m) throws Exception {
BdfDictionary d = new BdfDictionary();
context.checking(new Expectations() {{
oneOf(messageEncoder).setVisibleInUi(d, visible);
oneOf(messageEncoder).setVisibleInUi(d, true);
oneOf(clientHelper).mergeMessageMetadata(txn, m, d);
}});
}

View File

@@ -305,7 +305,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
lastRemoteMessageId);
expectSendJoinMessage(properJoinMessage, false);
expectMarkMessageVisibleInUi(properJoinMessage.getId(), true);
expectMarkMessageVisibleInUi(properJoinMessage.getId());
context.checking(new Expectations() {{
oneOf(messageTracker)
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
@@ -394,7 +394,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
lastRemoteMessageId);
CreatorSession session = getDefaultSession(INVITED);
expectMarkMessageVisibleInUi(properLeaveMessage.getId(), true);
expectMarkMessageVisibleInUi(properLeaveMessage.getId());
context.checking(new Expectations() {{
oneOf(messageTracker)
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
@@ -463,7 +463,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
}
private void assertSessionAborted(CreatorSession oldSession,
CreatorSession newSession) throws Exception {
CreatorSession newSession) {
assertEquals(ERROR, newSession.getState());
assertSessionRecordedSentMessage(newSession);
assertSessionConstantsUnchanged(oldSession, newSession);

View File

@@ -46,7 +46,6 @@ import javax.annotation.Nullable;
import static junit.framework.TestCase.fail;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage;
@@ -106,9 +105,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final Group privateGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final BdfDictionary meta = BdfDictionary.of(new BdfEntry("m", "e"));
private final Message message =
new Message(new MessageId(getRandomId()), contactGroup.getId(),
0L, getRandomBytes(MESSAGE_HEADER_LENGTH + 1));
private final Message message = getMessage(contactGroup.getId());
private final BdfList body = BdfList.of("body");
private final SessionId sessionId =
new SessionId(privateGroup.getId().getBytes());
@@ -725,13 +722,11 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
@Test
public void testGetInvitations() throws Exception {
BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
Message message2 = getMessage(contactGroup.getId());
BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
Map<MessageId, BdfDictionary> results = new HashMap<>();
results.put(message.getId(), meta);
results.put(messageId2, meta2);
Message message2 = new Message(messageId2, contactGroup.getId(),
0L, getRandomBytes(MESSAGE_HEADER_LENGTH + 1));
results.put(message2.getId(), meta2);
long time1 = 1L, time2 = 2L;
String groupName = getRandomString(MAX_GROUP_NAME_LENGTH);
byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
@@ -766,7 +761,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
salt);
will(returnValue(pg));
// message 2
oneOf(messageParser).getInviteMessage(txn, messageId2);
oneOf(messageParser).getInviteMessage(txn, message2.getId());
will(returnValue(inviteMessage2));
oneOf(privateGroupFactory).createPrivateGroup(groupName, author,
salt);

View File

@@ -360,7 +360,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
oneOf(db).getContact(txn, contactId);
will(returnValue(contact));
}});
expectMarkMessageVisibleInUi(properInviteMessage.getId(), true);
expectMarkMessageVisibleInUi(properInviteMessage.getId());
expectMarkMessageAvailableToAnswer(properInviteMessage.getId(), true);
context.checking(new Expectations() {{
oneOf(messageTracker).trackMessage(txn, contactGroupId,
@@ -766,7 +766,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
}
private void assertSessionAborted(InviteeSession oldSession,
InviteeSession newSession) throws Exception {
InviteeSession newSession) {
assertEquals(ERROR, newSession.getState());
assertSessionRecordedSentMessage(newSession);
assertSessionConstantsUnchanged(oldSession, newSession);

View File

@@ -36,7 +36,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION;
@@ -198,8 +198,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
throws Exception {
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
BdfDictionary sessionDict = new BdfDictionary();
Message message = new Message(new MessageId(getRandomId()),
contactGroup.getId(), 42L, getRandomBytes(1337));
Message message = getMessage(contactGroup.getId());
context.checking(new Expectations() {{
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact);