Use null instead of MessageId.NONE and AuthorId.NONE, as for other

optional fields.
This commit is contained in:
akwizgran
2011-09-13 14:04:23 +01:00
parent 70b1487140
commit 1d25b5a92e
13 changed files with 51 additions and 47 deletions

View File

@@ -109,13 +109,13 @@ public class FileReadWriteTest extends TestCase {
authorKeyPair.getPublic().getEncoded());
// Create two messages to each group: one anonymous, one pseudonymous
MessageEncoder messageEncoder = i.getInstance(MessageEncoder.class);
message = messageEncoder.encodeMessage(MessageId.NONE, group,
message = messageEncoder.encodeMessage(null, group,
messageBody.getBytes("UTF-8"));
message1 = messageEncoder.encodeMessage(MessageId.NONE, group1,
message1 = messageEncoder.encodeMessage(null, group1,
groupKeyPair.getPrivate(), messageBody.getBytes("UTF-8"));
message2 = messageEncoder.encodeMessage(MessageId.NONE, group, author,
message2 = messageEncoder.encodeMessage(null, group, author,
authorKeyPair.getPrivate(), messageBody.getBytes("UTF-8"));
message3 = messageEncoder.encodeMessage(MessageId.NONE, group1,
message3 = messageEncoder.encodeMessage(null, group1,
groupKeyPair.getPrivate(), author, authorKeyPair.getPrivate(),
messageBody.getBytes("UTF-8"));
transports = Collections.singletonMap("foo",

View File

@@ -6,7 +6,6 @@ import static net.sf.briar.api.db.DatabaseComponent.MIN_FREE_SPACE;
import java.util.Collections;
import net.sf.briar.api.db.DbException;
import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.db.DatabaseCleaner.Callback;
import org.jmock.Expectations;
@@ -109,7 +108,7 @@ public abstract class DatabaseComponentImplTest extends DatabaseComponentTest {
oneOf(database).getSendability(txn, messageId);
will(returnValue(1));
oneOf(database).getParent(txn, messageId);
will(returnValue(MessageId.NONE));
will(returnValue(null));
oneOf(database).removeMessage(txn, messageId);
oneOf(database).commitTransaction(txn);
oneOf(database).getFreeSpace();

View File

@@ -68,8 +68,8 @@ public abstract class DatabaseComponentTest extends TestCase {
timestamp = System.currentTimeMillis();
size = 1234;
raw = new byte[size];
message = new TestMessage(messageId, MessageId.NONE, groupId, authorId,
timestamp, raw);
message =
new TestMessage(messageId, null, groupId, authorId, timestamp, raw);
group = new TestGroup(groupId, "The really exciting group", null);
transports = Collections.singletonMap("foo",
Collections.singletonMap("bar", "baz"));
@@ -198,7 +198,7 @@ public abstract class DatabaseComponentTest extends TestCase {
oneOf(database).setSendability(txn, messageId, 1);
// Backward inclusion stops when the message has no parent
oneOf(database).getParent(txn, messageId);
will(returnValue(MessageId.NONE));
will(returnValue(null));
oneOf(database).commitTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner);
@@ -349,7 +349,7 @@ public abstract class DatabaseComponentTest extends TestCase {
will(returnValue(0));
oneOf(database).setSendability(txn, parentId, 1);
oneOf(database).getParent(txn, parentId);
will(returnValue(MessageId.NONE));
will(returnValue(null));
oneOf(database).commitTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner);
@@ -462,7 +462,7 @@ public abstract class DatabaseComponentTest extends TestCase {
oneOf(database).setSendability(txn, messageId, 3);
// The sendability of the message's ancestors should be updated
oneOf(database).getParent(txn, messageId);
will(returnValue(MessageId.NONE));
will(returnValue(null));
oneOf(database).commitTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner);
@@ -988,7 +988,7 @@ public abstract class DatabaseComponentTest extends TestCase {
will(returnValue(1));
oneOf(database).setSendability(txn, messageId, 2);
oneOf(database).getParent(txn, messageId);
will(returnValue(MessageId.NONE));
will(returnValue(null));
// The batch needs to be acknowledged
oneOf(batch).getId();
will(returnValue(batchId));

View File

@@ -84,8 +84,8 @@ public class H2DatabaseTest extends TestCase {
size = 1234;
raw = new byte[size];
random.nextBytes(raw);
message = new TestMessage(messageId, MessageId.NONE, groupId, authorId,
timestamp, raw);
message =
new TestMessage(messageId, null, groupId, authorId, timestamp, raw);
group = groupFactory.createGroup(groupId, "Group name", null);
transports = Collections.singletonMap("foo",
Collections.singletonMap("bar", "baz"));
@@ -675,8 +675,8 @@ public class H2DatabaseTest extends TestCase {
public void testGetMessagesByAuthor() throws DbException {
AuthorId authorId1 = new AuthorId(TestUtils.getRandomId());
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
Message message1 = new TestMessage(messageId1, MessageId.NONE, groupId,
authorId1, timestamp, raw);
Message message1 = new TestMessage(messageId1, null, groupId, authorId1,
timestamp, raw);
Database<Connection> db = open(false);
Connection txn = db.startTransaction();
@@ -744,8 +744,8 @@ public class H2DatabaseTest extends TestCase {
@Test
public void testGetOldMessages() throws DbException {
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
Message message1 = new TestMessage(messageId1, MessageId.NONE, groupId,
authorId, timestamp + 1000, raw);
Message message1 = new TestMessage(messageId1, null, groupId, authorId,
timestamp + 1000, raw);
Database<Connection> db = open(false);
Connection txn = db.startTransaction();
@@ -775,8 +775,8 @@ public class H2DatabaseTest extends TestCase {
public void testGetFreeSpace() throws Exception {
byte[] largeBody = new byte[ONE_MEGABYTE];
for(int i = 0; i < largeBody.length; i++) largeBody[i] = (byte) i;
Message message1 = new TestMessage(messageId, MessageId.NONE, groupId,
authorId, timestamp, largeBody);
Message message1 = new TestMessage(messageId, null, groupId, authorId,
timestamp, largeBody);
Database<Connection> db = open(false);
// Sanity check: there should be enough space on disk for this test

View File

@@ -15,7 +15,6 @@ import net.sf.briar.api.protocol.Group;
import net.sf.briar.api.protocol.GroupFactory;
import net.sf.briar.api.protocol.Message;
import net.sf.briar.api.protocol.MessageEncoder;
import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.api.protocol.Offer;
import net.sf.briar.api.protocol.ProtocolReader;
import net.sf.briar.api.protocol.ProtocolReaderFactory;
@@ -61,7 +60,7 @@ public class ProtocolReadWriteTest extends TestCase {
GroupFactory groupFactory = i.getInstance(GroupFactory.class);
group = groupFactory.createGroup("Unrestricted group", null);
MessageEncoder messageEncoder = i.getInstance(MessageEncoder.class);
message = messageEncoder.encodeMessage(MessageId.NONE, group,
message = messageEncoder.encodeMessage(null, group,
messageBody.getBytes("UTF-8"));
bitSet = new BitSet();
bitSet.set(3);

View File

@@ -87,7 +87,7 @@ public class ConstantsTest extends TestCase {
PrivateKey groupPrivate = crypto.generateKeyPair().getPrivate();
PrivateKey authorPrivate = crypto.generateKeyPair().getPrivate();
byte[] body = new byte[Message.MAX_BODY_LENGTH];
Message message = messageEncoder.encodeMessage(MessageId.NONE, group,
Message message = messageEncoder.encodeMessage(null, group,
groupPrivate, author, authorPrivate, body);
// Add the message to a batch
ByteArrayOutputStream out = new ByteArrayOutputStream(