mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Converted Group from an interface to an immutable class.
This commit is contained in:
@@ -79,7 +79,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
timestamp, raw);
|
||||
privateMessage = new TestMessage(messageId, null, null, null, subject,
|
||||
timestamp, raw);
|
||||
group = new TestGroup(groupId, "The really exciting group", null);
|
||||
group = new Group(groupId, "The really exciting group", null);
|
||||
transportId = new TransportId(TestUtils.getRandomId());
|
||||
TransportProperties properties = new TransportProperties(
|
||||
Collections.singletonMap("foo", "bar"));
|
||||
@@ -104,7 +104,6 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final PacketFactory packetFactory = context.mock(PacketFactory.class);
|
||||
final Group group = context.mock(Group.class);
|
||||
final DatabaseListener listener = context.mock(DatabaseListener.class);
|
||||
context.checking(new Expectations() {{
|
||||
allowing(database).startTransaction();
|
||||
@@ -140,14 +139,10 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).getRemoteProperties(txn, transportId);
|
||||
will(returnValue(Collections.emptyMap()));
|
||||
// subscribe(group)
|
||||
oneOf(group).getId();
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).containsSubscription(txn, groupId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addSubscription(txn, group);
|
||||
// subscribe(group) again
|
||||
oneOf(group).getId();
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).containsSubscription(txn, groupId);
|
||||
will(returnValue(true));
|
||||
// getMessageHeaders(groupId)
|
||||
|
||||
@@ -31,7 +31,6 @@ import net.sf.briar.api.db.MessageHeader;
|
||||
import net.sf.briar.api.protocol.AuthorId;
|
||||
import net.sf.briar.api.protocol.BatchId;
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.GroupFactory;
|
||||
import net.sf.briar.api.protocol.GroupId;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
@@ -52,7 +51,6 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
private final File testDir = TestUtils.getTestDirectory();
|
||||
private final Random random = new Random();
|
||||
private final GroupFactory groupFactory;
|
||||
private final Group group;
|
||||
private final AuthorId authorId;
|
||||
private final BatchId batchId;
|
||||
@@ -68,14 +66,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
public H2DatabaseTest() throws Exception {
|
||||
super();
|
||||
groupFactory = new TestGroupFactory();
|
||||
authorId = new AuthorId(TestUtils.getRandomId());
|
||||
batchId = new BatchId(TestUtils.getRandomId());
|
||||
contactId = new ContactId(1);
|
||||
groupId = new GroupId(TestUtils.getRandomId());
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
privateMessageId = new MessageId(TestUtils.getRandomId());
|
||||
group = new TestGroup(groupId, "Foo", null);
|
||||
group = new Group(groupId, "Foo", null);
|
||||
subject = "Foo";
|
||||
timestamp = System.currentTimeMillis();
|
||||
size = 1234;
|
||||
@@ -798,7 +795,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
MessageId childId2 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId childId3 = new MessageId(TestUtils.getRandomId());
|
||||
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||
Group group1 = groupFactory.createGroup(groupId1, "Another group name",
|
||||
Group group1 = new Group(groupId1, "Another group name",
|
||||
null);
|
||||
Message child1 = new TestMessage(childId1, messageId, groupId,
|
||||
authorId, subject, timestamp, raw);
|
||||
@@ -1391,7 +1388,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
public void testGetGroupMessageParentWithParentInAnotherGroup()
|
||||
throws Exception {
|
||||
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||
Group group1 = groupFactory.createGroup(groupId1, "Group name", null);
|
||||
Group group1 = new Group(groupId1, "Group name", null);
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
@@ -1641,8 +1638,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
// Subscribe to a couple of groups
|
||||
db.addSubscription(txn, group);
|
||||
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||
Group group1 = groupFactory.createGroup(groupId1, "Another group",
|
||||
null);
|
||||
Group group1 = new Group(groupId1, "Another group", null);
|
||||
db.addSubscription(txn, group1);
|
||||
|
||||
// Store two messages in the first group
|
||||
@@ -1695,7 +1691,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
List<Group> groups = new ArrayList<Group>();
|
||||
for(int i = 0; i < 100; i++) {
|
||||
GroupId id = new GroupId(TestUtils.getRandomId());
|
||||
groups.add(groupFactory.createGroup(id, "Group name", null));
|
||||
groups.add(new Group(id, "Group name", null));
|
||||
}
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
@@ -2030,9 +2026,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
private Database<Connection> open(boolean resume) throws Exception {
|
||||
Database<Connection> db = new H2Database(
|
||||
new TestDatabaseConfig(testDir, MAX_SIZE), groupFactory,
|
||||
new SystemClock());
|
||||
Database<Connection> db = new H2Database(new SystemClock(),
|
||||
new TestDatabaseConfig(testDir, MAX_SIZE));
|
||||
db.open(resume);
|
||||
return db;
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package net.sf.briar.db;
|
||||
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.GroupId;
|
||||
|
||||
class TestGroup implements Group {
|
||||
|
||||
private final GroupId id;
|
||||
private final String name;
|
||||
private final byte[] publicKey;
|
||||
|
||||
public TestGroup(GroupId id, String name, byte[] publicKey) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
public GroupId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package net.sf.briar.db;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.GroupFactory;
|
||||
import net.sf.briar.api.protocol.GroupId;
|
||||
|
||||
class TestGroupFactory implements GroupFactory {
|
||||
|
||||
public Group createGroup(String name, byte[] publicKey) throws IOException {
|
||||
GroupId id = new GroupId(TestUtils.getRandomId());
|
||||
return new TestGroup(id, name, publicKey);
|
||||
}
|
||||
|
||||
public Group createGroup(GroupId id, String name, byte[] publicKey) {
|
||||
return new TestGroup(id, name, publicKey);
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,9 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
||||
final int signedByAuthor = 100, signedByGroup = 110;
|
||||
final KeyPair authorKeyPair = crypto.generateSignatureKeyPair();
|
||||
final KeyPair groupKeyPair = crypto.generateSignatureKeyPair();
|
||||
GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
final Group group = new Group(groupId, "Group name",
|
||||
groupKeyPair.getPublic().getEncoded());
|
||||
Signature signature = crypto.getSignature();
|
||||
// Calculate the expected author and group signatures
|
||||
signature.initSign(authorKeyPair.getPrivate());
|
||||
@@ -139,7 +142,6 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
||||
final UnverifiedMessage message =
|
||||
context.mock(UnverifiedMessage.class, "message");
|
||||
final Author author = context.mock(Author.class);
|
||||
final Group group = context.mock(Group.class);
|
||||
final UnverifiedMessage message1 =
|
||||
context.mock(UnverifiedMessage.class, "message1");
|
||||
context.checking(new Expectations() {{
|
||||
@@ -156,16 +158,12 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
||||
will(returnValue(authorSignature));
|
||||
oneOf(message).getGroup();
|
||||
will(returnValue(group));
|
||||
exactly(2).of(group).getPublicKey();
|
||||
will(returnValue(groupKeyPair.getPublic().getEncoded()));
|
||||
oneOf(message).getLengthSignedByGroup();
|
||||
will(returnValue(signedByGroup));
|
||||
oneOf(message).getGroupSignature();
|
||||
will(returnValue(groupSignature));
|
||||
oneOf(author).getId();
|
||||
will(returnValue(new AuthorId(TestUtils.getRandomId())));
|
||||
oneOf(group).getId();
|
||||
will(returnValue(new GroupId(TestUtils.getRandomId())));
|
||||
oneOf(message).getParent();
|
||||
will(returnValue(null));
|
||||
oneOf(message).getSubject();
|
||||
|
||||
Reference in New Issue
Block a user