Added unit test for setting contact active.

This commit is contained in:
akwizgran
2016-02-18 10:10:12 +00:00
parent a6baa5821e
commit b7dc13ab53

View File

@@ -4,6 +4,7 @@ import org.briarproject.BriarTestCase;
import org.briarproject.TestDatabaseConfig;
import org.briarproject.TestUtils;
import org.briarproject.api.TransportId;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.crypto.SecretKey;
import org.briarproject.api.db.DbException;
@@ -1108,6 +1109,38 @@ public class H2DatabaseTest extends BriarTestCase {
db.close();
}
@Test
public void testSetContactActive() throws Exception {
Database<Connection> db = open(false);
Connection txn = db.startTransaction();
// Add a contact
db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
true));
// The contact should be active
Contact contact = db.getContact(txn, contactId);
assertTrue(contact.isActive());
// Set the contact inactive
db.setContactActive(txn, contactId, false);
// The contact should be inactive
contact = db.getContact(txn, contactId);
assertFalse(contact.isActive());
// Set the contact active
db.setContactActive(txn, contactId, true);
// The contact should be active
contact = db.getContact(txn, contactId);
assertTrue(contact.isActive());
db.commitTransaction(txn);
db.close();
}
@Test
public void testExceptionHandling() throws Exception {
Database<Connection> db = open(false);