Code cleanup: import static, use == to compare enum values.

This commit is contained in:
akwizgran
2013-02-01 22:40:36 +00:00
parent adff37481f
commit 30a0269652
6 changed files with 110 additions and 97 deletions

View File

@@ -523,9 +523,8 @@ interface Database<T> {
throws DbException; throws DbException;
/** /**
* Removes outstanding messages that have been acknowledged. Any of the * Marks any of the given messages that are considered outstanding with
* messages that are still considered outstanding (Status.SENT) with * respect to the given contact as seen by the contact.
* respect to the given contact are now considered seen (Status.SEEN).
* <p> * <p>
* Locking: contact read, message write. * Locking: contact read, message write.
*/ */
@@ -625,9 +624,8 @@ interface Database<T> {
/** /**
* If the database contains the given message and it belongs to a group * If the database contains the given message and it belongs to a group
* that is visible to the given contact, sets the status of the message * that is visible to the given contact, marks the message as seen by the
* with respect to the contact to Status.SEEN and returns true; otherwise * contact and returns true; otherwise returns false.
* returns false.
* <p> * <p>
* Locking: contact read, message write, subscription read. * Locking: contact read, message write, subscription read.
*/ */

View File

@@ -1,11 +1,14 @@
package net.sf.briar.db; package net.sf.briar.db;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static net.sf.briar.api.Rating.GOOD;
import static net.sf.briar.db.DatabaseConstants.BYTES_PER_SWEEP; import static net.sf.briar.db.DatabaseConstants.BYTES_PER_SWEEP;
import static net.sf.briar.db.DatabaseConstants.CRITICAL_FREE_SPACE; import static net.sf.briar.db.DatabaseConstants.CRITICAL_FREE_SPACE;
import static net.sf.briar.db.DatabaseConstants.MAX_BYTES_BETWEEN_SPACE_CHECKS; import static net.sf.briar.db.DatabaseConstants.MAX_BYTES_BETWEEN_SPACE_CHECKS;
import static net.sf.briar.db.DatabaseConstants.MAX_MS_BETWEEN_SPACE_CHECKS; import static net.sf.briar.db.DatabaseConstants.MAX_MS_BETWEEN_SPACE_CHECKS;
import static net.sf.briar.db.DatabaseConstants.MIN_FREE_SPACE; import static net.sf.briar.db.DatabaseConstants.MIN_FREE_SPACE;
import static net.sf.briar.db.Status.NEW;
import static net.sf.briar.db.Status.SEEN;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -274,11 +277,11 @@ DatabaseCleaner.Callback {
boolean stored = db.addGroupMessage(txn, m); boolean stored = db.addGroupMessage(txn, m);
// Mark the message as seen by the sender // Mark the message as seen by the sender
MessageId id = m.getId(); MessageId id = m.getId();
if(sender != null) db.setStatus(txn, sender, id, Status.SEEN); if(sender != null) db.setStatus(txn, sender, id, SEEN);
if(stored) { if(stored) {
// Mark the message as unseen by other contacts // Mark the message as unseen by other contacts
for(ContactId c : db.getContacts(txn)) { for(ContactId c : db.getContacts(txn)) {
if(!c.equals(sender)) db.setStatus(txn, c, id, Status.NEW); if(!c.equals(sender)) db.setStatus(txn, c, id, NEW);
} }
// Calculate and store the message's sendability // Calculate and store the message's sendability
int sendability = calculateSendability(txn, m); int sendability = calculateSendability(txn, m);
@@ -301,7 +304,7 @@ DatabaseCleaner.Callback {
int sendability = 0; int sendability = 0;
// One point for a good rating // One point for a good rating
AuthorId a = m.getAuthor(); AuthorId a = m.getAuthor();
if(a != null && db.getRating(txn, a) == Rating.GOOD) sendability++; if(a != null && db.getRating(txn, a) == GOOD) sendability++;
// One point per sendable child (backward inclusion) // One point per sendable child (backward inclusion)
sendability += db.getNumberOfSendableChildren(txn, m.getId()); sendability += db.getNumberOfSendableChildren(txn, m.getId());
return sendability; return sendability;
@@ -438,8 +441,8 @@ DatabaseCleaner.Callback {
if(m.getAuthor() != null) throw new IllegalArgumentException(); if(m.getAuthor() != null) throw new IllegalArgumentException();
if(!db.addPrivateMessage(txn, m, c)) return false; if(!db.addPrivateMessage(txn, m, c)) return false;
MessageId id = m.getId(); MessageId id = m.getId();
if(incoming) db.setStatus(txn, c, id, Status.SEEN); if(incoming) db.setStatus(txn, c, id, SEEN);
else db.setStatus(txn, c, id, Status.NEW); else db.setStatus(txn, c, id, NEW);
// Count the bytes stored // Count the bytes stored
synchronized(spaceLock) { synchronized(spaceLock) {
bytesStoredSinceLastCheck += m.getSerialised().length; bytesStoredSinceLastCheck += m.getSerialised().length;
@@ -518,7 +521,7 @@ DatabaseCleaner.Callback {
messageLock.readLock().unlock(); messageLock.readLock().unlock();
} }
if(messages.isEmpty()) return null; if(messages.isEmpty()) return null;
// Record the message as sent // Record the messages as sent
messageLock.writeLock().lock(); messageLock.writeLock().lock();
try { try {
T txn = db.startTransaction(); T txn = db.startTransaction();
@@ -1553,9 +1556,9 @@ DatabaseCleaner.Callback {
Rating old = db.setRating(txn, a, r); Rating old = db.setRating(txn, a, r);
changed = (old != r); changed = (old != r);
// Update the sendability of the author's messages // Update the sendability of the author's messages
if(r == Rating.GOOD && old != Rating.GOOD) if(r == GOOD && old != GOOD)
updateAuthorSendability(txn, a, true); updateAuthorSendability(txn, a, true);
else if(r != Rating.GOOD && old == Rating.GOOD) else if(r != GOOD && old == GOOD)
updateAuthorSendability(txn, a, false); updateAuthorSendability(txn, a, false);
db.commitTransaction(txn); db.commitTransaction(txn);
} catch(DbException e) { } catch(DbException e) {

View File

@@ -3,7 +3,11 @@ package net.sf.briar.db;
import static java.sql.Types.BINARY; import static java.sql.Types.BINARY;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static net.sf.briar.api.Rating.UNRATED;
import static net.sf.briar.db.DatabaseConstants.RETENTION_MODULUS; import static net.sf.briar.db.DatabaseConstants.RETENTION_MODULUS;
import static net.sf.briar.db.Status.NEW;
import static net.sf.briar.db.Status.SEEN;
import static net.sf.briar.db.Status.SENT;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -649,9 +653,9 @@ abstract class JdbcDatabase implements Database<Connection> {
String sql = "UPDATE statuses SET status = ?" String sql = "UPDATE statuses SET status = ?"
+ " WHERE messageId = ? AND contactId = ? AND status = ?"; + " WHERE messageId = ? AND contactId = ? AND status = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setShort(1, (short) Status.SENT.ordinal()); ps.setShort(1, (short) SENT.ordinal());
ps.setInt(3, c.getInt()); ps.setInt(3, c.getInt());
ps.setShort(4, (short) Status.NEW.ordinal()); ps.setShort(4, (short) NEW.ordinal());
for(MessageId m : sent) { for(MessageId m : sent) {
ps.setBytes(2, m.getBytes()); ps.setBytes(2, m.getBytes());
ps.addBatch(); ps.addBatch();
@@ -1227,7 +1231,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " ORDER BY timestamp DESC LIMIT ?"; + " ORDER BY timestamp DESC LIMIT ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setShort(2, (short) Status.NEW.ordinal()); ps.setShort(2, (short) NEW.ordinal());
ps.setInt(3, maxMessages); ps.setInt(3, maxMessages);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<MessageId>();
@@ -1255,7 +1259,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " ORDER BY timestamp DESC LIMIT ?"; + " ORDER BY timestamp DESC LIMIT ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setShort(2, (short) Status.NEW.ordinal()); ps.setShort(2, (short) NEW.ordinal());
ps.setInt(3, maxMessages - ids.size()); ps.setInt(3, maxMessages - ids.size());
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()) ids.add(new MessageId(rs.getBytes(2))); while(rs.next()) ids.add(new MessageId(rs.getBytes(2)));
@@ -1341,7 +1345,7 @@ abstract class JdbcDatabase implements Database<Connection> {
rs = ps.executeQuery(); rs = ps.executeQuery();
Rating r; Rating r;
if(rs.next()) r = Rating.values()[rs.getByte(1)]; if(rs.next()) r = Rating.values()[rs.getByte(1)];
else r = Rating.UNRATED; else r = UNRATED;
if(rs.next()) throw new DbStateException(); if(rs.next()) throw new DbStateException();
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1391,7 +1395,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getBytes()); ps.setBytes(1, m.getBytes());
ps.setInt(2, c.getInt()); ps.setInt(2, c.getInt());
ps.setShort(3, (short) Status.NEW.ordinal()); ps.setShort(3, (short) NEW.ordinal());
rs = ps.executeQuery(); rs = ps.executeQuery();
byte[] raw = null; byte[] raw = null;
if(rs.next()) { if(rs.next()) {
@@ -1423,7 +1427,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getBytes()); ps.setBytes(1, m.getBytes());
ps.setInt(2, c.getInt()); ps.setInt(2, c.getInt());
ps.setShort(3, (short) Status.NEW.ordinal()); ps.setShort(3, (short) NEW.ordinal());
rs = ps.executeQuery(); rs = ps.executeQuery();
if(rs.next()) { if(rs.next()) {
int length = rs.getInt(1); int length = rs.getInt(1);
@@ -1638,7 +1642,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " ORDER BY timestamp DESC"; + " ORDER BY timestamp DESC";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setShort(2, (short) Status.NEW.ordinal()); ps.setShort(2, (short) NEW.ordinal());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<MessageId>();
int total = 0; int total = 0;
@@ -1670,7 +1674,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " ORDER BY timestamp DESC"; + " ORDER BY timestamp DESC";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setShort(2, (short) Status.NEW.ordinal()); ps.setShort(2, (short) NEW.ordinal());
rs = ps.executeQuery(); rs = ps.executeQuery();
while(rs.next()) { while(rs.next()) {
int length = rs.getInt(1); int length = rs.getInt(1);
@@ -1995,7 +1999,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " LIMIT ?"; + " LIMIT ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setShort(2, (short) Status.NEW.ordinal()); ps.setShort(2, (short) NEW.ordinal());
ps.setInt(3, 1); ps.setInt(3, 1);
rs = ps.executeQuery(); rs = ps.executeQuery();
boolean found = rs.next(); boolean found = rs.next();
@@ -2022,7 +2026,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " LIMIT ?"; + " LIMIT ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setShort(2, (short) Status.NEW.ordinal()); ps.setShort(2, (short) NEW.ordinal());
ps.setInt(3, 1); ps.setInt(3, 1);
rs = ps.executeQuery(); rs = ps.executeQuery();
found = rs.next(); found = rs.next();
@@ -2100,9 +2104,9 @@ abstract class JdbcDatabase implements Database<Connection> {
String sql = "UPDATE statuses SET status = ?" String sql = "UPDATE statuses SET status = ?"
+ " WHERE messageId = ? AND contactId = ? AND status = ?"; + " WHERE messageId = ? AND contactId = ? AND status = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setShort(1, (short) Status.SEEN.ordinal()); ps.setShort(1, (short) SEEN.ordinal());
ps.setInt(3, c.getInt()); ps.setInt(3, c.getInt());
ps.setShort(4, (short) Status.SENT.ordinal()); ps.setShort(4, (short) SENT.ordinal());
for(MessageId m : acked) { for(MessageId m : acked) {
ps.setBytes(2, m.getBytes()); ps.setBytes(2, m.getBytes());
ps.addBatch(); ps.addBatch();
@@ -2417,7 +2421,7 @@ abstract class JdbcDatabase implements Database<Connection> {
if(rs.next()) throw new DbStateException(); if(rs.next()) throw new DbStateException();
rs.close(); rs.close();
ps.close(); ps.close();
if(!old.equals(r)) { if(old != r) {
sql = "UPDATE ratings SET rating = ? WHERE authorId = ?"; sql = "UPDATE ratings SET rating = ? WHERE authorId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setShort(1, (short) r.ordinal()); ps.setShort(1, (short) r.ordinal());
@@ -2430,8 +2434,8 @@ abstract class JdbcDatabase implements Database<Connection> {
// No rating row exists - create one if necessary // No rating row exists - create one if necessary
rs.close(); rs.close();
ps.close(); ps.close();
old = Rating.UNRATED; old = UNRATED;
if(!old.equals(r)) { if(old != r) {
sql = "INSERT INTO ratings (authorId, rating)" sql = "INSERT INTO ratings (authorId, rating)"
+ " VALUES (?, ?)"; + " VALUES (?, ?)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
@@ -2625,7 +2629,7 @@ abstract class JdbcDatabase implements Database<Connection> {
if(rs.next()) throw new DbStateException(); if(rs.next()) throw new DbStateException();
rs.close(); rs.close();
ps.close(); ps.close();
if(!old.equals(Status.SEEN) && !old.equals(s)) { if(old != SEEN && old != s) {
sql = "UPDATE statuses SET status = ?" sql = "UPDATE statuses SET status = ?"
+ " WHERE messageId = ? AND contactId = ?"; + " WHERE messageId = ? AND contactId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
@@ -2685,7 +2689,7 @@ abstract class JdbcDatabase implements Database<Connection> {
sql = "UPDATE statuses SET status = ?" sql = "UPDATE statuses SET status = ?"
+ " WHERE messageId = ? AND contactId = ?"; + " WHERE messageId = ? AND contactId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setShort(1, (short) Status.SEEN.ordinal()); ps.setShort(1, (short) SEEN.ordinal());
ps.setBytes(2, m.getBytes()); ps.setBytes(2, m.getBytes());
ps.setInt(3, c.getInt()); ps.setInt(3, c.getInt());
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();

View File

@@ -2,6 +2,7 @@ package net.sf.briar.messaging.duplex;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static net.sf.briar.api.Rating.GOOD;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -21,7 +22,6 @@ import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
import net.sf.briar.api.FormatException; import net.sf.briar.api.FormatException;
import net.sf.briar.api.Rating;
import net.sf.briar.api.db.DatabaseComponent; import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.DatabaseExecutor; import net.sf.briar.api.db.DatabaseExecutor;
import net.sf.briar.api.db.DbException; import net.sf.briar.api.db.DbException;
@@ -147,7 +147,7 @@ abstract class DuplexConnection implements DatabaseListener {
dbExecutor.execute(new GenerateAcks()); dbExecutor.execute(new GenerateAcks());
} else if(e instanceof RatingChangedEvent) { } else if(e instanceof RatingChangedEvent) {
RatingChangedEvent r = (RatingChangedEvent) e; RatingChangedEvent r = (RatingChangedEvent) e;
if(r.getRating() == Rating.GOOD && canSendOffer.getAndSet(false)) if(r.getRating() == GOOD && canSendOffer.getAndSet(false))
dbExecutor.execute(new GenerateOffer()); dbExecutor.execute(new GenerateOffer());
} else if(e instanceof RemoteRetentionTimeUpdatedEvent) { } else if(e instanceof RemoteRetentionTimeUpdatedEvent) {
dbExecutor.execute(new GenerateRetentionAck()); dbExecutor.execute(new GenerateRetentionAck());

View File

@@ -1,5 +1,10 @@
package net.sf.briar.db; package net.sf.briar.db;
import static net.sf.briar.api.Rating.GOOD;
import static net.sf.briar.api.Rating.UNRATED;
import static net.sf.briar.db.Status.NEW;
import static net.sf.briar.db.Status.SEEN;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.BitSet; import java.util.BitSet;
@@ -10,7 +15,6 @@ import net.sf.briar.BriarTestCase;
import net.sf.briar.TestMessage; import net.sf.briar.TestMessage;
import net.sf.briar.TestUtils; import net.sf.briar.TestUtils;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
import net.sf.briar.api.Rating;
import net.sf.briar.api.TransportProperties; import net.sf.briar.api.TransportProperties;
import net.sf.briar.api.db.DatabaseComponent; import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.NoSuchContactException; import net.sf.briar.api.db.NoSuchContactException;
@@ -109,16 +113,16 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
will(returnValue(shutdownHandle)); will(returnValue(shutdownHandle));
// getRating(authorId) // getRating(authorId)
oneOf(database).getRating(txn, authorId); oneOf(database).getRating(txn, authorId);
will(returnValue(Rating.UNRATED)); will(returnValue(UNRATED));
// setRating(authorId, Rating.GOOD) // setRating(authorId, GOOD)
oneOf(database).setRating(txn, authorId, Rating.GOOD); oneOf(database).setRating(txn, authorId, GOOD);
will(returnValue(Rating.UNRATED)); will(returnValue(UNRATED));
oneOf(database).getMessagesByAuthor(txn, authorId); oneOf(database).getMessagesByAuthor(txn, authorId);
will(returnValue(Collections.emptyList())); will(returnValue(Collections.emptyList()));
oneOf(listener).eventOccurred(with(any(RatingChangedEvent.class))); oneOf(listener).eventOccurred(with(any(RatingChangedEvent.class)));
// setRating(authorId, Rating.GOOD) again // setRating(authorId, GOOD) again
oneOf(database).setRating(txn, authorId, Rating.GOOD); oneOf(database).setRating(txn, authorId, GOOD);
will(returnValue(Rating.GOOD)); will(returnValue(GOOD));
// addContact() // addContact()
oneOf(database).addContact(txn); oneOf(database).addContact(txn);
will(returnValue(contactId)); will(returnValue(contactId));
@@ -167,9 +171,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
db.open(false); db.open(false);
db.addListener(listener); db.addListener(listener);
assertEquals(Rating.UNRATED, db.getRating(authorId)); assertEquals(UNRATED, db.getRating(authorId));
db.setRating(authorId, Rating.GOOD); // First time - listeners called db.setRating(authorId, GOOD); // First time - listeners called
db.setRating(authorId, Rating.GOOD); // Second time - not called db.setRating(authorId, GOOD); // Second time - not called
assertEquals(contactId, db.addContact()); assertEquals(contactId, db.addContact());
assertEquals(Collections.singletonList(contactId), db.getContacts()); assertEquals(Collections.singletonList(contactId), db.getContacts());
assertEquals(Collections.emptyMap(), assertEquals(Collections.emptyMap(),
@@ -194,11 +198,11 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class); final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
final ShutdownManager shutdown = context.mock(ShutdownManager.class); final ShutdownManager shutdown = context.mock(ShutdownManager.class);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
// setRating(authorId, Rating.GOOD) // setRating(authorId, GOOD)
allowing(database).startTransaction(); allowing(database).startTransaction();
will(returnValue(txn)); will(returnValue(txn));
oneOf(database).setRating(txn, authorId, Rating.GOOD); oneOf(database).setRating(txn, authorId, GOOD);
will(returnValue(Rating.UNRATED)); will(returnValue(UNRATED));
// The sendability of the author's messages should be incremented // The sendability of the author's messages should be incremented
oneOf(database).getMessagesByAuthor(txn, authorId); oneOf(database).getMessagesByAuthor(txn, authorId);
will(returnValue(Collections.singletonList(messageId))); will(returnValue(Collections.singletonList(messageId)));
@@ -213,7 +217,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
DatabaseComponent db = createDatabaseComponent(database, cleaner, DatabaseComponent db = createDatabaseComponent(database, cleaner,
shutdown); shutdown);
db.setRating(authorId, Rating.GOOD); db.setRating(authorId, GOOD);
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@@ -226,11 +230,11 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class); final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
final ShutdownManager shutdown = context.mock(ShutdownManager.class); final ShutdownManager shutdown = context.mock(ShutdownManager.class);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
// setRating(authorId, Rating.GOOD) // setRating(authorId, GOOD)
oneOf(database).startTransaction(); oneOf(database).startTransaction();
will(returnValue(txn)); will(returnValue(txn));
oneOf(database).setRating(txn, authorId, Rating.GOOD); oneOf(database).setRating(txn, authorId, GOOD);
will(returnValue(Rating.UNRATED)); will(returnValue(UNRATED));
// The sendability of the author's messages should be incremented // The sendability of the author's messages should be incremented
oneOf(database).getMessagesByAuthor(txn, authorId); oneOf(database).getMessagesByAuthor(txn, authorId);
will(returnValue(Collections.singletonList(messageId))); will(returnValue(Collections.singletonList(messageId)));
@@ -249,7 +253,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
DatabaseComponent db = createDatabaseComponent(database, cleaner, DatabaseComponent db = createDatabaseComponent(database, cleaner,
shutdown); shutdown);
db.setRating(authorId, Rating.GOOD); db.setRating(authorId, GOOD);
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@@ -263,11 +267,11 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class); final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
final ShutdownManager shutdown = context.mock(ShutdownManager.class); final ShutdownManager shutdown = context.mock(ShutdownManager.class);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
// setRating(authorId, Rating.GOOD) // setRating(authorId, GOOD)
oneOf(database).startTransaction(); oneOf(database).startTransaction();
will(returnValue(txn)); will(returnValue(txn));
oneOf(database).setRating(txn, authorId, Rating.GOOD); oneOf(database).setRating(txn, authorId, GOOD);
will(returnValue(Rating.UNRATED)); will(returnValue(UNRATED));
// The sendability of the author's messages should be incremented // The sendability of the author's messages should be incremented
oneOf(database).getMessagesByAuthor(txn, authorId); oneOf(database).getMessagesByAuthor(txn, authorId);
will(returnValue(Collections.singletonList(messageId))); will(returnValue(Collections.singletonList(messageId)));
@@ -289,7 +293,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
DatabaseComponent db = createDatabaseComponent(database, cleaner, DatabaseComponent db = createDatabaseComponent(database, cleaner,
shutdown); shutdown);
db.setRating(authorId, Rating.GOOD); db.setRating(authorId, GOOD);
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@@ -360,10 +364,10 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
will(returnValue(true)); will(returnValue(true));
oneOf(database).getContacts(txn); oneOf(database).getContacts(txn);
will(returnValue(Collections.singletonList(contactId))); will(returnValue(Collections.singletonList(contactId)));
oneOf(database).setStatus(txn, contactId, messageId, Status.NEW); oneOf(database).setStatus(txn, contactId, messageId, NEW);
// The author is unrated and there are no sendable children // The author is unrated and there are no sendable children
oneOf(database).getRating(txn, authorId); oneOf(database).getRating(txn, authorId);
will(returnValue(Rating.UNRATED)); will(returnValue(UNRATED));
oneOf(database).getNumberOfSendableChildren(txn, messageId); oneOf(database).getNumberOfSendableChildren(txn, messageId);
will(returnValue(0)); will(returnValue(0));
oneOf(database).setSendability(txn, messageId, 0); oneOf(database).setSendability(txn, messageId, 0);
@@ -395,10 +399,10 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
will(returnValue(true)); will(returnValue(true));
oneOf(database).getContacts(txn); oneOf(database).getContacts(txn);
will(returnValue(Collections.singletonList(contactId))); will(returnValue(Collections.singletonList(contactId)));
oneOf(database).setStatus(txn, contactId, messageId, Status.NEW); oneOf(database).setStatus(txn, contactId, messageId, NEW);
// The author is rated GOOD and there are two sendable children // The author is rated GOOD and there are two sendable children
oneOf(database).getRating(txn, authorId); oneOf(database).getRating(txn, authorId);
will(returnValue(Rating.GOOD)); will(returnValue(GOOD));
oneOf(database).getNumberOfSendableChildren(txn, messageId); oneOf(database).getNumberOfSendableChildren(txn, messageId);
will(returnValue(2)); will(returnValue(2));
oneOf(database).setSendability(txn, messageId, 3); oneOf(database).setSendability(txn, messageId, 3);
@@ -456,7 +460,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
// addLocalPrivateMessage(privateMessage, contactId) // addLocalPrivateMessage(privateMessage, contactId)
oneOf(database).addPrivateMessage(txn, privateMessage, contactId); oneOf(database).addPrivateMessage(txn, privateMessage, contactId);
will(returnValue(true)); will(returnValue(true));
oneOf(database).setStatus(txn, contactId, messageId, Status.NEW); oneOf(database).setStatus(txn, contactId, messageId, NEW);
}}); }});
DatabaseComponent db = createDatabaseComponent(database, cleaner, DatabaseComponent db = createDatabaseComponent(database, cleaner,
shutdown); shutdown);
@@ -918,7 +922,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
// The message is stored // The message is stored
oneOf(database).addPrivateMessage(txn, privateMessage, contactId); oneOf(database).addPrivateMessage(txn, privateMessage, contactId);
will(returnValue(true)); will(returnValue(true));
oneOf(database).setStatus(txn, contactId, messageId, Status.SEEN); oneOf(database).setStatus(txn, contactId, messageId, SEEN);
// The message must be acked // The message must be acked
oneOf(database).addMessageToAck(txn, contactId, messageId); oneOf(database).addMessageToAck(txn, contactId, messageId);
}}); }});
@@ -1007,7 +1011,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
// The message is stored, but it's a duplicate // The message is stored, but it's a duplicate
oneOf(database).addGroupMessage(txn, message); oneOf(database).addGroupMessage(txn, message);
will(returnValue(false)); will(returnValue(false));
oneOf(database).setStatus(txn, contactId, messageId, Status.SEEN); oneOf(database).setStatus(txn, contactId, messageId, SEEN);
// The message must be acked // The message must be acked
oneOf(database).addMessageToAck(txn, contactId, messageId); oneOf(database).addMessageToAck(txn, contactId, messageId);
}}); }});
@@ -1039,13 +1043,13 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
// The message is stored, and it's not a duplicate // The message is stored, and it's not a duplicate
oneOf(database).addGroupMessage(txn, message); oneOf(database).addGroupMessage(txn, message);
will(returnValue(true)); will(returnValue(true));
oneOf(database).setStatus(txn, contactId, messageId, Status.SEEN); oneOf(database).setStatus(txn, contactId, messageId, SEEN);
// Set the status to NEW for all other contacts (there are none) // Set the status to NEW for all other contacts (there are none)
oneOf(database).getContacts(txn); oneOf(database).getContacts(txn);
will(returnValue(Collections.singletonList(contactId))); will(returnValue(Collections.singletonList(contactId)));
// Calculate the sendability - zero, so ancestors aren't updated // Calculate the sendability - zero, so ancestors aren't updated
oneOf(database).getRating(txn, authorId); oneOf(database).getRating(txn, authorId);
will(returnValue(Rating.UNRATED)); will(returnValue(UNRATED));
oneOf(database).getNumberOfSendableChildren(txn, messageId); oneOf(database).getNumberOfSendableChildren(txn, messageId);
will(returnValue(0)); will(returnValue(0));
oneOf(database).setSendability(txn, messageId, 0); oneOf(database).setSendability(txn, messageId, 0);
@@ -1081,13 +1085,13 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
// The message is stored, and it's not a duplicate // The message is stored, and it's not a duplicate
oneOf(database).addGroupMessage(txn, message); oneOf(database).addGroupMessage(txn, message);
will(returnValue(true)); will(returnValue(true));
oneOf(database).setStatus(txn, contactId, messageId, Status.SEEN); oneOf(database).setStatus(txn, contactId, messageId, SEEN);
// Set the status to NEW for all other contacts (there are none) // Set the status to NEW for all other contacts (there are none)
oneOf(database).getContacts(txn); oneOf(database).getContacts(txn);
will(returnValue(Collections.singletonList(contactId))); will(returnValue(Collections.singletonList(contactId)));
// Calculate the sendability - ancestors are updated // Calculate the sendability - ancestors are updated
oneOf(database).getRating(txn, authorId); oneOf(database).getRating(txn, authorId);
will(returnValue(Rating.GOOD)); will(returnValue(GOOD));
oneOf(database).getNumberOfSendableChildren(txn, messageId); oneOf(database).getNumberOfSendableChildren(txn, messageId);
will(returnValue(1)); will(returnValue(1));
oneOf(database).setSendability(txn, messageId, 2); oneOf(database).setSendability(txn, messageId, 2);
@@ -1210,9 +1214,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
will(returnValue(true)); will(returnValue(true));
oneOf(database).getContacts(txn); oneOf(database).getContacts(txn);
will(returnValue(Collections.singletonList(contactId))); will(returnValue(Collections.singletonList(contactId)));
oneOf(database).setStatus(txn, contactId, messageId, Status.NEW); oneOf(database).setStatus(txn, contactId, messageId, NEW);
oneOf(database).getRating(txn, authorId); oneOf(database).getRating(txn, authorId);
will(returnValue(Rating.UNRATED)); will(returnValue(UNRATED));
oneOf(database).getNumberOfSendableChildren(txn, messageId); oneOf(database).getNumberOfSendableChildren(txn, messageId);
will(returnValue(0)); will(returnValue(0));
oneOf(database).setSendability(txn, messageId, 0); oneOf(database).setSendability(txn, messageId, 0);
@@ -1246,7 +1250,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
// addLocalPrivateMessage(privateMessage, contactId) // addLocalPrivateMessage(privateMessage, contactId)
oneOf(database).addPrivateMessage(txn, privateMessage, contactId); oneOf(database).addPrivateMessage(txn, privateMessage, contactId);
will(returnValue(true)); will(returnValue(true));
oneOf(database).setStatus(txn, contactId, messageId, Status.NEW); oneOf(database).setStatus(txn, contactId, messageId, NEW);
// The message was added, so the listener should be called // The message was added, so the listener should be called
oneOf(listener).eventOccurred(with(any(MessageAddedEvent.class))); oneOf(listener).eventOccurred(with(any(MessageAddedEvent.class)));
}}); }});

View File

@@ -1,6 +1,11 @@
package net.sf.briar.db; package net.sf.briar.db;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static net.sf.briar.api.Rating.GOOD;
import static net.sf.briar.api.Rating.UNRATED;
import static net.sf.briar.db.Status.NEW;
import static net.sf.briar.db.Status.SEEN;
import static net.sf.briar.db.Status.SENT;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import java.io.File; import java.io.File;
@@ -22,7 +27,6 @@ import net.sf.briar.TestDatabaseConfig;
import net.sf.briar.TestMessage; import net.sf.briar.TestMessage;
import net.sf.briar.TestUtils; import net.sf.briar.TestUtils;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
import net.sf.briar.api.Rating;
import net.sf.briar.api.TransportConfig; import net.sf.briar.api.TransportConfig;
import net.sf.briar.api.TransportProperties; import net.sf.briar.api.TransportProperties;
import net.sf.briar.api.db.DbException; import net.sf.briar.api.db.DbException;
@@ -173,11 +177,11 @@ public class H2DatabaseTest extends BriarTestCase {
Connection txn = db.startTransaction(); Connection txn = db.startTransaction();
// Unknown authors should be unrated // Unknown authors should be unrated
assertEquals(Rating.UNRATED, db.getRating(txn, authorId)); assertEquals(UNRATED, db.getRating(txn, authorId));
// Store a rating // Store a rating
db.setRating(txn, authorId, Rating.GOOD); db.setRating(txn, authorId, GOOD);
// Check that the rating was stored // Check that the rating was stored
assertEquals(Rating.GOOD, db.getRating(txn, authorId)); assertEquals(GOOD, db.getRating(txn, authorId));
db.commitTransaction(txn); db.commitTransaction(txn);
db.close(); db.close();
@@ -236,7 +240,7 @@ public class H2DatabaseTest extends BriarTestCase {
assertFalse(it.hasNext()); assertFalse(it.hasNext());
// Changing the status to NEW should make the message sendable // Changing the status to NEW should make the message sendable
db.setStatus(txn, contactId, messageId1, Status.NEW); db.setStatus(txn, contactId, messageId1, NEW);
assertTrue(db.hasSendableMessages(txn, contactId)); assertTrue(db.hasSendableMessages(txn, contactId));
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator(); it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
assertTrue(it.hasNext()); assertTrue(it.hasNext());
@@ -244,13 +248,13 @@ public class H2DatabaseTest extends BriarTestCase {
assertFalse(it.hasNext()); assertFalse(it.hasNext());
// Changing the status to SENT should make the message unsendable // Changing the status to SENT should make the message unsendable
db.setStatus(txn, contactId, messageId1, Status.SENT); db.setStatus(txn, contactId, messageId1, SENT);
assertFalse(db.hasSendableMessages(txn, contactId)); assertFalse(db.hasSendableMessages(txn, contactId));
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator(); it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
assertFalse(it.hasNext()); assertFalse(it.hasNext());
// Changing the status to SEEN should also make the message unsendable // Changing the status to SEEN should also make the message unsendable
db.setStatus(txn, contactId, messageId1, Status.SEEN); db.setStatus(txn, contactId, messageId1, SEEN);
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator(); it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
assertFalse(it.hasNext()); assertFalse(it.hasNext());
@@ -267,7 +271,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Add a contact and store a private message // Add a contact and store a private message
assertEquals(contactId, db.addContact(txn)); assertEquals(contactId, db.addContact(txn));
db.addPrivateMessage(txn, privateMessage, contactId); db.addPrivateMessage(txn, privateMessage, contactId);
db.setStatus(txn, contactId, messageId1, Status.NEW); db.setStatus(txn, contactId, messageId1, NEW);
// The message is sendable, but too large to send // The message is sendable, but too large to send
assertTrue(db.hasSendableMessages(txn, contactId)); assertTrue(db.hasSendableMessages(txn, contactId));
@@ -298,7 +302,7 @@ public class H2DatabaseTest extends BriarTestCase {
db.addVisibility(txn, contactId, groupId); db.addVisibility(txn, contactId, groupId);
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1); db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// The message should not be sendable // The message should not be sendable
assertFalse(db.hasSendableMessages(txn, contactId)); assertFalse(db.hasSendableMessages(txn, contactId));
@@ -344,8 +348,8 @@ public class H2DatabaseTest extends BriarTestCase {
db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator(); db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
assertFalse(it.hasNext()); assertFalse(it.hasNext());
// Changing the status to Status.NEW should make the message sendable // Changing the status to NEW should make the message sendable
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
assertTrue(db.hasSendableMessages(txn, contactId)); assertTrue(db.hasSendableMessages(txn, contactId));
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator(); it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
assertTrue(it.hasNext()); assertTrue(it.hasNext());
@@ -353,13 +357,13 @@ public class H2DatabaseTest extends BriarTestCase {
assertFalse(it.hasNext()); assertFalse(it.hasNext());
// Changing the status to SENT should make the message unsendable // Changing the status to SENT should make the message unsendable
db.setStatus(txn, contactId, messageId, Status.SENT); db.setStatus(txn, contactId, messageId, SENT);
assertFalse(db.hasSendableMessages(txn, contactId)); assertFalse(db.hasSendableMessages(txn, contactId));
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator(); it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
assertFalse(it.hasNext()); assertFalse(it.hasNext());
// Changing the status to SEEN should also make the message unsendable // Changing the status to SEEN should also make the message unsendable
db.setStatus(txn, contactId, messageId, Status.SEEN); db.setStatus(txn, contactId, messageId, SEEN);
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator(); it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
assertFalse(it.hasNext()); assertFalse(it.hasNext());
@@ -378,7 +382,7 @@ public class H2DatabaseTest extends BriarTestCase {
db.addVisibility(txn, contactId, groupId); db.addVisibility(txn, contactId, groupId);
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
db.setSendability(txn, messageId, 1); db.setSendability(txn, messageId, 1);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// The contact is not subscribed, so the message should not be sendable // The contact is not subscribed, so the message should not be sendable
assertFalse(db.hasSendableMessages(txn, contactId)); assertFalse(db.hasSendableMessages(txn, contactId));
@@ -416,7 +420,7 @@ public class H2DatabaseTest extends BriarTestCase {
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1); db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
db.setSendability(txn, messageId, 1); db.setSendability(txn, messageId, 1);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// The message is sendable, but too large to send // The message is sendable, but too large to send
assertTrue(db.hasSendableMessages(txn, contactId)); assertTrue(db.hasSendableMessages(txn, contactId));
@@ -446,7 +450,7 @@ public class H2DatabaseTest extends BriarTestCase {
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1); db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
db.setSendability(txn, messageId, 1); db.setSendability(txn, messageId, 1);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// The subscription is not visible to the contact, so the message // The subscription is not visible to the contact, so the message
// should not be sendable // should not be sendable
@@ -530,7 +534,7 @@ public class H2DatabaseTest extends BriarTestCase {
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1); db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
db.setSendability(txn, messageId, 1); db.setSendability(txn, messageId, 1);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// Retrieve the message from the database and mark it as sent // Retrieve the message from the database and mark it as sent
Iterator<MessageId> it = Iterator<MessageId> it =
@@ -538,7 +542,7 @@ public class H2DatabaseTest extends BriarTestCase {
assertTrue(it.hasNext()); assertTrue(it.hasNext());
assertEquals(messageId, it.next()); assertEquals(messageId, it.next());
assertFalse(it.hasNext()); assertFalse(it.hasNext());
db.setStatus(txn, contactId, messageId, Status.SENT); db.setStatus(txn, contactId, messageId, SENT);
db.addOutstandingMessages(txn, contactId, db.addOutstandingMessages(txn, contactId,
Collections.singletonList(messageId)); Collections.singletonList(messageId));
@@ -911,7 +915,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Set the sendability to > 0 and the status to SEEN // Set the sendability to > 0 and the status to SEEN
db.setSendability(txn, messageId, 1); db.setSendability(txn, messageId, 1);
db.setStatus(txn, contactId, messageId, Status.SEEN); db.setStatus(txn, contactId, messageId, SEEN);
// The message is not sendable because its status is SEEN // The message is not sendable because its status is SEEN
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId)); assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
@@ -934,7 +938,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Set the sendability to 0 and the status to NEW // Set the sendability to 0 and the status to NEW
db.setSendability(txn, messageId, 0); db.setSendability(txn, messageId, 0);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// The message is not sendable because its sendability is 0 // The message is not sendable because its sendability is 0
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId)); assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
@@ -959,7 +963,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Set the sendability to > 0 and the status to NEW // Set the sendability to > 0 and the status to NEW
db.setSendability(txn, messageId, 1); db.setSendability(txn, messageId, 1);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// The message is not sendable because it's too old // The message is not sendable because it's too old
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId)); assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
@@ -982,7 +986,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Set the sendability to > 0 and the status to NEW // Set the sendability to > 0 and the status to NEW
db.setSendability(txn, messageId, 1); db.setSendability(txn, messageId, 1);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// The message is sendable so it should be returned // The message is sendable so it should be returned
byte[] b = db.getRawMessageIfSendable(txn, contactId, messageId); byte[] b = db.getRawMessageIfSendable(txn, contactId, messageId);
@@ -1038,7 +1042,7 @@ public class H2DatabaseTest extends BriarTestCase {
assertEquals(contactId, db.addContact(txn)); assertEquals(contactId, db.addContact(txn));
db.addSubscription(txn, group); db.addSubscription(txn, group);
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// There's no contact subscription for the group // There's no contact subscription for the group
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId)); assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
@@ -1058,7 +1062,7 @@ public class H2DatabaseTest extends BriarTestCase {
db.addSubscription(txn, group); db.addSubscription(txn, group);
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1); db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
// The subscription is not visible // The subscription is not visible
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId)); assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
@@ -1081,7 +1085,7 @@ public class H2DatabaseTest extends BriarTestCase {
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
// The message has already been seen by the contact // The message has already been seen by the contact
db.setStatus(txn, contactId, messageId, Status.SEEN); db.setStatus(txn, contactId, messageId, SEEN);
assertTrue(db.setStatusSeenIfVisible(txn, contactId, messageId)); assertTrue(db.setStatusSeenIfVisible(txn, contactId, messageId));
@@ -1103,7 +1107,7 @@ public class H2DatabaseTest extends BriarTestCase {
db.addGroupMessage(txn, message); db.addGroupMessage(txn, message);
// The message has not been seen by the contact // The message has not been seen by the contact
db.setStatus(txn, contactId, messageId, Status.NEW); db.setStatus(txn, contactId, messageId, NEW);
assertTrue(db.setStatusSeenIfVisible(txn, contactId, messageId)); assertTrue(db.setStatusSeenIfVisible(txn, contactId, messageId));