mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Add database method for retrieving a contact by author ID
and use it for retreiving the status of an author faster. Also add tests for both.
This commit is contained in:
@@ -784,6 +784,33 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContactsByAuthorId() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a local author - no contacts should be associated
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
|
||||
// Add a contact associated with the local author
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true, true));
|
||||
|
||||
// Ensure contact is returned from database by Author ID
|
||||
Collection<Contact> contacts =
|
||||
db.getContactsByAuthorId(txn, author.getId());
|
||||
assertEquals(1, contacts.size());
|
||||
assertEquals(contactId, contacts.iterator().next().getId());
|
||||
|
||||
// Ensure no contacts are returned after contact was deleted
|
||||
db.removeContact(txn, contactId);
|
||||
contacts = db.getContactsByAuthorId(txn, author.getId());
|
||||
assertEquals(0, contacts.size());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContactsByLocalAuthorId() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
|
||||
Reference in New Issue
Block a user