mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Effectively final.
This commit is contained in:
@@ -45,7 +45,7 @@ public class AndroidPluginModule {
|
||||
backoffFactory);
|
||||
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
||||
backoffFactory, appContext);
|
||||
final Collection<DuplexPluginFactory> duplex =
|
||||
Collection<DuplexPluginFactory> duplex =
|
||||
Arrays.asList(bluetooth, tor, lan);
|
||||
@NotNullByDefault
|
||||
PluginConfig pluginConfig = new PluginConfig() {
|
||||
|
||||
@@ -285,11 +285,11 @@ class DroidtoothPlugin implements DuplexPlugin, EventListener {
|
||||
Map<ContactId, TransportProperties> remote =
|
||||
callback.getRemoteProperties();
|
||||
for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
|
||||
final ContactId c = e.getKey();
|
||||
ContactId c = e.getKey();
|
||||
if (connected.contains(c)) continue;
|
||||
final String address = e.getValue().get(PROP_ADDRESS);
|
||||
String address = e.getValue().get(PROP_ADDRESS);
|
||||
if (StringUtils.isNullOrEmpty(address)) continue;
|
||||
final String uuid = e.getValue().get(PROP_UUID);
|
||||
String uuid = e.getValue().get(PROP_UUID);
|
||||
if (StringUtils.isNullOrEmpty(uuid)) continue;
|
||||
ioExecutor.execute(() -> {
|
||||
if (!running) return;
|
||||
|
||||
@@ -400,7 +400,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
socket = ss;
|
||||
// Store the port number
|
||||
final String localPort = String.valueOf(ss.getLocalPort());
|
||||
String localPort = String.valueOf(ss.getLocalPort());
|
||||
Settings s = new Settings();
|
||||
s.put(PREF_TOR_PORT, localPort);
|
||||
callback.mergeSettings(s);
|
||||
@@ -536,8 +536,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void connectAndCallBack(final ContactId c,
|
||||
final TransportProperties p) {
|
||||
private void connectAndCallBack(ContactId c, TransportProperties p) {
|
||||
ioExecutor.execute(() -> {
|
||||
if (!isRunning()) return;
|
||||
DuplexTransportConnection d = createConnection(p);
|
||||
|
||||
@@ -48,8 +48,8 @@ public class PoliteExecutor implements Executor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final Runnable r) {
|
||||
final long submitted = System.currentTimeMillis();
|
||||
public void execute(Runnable r) {
|
||||
long submitted = System.currentTimeMillis();
|
||||
Runnable wrapped = () -> {
|
||||
if (log.isLoggable(LOG_LEVEL)) {
|
||||
long queued = System.currentTimeMillis() - submitted;
|
||||
|
||||
@@ -28,9 +28,9 @@ public class TimeLoggingExecutor extends ThreadPoolExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final Runnable r) {
|
||||
public void execute(Runnable r) {
|
||||
if (log.isLoggable(LOG_LEVEL)) {
|
||||
final long submitted = System.currentTimeMillis();
|
||||
long submitted = System.currentTimeMillis();
|
||||
super.execute(() -> {
|
||||
long started = System.currentTimeMillis();
|
||||
long queued = started - submitted;
|
||||
|
||||
@@ -88,7 +88,7 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
executors.add(e);
|
||||
}
|
||||
|
||||
private LocalAuthor createLocalAuthor(final String nickname) {
|
||||
private LocalAuthor createLocalAuthor(String nickname) {
|
||||
long now = System.currentTimeMillis();
|
||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||
byte[] publicKey = keyPair.getPublic().getEncoded();
|
||||
|
||||
@@ -111,7 +111,7 @@ class Poller implements EventListener {
|
||||
connectToContact(c, (DuplexPlugin) p);
|
||||
}
|
||||
|
||||
private void connectToContact(final ContactId c, final SimplexPlugin p) {
|
||||
private void connectToContact(ContactId c, SimplexPlugin p) {
|
||||
ioExecutor.execute(() -> {
|
||||
TransportId t = p.getId();
|
||||
if (!connectionRegistry.isConnected(c, t)) {
|
||||
@@ -122,7 +122,7 @@ class Poller implements EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void connectToContact(final ContactId c, final DuplexPlugin p) {
|
||||
private void connectToContact(ContactId c, DuplexPlugin p) {
|
||||
ioExecutor.execute(() -> {
|
||||
TransportId t = p.getId();
|
||||
if (!connectionRegistry.isConnected(c, t)) {
|
||||
@@ -153,7 +153,7 @@ class Poller implements EventListener {
|
||||
try {
|
||||
PollTask scheduled = tasks.get(t);
|
||||
if (scheduled == null || due < scheduled.due) {
|
||||
final PollTask task = new PollTask(p, due, randomiseNext);
|
||||
PollTask task = new PollTask(p, due, randomiseNext);
|
||||
tasks.put(t, task);
|
||||
scheduler.schedule(
|
||||
() -> ioExecutor.execute(task), delay, MILLISECONDS);
|
||||
@@ -164,7 +164,7 @@ class Poller implements EventListener {
|
||||
}
|
||||
|
||||
@IoExecutor
|
||||
private void poll(final Plugin p) {
|
||||
private void poll(Plugin p) {
|
||||
TransportId t = p.getId();
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Polling plugin " + t);
|
||||
p.poll(connectionRegistry.getConnectedContacts(t));
|
||||
|
||||
@@ -108,7 +108,7 @@ abstract class FilePlugin implements SimplexPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
protected void createReaderFromFile(final File f) {
|
||||
protected void createReaderFromFile(File f) {
|
||||
if (!running) return;
|
||||
ioExecutor.execute(new ReaderCreator(f));
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class PortMapperImpl implements PortMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingResult map(final int port) {
|
||||
public MappingResult map(int port) {
|
||||
if (!started.getAndSet(true)) start();
|
||||
if (gateway == null) return null;
|
||||
InetAddress internal = gateway.getLocalAddress();
|
||||
|
||||
@@ -214,8 +214,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void connectAndCallBack(final ContactId c,
|
||||
final TransportProperties p) {
|
||||
private void connectAndCallBack(ContactId c, TransportProperties p) {
|
||||
ioExecutor.execute(() -> {
|
||||
if (!isRunning()) return;
|
||||
DuplexTransportConnection d = createConnection(p);
|
||||
|
||||
@@ -48,7 +48,7 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
|
||||
@Override
|
||||
public void start() {
|
||||
SlipEncoder encoder = new SlipEncoder(this);
|
||||
final Sender sender = new Sender(clock, encoder);
|
||||
Sender sender = new Sender(clock, encoder);
|
||||
receiver = new Receiver(clock, sender);
|
||||
decoder = new SlipDecoder(receiver, Data.MAX_LENGTH);
|
||||
inputStream = new ReceiverInputStream(receiver);
|
||||
|
||||
@@ -93,7 +93,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
hooks.put(c, hook);
|
||||
}
|
||||
|
||||
private void validateOutstandingMessagesAsync(final ClientId c) {
|
||||
private void validateOutstandingMessagesAsync(ClientId c) {
|
||||
dbExecutor.execute(() -> validateOutstandingMessages(c));
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
}
|
||||
|
||||
private void validateNextMessageAsync(final Queue<MessageId> unvalidated) {
|
||||
private void validateNextMessageAsync(Queue<MessageId> unvalidated) {
|
||||
if (unvalidated.isEmpty()) return;
|
||||
dbExecutor.execute(() -> validateNextMessage(unvalidated));
|
||||
}
|
||||
@@ -148,7 +148,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
}
|
||||
|
||||
private void deliverOutstandingMessagesAsync(final ClientId c) {
|
||||
private void deliverOutstandingMessagesAsync(ClientId c) {
|
||||
dbExecutor.execute(() -> deliverOutstandingMessages(c));
|
||||
}
|
||||
|
||||
@@ -169,8 +169,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
}
|
||||
|
||||
private void deliverNextPendingMessageAsync(
|
||||
final Queue<MessageId> pending) {
|
||||
private void deliverNextPendingMessageAsync(Queue<MessageId> pending) {
|
||||
if (pending.isEmpty()) return;
|
||||
dbExecutor.execute(() -> deliverNextPendingMessage(pending));
|
||||
}
|
||||
@@ -234,7 +233,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
}
|
||||
|
||||
private void validateMessageAsync(final Message m, final Group g) {
|
||||
private void validateMessageAsync(Message m, Group g) {
|
||||
validationExecutor.execute(() -> validateMessage(m, g));
|
||||
}
|
||||
|
||||
@@ -258,8 +257,8 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
}
|
||||
|
||||
private void storeMessageContextAsync(final Message m, final ClientId c,
|
||||
final MessageContext result) {
|
||||
private void storeMessageContextAsync(Message m, ClientId c,
|
||||
MessageContext result) {
|
||||
dbExecutor.execute(() -> storeMessageContext(m, c, result));
|
||||
}
|
||||
|
||||
@@ -354,7 +353,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
return pending;
|
||||
}
|
||||
|
||||
private void shareOutstandingMessagesAsync(final ClientId c) {
|
||||
private void shareOutstandingMessagesAsync(ClientId c) {
|
||||
dbExecutor.execute(() -> shareOutstandingMessages(c));
|
||||
}
|
||||
|
||||
@@ -381,7 +380,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
* This method should only be called for messages that have all their
|
||||
* dependencies delivered and have been delivered themselves.
|
||||
*/
|
||||
private void shareNextMessageAsync(final Queue<MessageId> toShare) {
|
||||
private void shareNextMessageAsync(Queue<MessageId> toShare) {
|
||||
if (toShare.isEmpty()) return;
|
||||
dbExecutor.execute(() -> shareNextMessage(toShare));
|
||||
}
|
||||
@@ -410,7 +409,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidateNextMessageAsync(final Queue<MessageId> invalidate) {
|
||||
private void invalidateNextMessageAsync(Queue<MessageId> invalidate) {
|
||||
if (invalidate.isEmpty()) return;
|
||||
dbExecutor.execute(() -> invalidateNextMessage(invalidate));
|
||||
}
|
||||
@@ -467,12 +466,12 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
}
|
||||
|
||||
private void loadGroupAndValidateAsync(final Message m) {
|
||||
private void loadGroupAndValidateAsync(Message m) {
|
||||
dbExecutor.execute(() -> loadGroupAndValidate(m));
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
private void loadGroupAndValidate(final Message m) {
|
||||
private void loadGroupAndValidate(Message m) {
|
||||
try {
|
||||
Group g;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
|
||||
@@ -155,7 +155,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void removeContact(final ContactId c) {
|
||||
private void removeContact(ContactId c) {
|
||||
activeContacts.remove(c);
|
||||
dbExecutor.execute(() -> {
|
||||
for (TransportKeyManager m : managers.values()) m.removeContact(c);
|
||||
|
||||
@@ -24,10 +24,10 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
||||
Executor delegate = Executors.newSingleThreadExecutor();
|
||||
// Allow all the tasks to be delegated straight away
|
||||
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, TASKS * 2);
|
||||
final List<Integer> list = new Vector<>();
|
||||
final CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
List<Integer> list = new Vector<>();
|
||||
CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
for (int i = 0; i < TASKS; i++) {
|
||||
final int result = i;
|
||||
int result = i;
|
||||
polite.execute(() -> {
|
||||
list.add(result);
|
||||
latch.countDown();
|
||||
@@ -46,10 +46,10 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
||||
Executor delegate = Executors.newSingleThreadExecutor();
|
||||
// Allow two tasks to be delegated at a time
|
||||
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, 2);
|
||||
final List<Integer> list = new Vector<>();
|
||||
final CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
List<Integer> list = new Vector<>();
|
||||
CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
for (int i = 0; i < TASKS; i++) {
|
||||
final int result = i;
|
||||
int result = i;
|
||||
polite.execute(() -> {
|
||||
list.add(result);
|
||||
latch.countDown();
|
||||
@@ -67,11 +67,11 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
||||
Executor delegate = Executors.newCachedThreadPool();
|
||||
// Allow all the tasks to be delegated straight away
|
||||
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, TASKS * 2);
|
||||
final List<Integer> list = new Vector<>();
|
||||
final CountDownLatch[] latches = new CountDownLatch[TASKS];
|
||||
List<Integer> list = new Vector<>();
|
||||
CountDownLatch[] latches = new CountDownLatch[TASKS];
|
||||
for (int i = 0; i < TASKS; i++) latches[i] = new CountDownLatch(1);
|
||||
for (int i = 0; i < TASKS; i++) {
|
||||
final int result = i;
|
||||
int result = i;
|
||||
polite.execute(() -> {
|
||||
try {
|
||||
// Each task waits for the next task, if any, to finish
|
||||
@@ -95,10 +95,10 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
||||
Executor delegate = Executors.newCachedThreadPool();
|
||||
// Allow one task to be delegated at a time
|
||||
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, 1);
|
||||
final List<Integer> list = new Vector<>();
|
||||
final CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
List<Integer> list = new Vector<>();
|
||||
CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
for (int i = 0; i < TASKS; i++) {
|
||||
final int result = i;
|
||||
int result = i;
|
||||
polite.execute(() -> {
|
||||
try {
|
||||
// Each task runs faster than the previous task
|
||||
|
||||
@@ -83,9 +83,9 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
|
||||
|
||||
@Test(expected = InvalidMessageException.class)
|
||||
public void testRejectsTooShortMessage() throws Exception {
|
||||
final byte[] invalidRaw = new byte[MESSAGE_HEADER_LENGTH];
|
||||
byte[] invalidRaw = new byte[MESSAGE_HEADER_LENGTH];
|
||||
// Use a mock message so the length of the raw message can be invalid
|
||||
final Message invalidMessage = context.mock(Message.class);
|
||||
Message invalidMessage = context.mock(Message.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(invalidMessage).getTimestamp();
|
||||
@@ -101,8 +101,8 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
|
||||
|
||||
@Test
|
||||
public void testAcceptsMinLengthMessage() throws Exception {
|
||||
final byte[] shortRaw = new byte[MESSAGE_HEADER_LENGTH + 1];
|
||||
final Message shortMessage =
|
||||
byte[] shortRaw = new byte[MESSAGE_HEADER_LENGTH + 1];
|
||||
Message shortMessage =
|
||||
new Message(messageId, groupId, timestamp, shortRaw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -76,8 +76,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalMessage() throws Exception {
|
||||
final boolean shared = true;
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
boolean shared = true;
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -95,7 +95,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreateMessage() throws Exception {
|
||||
final byte[] bytes = expectToByteArray(list);
|
||||
byte[] bytes = expectToByteArray(list);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageFactory).createMessage(groupId, timestamp, bytes);
|
||||
@@ -107,7 +107,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetMessageAsList() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
|
||||
expectToList(true);
|
||||
context.checking(new Expectations() {{
|
||||
@@ -125,7 +125,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetGroupMetadataAsDictionary() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
@@ -145,7 +145,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetMessageMetadataAsDictionary() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
@@ -165,9 +165,9 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetMessageMetadataAsDictionaryMap() throws Exception {
|
||||
final Map<MessageId, BdfDictionary> map = new HashMap<>();
|
||||
Map<MessageId, BdfDictionary> map = new HashMap<>();
|
||||
map.put(messageId, dictionary);
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
@@ -187,13 +187,13 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetMessageMetadataAsDictionaryQuery() throws Exception {
|
||||
final Map<MessageId, BdfDictionary> map = new HashMap<>();
|
||||
Map<MessageId, BdfDictionary> map = new HashMap<>();
|
||||
map.put(messageId, dictionary);
|
||||
final BdfDictionary query =
|
||||
BdfDictionary query =
|
||||
BdfDictionary.of(new BdfEntry("query", "me"));
|
||||
final Metadata queryMetadata = new Metadata();
|
||||
Metadata queryMetadata = new Metadata();
|
||||
queryMetadata.put("query", getRandomBytes(42));
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
@@ -215,7 +215,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testMergeGroupMetadata() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -233,7 +233,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testMergeMessageMetadata() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -280,10 +280,10 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testSign() throws Exception {
|
||||
final byte[] privateKey = getRandomBytes(42);
|
||||
final byte[] signed = getRandomBytes(42);
|
||||
byte[] privateKey = getRandomBytes(42);
|
||||
byte[] signed = getRandomBytes(42);
|
||||
|
||||
final byte[] bytes = expectToByteArray(list);
|
||||
byte[] bytes = expectToByteArray(list);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(cryptoComponent).sign(label, bytes, privateKey);
|
||||
will(returnValue(signed));
|
||||
@@ -295,8 +295,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testVerifySignature() throws Exception {
|
||||
final byte[] publicKey = getRandomBytes(42);
|
||||
final byte[] bytes = expectToByteArray(list);
|
||||
byte[] publicKey = getRandomBytes(42);
|
||||
byte[] bytes = expectToByteArray(list);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(cryptoComponent).verify(label, bytes, publicKey, rawMessage);
|
||||
@@ -309,8 +309,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testVerifyWrongSignature() throws Exception {
|
||||
final byte[] publicKey = getRandomBytes(42);
|
||||
final byte[] bytes = expectToByteArray(list);
|
||||
byte[] publicKey = getRandomBytes(42);
|
||||
byte[] bytes = expectToByteArray(list);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(cryptoComponent).verify(label, bytes, publicKey, rawMessage);
|
||||
@@ -327,8 +327,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] expectToByteArray(final BdfList list) throws Exception {
|
||||
final BdfWriter bdfWriter = context.mock(BdfWriter.class);
|
||||
private byte[] expectToByteArray(BdfList list) throws Exception {
|
||||
BdfWriter bdfWriter = context.mock(BdfWriter.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(bdfWriterFactory)
|
||||
@@ -339,8 +339,8 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
private void expectToList(final boolean eof) throws Exception {
|
||||
final BdfReader bdfReader = context.mock(BdfReader.class);
|
||||
private void expectToList(boolean eof) throws Exception {
|
||||
BdfReader bdfReader = context.mock(BdfReader.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(bdfReaderFactory)
|
||||
|
||||
@@ -46,10 +46,10 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddContact() throws Exception {
|
||||
final SecretKey master = getSecretKey();
|
||||
final long timestamp = 42;
|
||||
final boolean alice = true;
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
SecretKey master = getSecretKey();
|
||||
long timestamp = 42;
|
||||
boolean alice = true;
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -64,14 +64,13 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
|
||||
assertEquals(contactId, contactManager
|
||||
.addContact(remote, local, master, timestamp, alice, verified,
|
||||
active));
|
||||
assertEquals(contactId, contactManager.addContact(remote, local,
|
||||
master, timestamp, alice, verified, active));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContact() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -86,8 +85,8 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetContactByAuthor() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Collection<Contact> contacts = Collections.singleton(contact);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Collection<Contact> contacts = Collections.singleton(contact);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -102,7 +101,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test(expected = NoSuchContactException.class)
|
||||
public void testGetContactByUnknownAuthor() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -116,8 +115,8 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test(expected = NoSuchContactException.class)
|
||||
public void testGetContactByUnknownLocalAuthor() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Collection<Contact> contacts = Collections.singleton(contact);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Collection<Contact> contacts = Collections.singleton(contact);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -132,9 +131,9 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testActiveContacts() throws Exception {
|
||||
Collection<Contact> activeContacts = Collections.singletonList(contact);
|
||||
final Collection<Contact> contacts = new ArrayList<>(activeContacts);
|
||||
Collection<Contact> contacts = new ArrayList<>(activeContacts);
|
||||
contacts.add(new Contact(new ContactId(3), remote, local, true, false));
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -149,7 +148,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemoveContact() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
will(returnValue(txn));
|
||||
@@ -165,7 +164,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testSetContactActive() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).setContactActive(txn, contactId, active);
|
||||
}});
|
||||
@@ -175,7 +174,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testContactExists() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
|
||||
@@ -127,11 +127,11 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSimpleCalls() throws Exception {
|
||||
final int shutdownHandle = 12345;
|
||||
int shutdownHandle = 12345;
|
||||
Mockery context = new Mockery();
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// open()
|
||||
oneOf(database).open();
|
||||
@@ -230,9 +230,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -260,9 +260,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testAddLocalMessage() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -303,9 +303,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the contact is in the DB (which it's not)
|
||||
exactly(18).of(database).startTransaction();
|
||||
@@ -509,9 +509,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the pseudonym is in the DB (which it's not)
|
||||
exactly(3).of(database).startTransaction();
|
||||
@@ -561,9 +561,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the group is in the DB (which it's not)
|
||||
exactly(8).of(database).startTransaction();
|
||||
@@ -666,9 +666,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the message is in the DB (which it's not)
|
||||
exactly(11).of(database).startTransaction();
|
||||
@@ -801,9 +801,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
@@ -896,13 +896,13 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGenerateAck() throws Exception {
|
||||
final Collection<MessageId> messagesToAck = Arrays.asList(messageId,
|
||||
Collection<MessageId> messagesToAck = Arrays.asList(messageId,
|
||||
messageId1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -931,14 +931,14 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGenerateBatch() throws Exception {
|
||||
final byte[] raw1 = new byte[size];
|
||||
final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
final Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||
byte[] raw1 = new byte[size];
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -975,13 +975,13 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGenerateOffer() throws Exception {
|
||||
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1013,13 +1013,13 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGenerateRequest() throws Exception {
|
||||
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1048,14 +1048,14 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGenerateRequestedBatch() throws Exception {
|
||||
final byte[] raw1 = new byte[size];
|
||||
final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
final Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||
byte[] raw1 = new byte[size];
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1095,9 +1095,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testReceiveAck() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1128,9 +1128,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testReceiveMessage() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1183,9 +1183,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testReceiveDuplicateMessage() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1220,9 +1220,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testReceiveMessageWithoutVisibleGroup() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1248,14 +1248,14 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testReceiveOffer() throws Exception {
|
||||
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
final MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1304,9 +1304,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testReceiveRequest() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1338,9 +1338,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testChangingVisibilityCallsListeners() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1379,9 +1379,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1409,14 +1409,14 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testTransportKeys() throws Exception {
|
||||
final TransportKeys transportKeys = createTransportKeys();
|
||||
final Map<ContactId, TransportKeys> keys = Collections.singletonMap(
|
||||
TransportKeys transportKeys = createTransportKeys();
|
||||
Map<ContactId, TransportKeys> keys = Collections.singletonMap(
|
||||
contactId, transportKeys);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
@@ -1472,19 +1472,19 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testMergeSettings() throws Exception {
|
||||
final Settings before = new Settings();
|
||||
Settings before = new Settings();
|
||||
before.put("foo", "bar");
|
||||
before.put("baz", "bam");
|
||||
final Settings update = new Settings();
|
||||
Settings update = new Settings();
|
||||
update.put("baz", "qux");
|
||||
final Settings merged = new Settings();
|
||||
Settings merged = new Settings();
|
||||
merged.put("foo", "bar");
|
||||
merged.put("baz", "qux");
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
@@ -1547,9 +1547,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
@@ -1572,9 +1572,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testCannotAddLocalIdentityAsContact() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
@@ -1607,9 +1607,9 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
public void testCannotAddDuplicateContact() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
@@ -1643,12 +1643,12 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMessageDependencies() throws Exception {
|
||||
final int shutdownHandle = 12345;
|
||||
int shutdownHandle = 12345;
|
||||
Mockery context = new Mockery();
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
Database<Object> database = context.mock(Database.class);
|
||||
ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
context.checking(new Expectations() {{
|
||||
// open()
|
||||
oneOf(database).open();
|
||||
|
||||
@@ -464,11 +464,11 @@ public class H2DatabaseTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testCloseWaitsForCommit() throws Exception {
|
||||
final CountDownLatch closing = new CountDownLatch(1);
|
||||
final CountDownLatch closed = new CountDownLatch(1);
|
||||
final AtomicBoolean transactionFinished = new AtomicBoolean(false);
|
||||
final AtomicBoolean error = new AtomicBoolean(false);
|
||||
final Database<Connection> db = open(false);
|
||||
CountDownLatch closing = new CountDownLatch(1);
|
||||
CountDownLatch closed = new CountDownLatch(1);
|
||||
AtomicBoolean transactionFinished = new AtomicBoolean(false);
|
||||
AtomicBoolean error = new AtomicBoolean(false);
|
||||
Database<Connection> db = open(false);
|
||||
|
||||
// Start a transaction
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -501,11 +501,11 @@ public class H2DatabaseTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testCloseWaitsForAbort() throws Exception {
|
||||
final CountDownLatch closing = new CountDownLatch(1);
|
||||
final CountDownLatch closed = new CountDownLatch(1);
|
||||
final AtomicBoolean transactionFinished = new AtomicBoolean(false);
|
||||
final AtomicBoolean error = new AtomicBoolean(false);
|
||||
final Database<Connection> db = open(false);
|
||||
CountDownLatch closing = new CountDownLatch(1);
|
||||
CountDownLatch closed = new CountDownLatch(1);
|
||||
AtomicBoolean transactionFinished = new AtomicBoolean(false);
|
||||
AtomicBoolean error = new AtomicBoolean(false);
|
||||
Database<Connection> db = open(false);
|
||||
|
||||
// Start a transaction
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
@@ -17,11 +17,11 @@ public class LockFairnessTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testReadersCanShareTheLock() throws Exception {
|
||||
// Use a fair lock
|
||||
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
|
||||
final CountDownLatch firstReaderHasLock = new CountDownLatch(1);
|
||||
final CountDownLatch firstReaderHasFinished = new CountDownLatch(1);
|
||||
final CountDownLatch secondReaderHasLock = new CountDownLatch(1);
|
||||
final CountDownLatch secondReaderHasFinished = new CountDownLatch(1);
|
||||
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
|
||||
CountDownLatch firstReaderHasLock = new CountDownLatch(1);
|
||||
CountDownLatch firstReaderHasFinished = new CountDownLatch(1);
|
||||
CountDownLatch secondReaderHasLock = new CountDownLatch(1);
|
||||
CountDownLatch secondReaderHasFinished = new CountDownLatch(1);
|
||||
// First reader
|
||||
Thread first = new Thread() {
|
||||
@Override
|
||||
@@ -76,13 +76,13 @@ public class LockFairnessTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testWritersDoNotStarve() throws Exception {
|
||||
// Use a fair lock
|
||||
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
|
||||
final CountDownLatch firstReaderHasLock = new CountDownLatch(1);
|
||||
final CountDownLatch firstReaderHasFinished = new CountDownLatch(1);
|
||||
final CountDownLatch secondReaderHasFinished = new CountDownLatch(1);
|
||||
final CountDownLatch writerHasFinished = new CountDownLatch(1);
|
||||
final AtomicBoolean secondReaderHasHeldLock = new AtomicBoolean(false);
|
||||
final AtomicBoolean writerHasHeldLock = new AtomicBoolean(false);
|
||||
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
|
||||
CountDownLatch firstReaderHasLock = new CountDownLatch(1);
|
||||
CountDownLatch firstReaderHasFinished = new CountDownLatch(1);
|
||||
CountDownLatch secondReaderHasFinished = new CountDownLatch(1);
|
||||
CountDownLatch writerHasFinished = new CountDownLatch(1);
|
||||
AtomicBoolean secondReaderHasHeldLock = new AtomicBoolean(false);
|
||||
AtomicBoolean writerHasHeldLock = new AtomicBoolean(false);
|
||||
// First reader
|
||||
Thread first = new Thread() {
|
||||
@Override
|
||||
|
||||
@@ -80,8 +80,8 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetAuthorStatus() throws DbException {
|
||||
final AuthorId authorId = new AuthorId(TestUtils.getRandomId());
|
||||
final Collection<Contact> contacts = new ArrayList<>();
|
||||
AuthorId authorId = new AuthorId(TestUtils.getRandomId());
|
||||
Collection<Contact> contacts = new ArrayList<>();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
@@ -125,8 +125,8 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
identityManager.getAuthorStatus(localAuthor.getId()));
|
||||
}
|
||||
|
||||
private void checkAuthorStatusContext(final AuthorId authorId,
|
||||
final Collection<Contact> contacts) throws DbException {
|
||||
private void checkAuthorStatusContext(AuthorId authorId,
|
||||
Collection<Contact> contacts) throws DbException {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
|
||||
@@ -65,11 +65,11 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testAliceProtocol() throws Exception {
|
||||
// set up
|
||||
final Payload theirPayload = new Payload(BOB_COMMIT, null);
|
||||
final Payload ourPayload = new Payload(ALICE_COMMIT, null);
|
||||
final KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
final SecretKey sharedSecret = TestUtils.getSecretKey();
|
||||
final SecretKey masterSecret = TestUtils.getSecretKey();
|
||||
Payload theirPayload = new Payload(BOB_COMMIT, null);
|
||||
Payload ourPayload = new Payload(ALICE_COMMIT, null);
|
||||
KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
SecretKey sharedSecret = TestUtils.getSecretKey();
|
||||
SecretKey masterSecret = TestUtils.getSecretKey();
|
||||
|
||||
KeyAgreementProtocol protocol =
|
||||
new KeyAgreementProtocol(callbacks, crypto, payloadEncoder,
|
||||
@@ -129,11 +129,11 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testBobProtocol() throws Exception {
|
||||
// set up
|
||||
final Payload theirPayload = new Payload(ALICE_COMMIT, null);
|
||||
final Payload ourPayload = new Payload(BOB_COMMIT, null);
|
||||
final KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
final SecretKey sharedSecret = TestUtils.getSecretKey();
|
||||
final SecretKey masterSecret = TestUtils.getSecretKey();
|
||||
Payload theirPayload = new Payload(ALICE_COMMIT, null);
|
||||
Payload ourPayload = new Payload(BOB_COMMIT, null);
|
||||
KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
SecretKey sharedSecret = TestUtils.getSecretKey();
|
||||
SecretKey masterSecret = TestUtils.getSecretKey();
|
||||
|
||||
KeyAgreementProtocol protocol =
|
||||
new KeyAgreementProtocol(callbacks, crypto, payloadEncoder,
|
||||
@@ -192,9 +192,9 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
||||
@Test(expected = AbortException.class)
|
||||
public void testAliceProtocolAbortOnBadKey() throws Exception {
|
||||
// set up
|
||||
final Payload theirPayload = new Payload(BOB_COMMIT, null);
|
||||
final Payload ourPayload = new Payload(ALICE_COMMIT, null);
|
||||
final KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
Payload theirPayload = new Payload(BOB_COMMIT, null);
|
||||
Payload ourPayload = new Payload(ALICE_COMMIT, null);
|
||||
KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
|
||||
KeyAgreementProtocol protocol =
|
||||
new KeyAgreementProtocol(callbacks, crypto, payloadEncoder,
|
||||
@@ -233,9 +233,9 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
||||
@Test(expected = AbortException.class)
|
||||
public void testBobProtocolAbortOnBadKey() throws Exception {
|
||||
// set up
|
||||
final Payload theirPayload = new Payload(ALICE_COMMIT, null);
|
||||
final Payload ourPayload = new Payload(BOB_COMMIT, null);
|
||||
final KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
Payload theirPayload = new Payload(ALICE_COMMIT, null);
|
||||
Payload ourPayload = new Payload(BOB_COMMIT, null);
|
||||
KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
|
||||
KeyAgreementProtocol protocol =
|
||||
new KeyAgreementProtocol(callbacks, crypto, payloadEncoder,
|
||||
@@ -270,10 +270,10 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
||||
@Test(expected = AbortException.class)
|
||||
public void testAliceProtocolAbortOnBadConfirm() throws Exception {
|
||||
// set up
|
||||
final Payload theirPayload = new Payload(BOB_COMMIT, null);
|
||||
final Payload ourPayload = new Payload(ALICE_COMMIT, null);
|
||||
final KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
final SecretKey sharedSecret = TestUtils.getSecretKey();
|
||||
Payload theirPayload = new Payload(BOB_COMMIT, null);
|
||||
Payload ourPayload = new Payload(ALICE_COMMIT, null);
|
||||
KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
SecretKey sharedSecret = TestUtils.getSecretKey();
|
||||
|
||||
KeyAgreementProtocol protocol =
|
||||
new KeyAgreementProtocol(callbacks, crypto, payloadEncoder,
|
||||
@@ -335,10 +335,10 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
||||
@Test(expected = AbortException.class)
|
||||
public void testBobProtocolAbortOnBadConfirm() throws Exception {
|
||||
// set up
|
||||
final Payload theirPayload = new Payload(ALICE_COMMIT, null);
|
||||
final Payload ourPayload = new Payload(BOB_COMMIT, null);
|
||||
final KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
final SecretKey sharedSecret = TestUtils.getSecretKey();
|
||||
Payload theirPayload = new Payload(ALICE_COMMIT, null);
|
||||
Payload ourPayload = new Payload(BOB_COMMIT, null);
|
||||
KeyPair ourKeyPair = new KeyPair(ourPubKey, null);
|
||||
SecretKey sharedSecret = TestUtils.getSecretKey();
|
||||
|
||||
KeyAgreementProtocol protocol =
|
||||
new KeyAgreementProtocol(callbacks, crypto, payloadEncoder,
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ConnectionRegistryImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testRegisterAndUnregister() {
|
||||
Mockery context = new Mockery();
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
exactly(5).of(eventBus).broadcast(with(any(
|
||||
ConnectionOpenedEvent.class)));
|
||||
|
||||
@@ -30,36 +30,36 @@ public class PluginManagerImplTest extends BrambleTestCase {
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor ioExecutor = Executors.newSingleThreadExecutor();
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final PluginConfig pluginConfig = context.mock(PluginConfig.class);
|
||||
final ConnectionManager connectionManager =
|
||||
Executor ioExecutor = Executors.newSingleThreadExecutor();
|
||||
EventBus eventBus = context.mock(EventBus.class);
|
||||
PluginConfig pluginConfig = context.mock(PluginConfig.class);
|
||||
ConnectionManager connectionManager =
|
||||
context.mock(ConnectionManager.class);
|
||||
final SettingsManager settingsManager =
|
||||
SettingsManager settingsManager =
|
||||
context.mock(SettingsManager.class);
|
||||
final TransportPropertyManager transportPropertyManager =
|
||||
TransportPropertyManager transportPropertyManager =
|
||||
context.mock(TransportPropertyManager.class);
|
||||
final UiCallback uiCallback = context.mock(UiCallback.class);
|
||||
UiCallback uiCallback = context.mock(UiCallback.class);
|
||||
|
||||
// Two simplex plugin factories: both create plugins, one fails to start
|
||||
final SimplexPluginFactory simplexFactory =
|
||||
SimplexPluginFactory simplexFactory =
|
||||
context.mock(SimplexPluginFactory.class);
|
||||
final SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||
final TransportId simplexId = new TransportId("simplex");
|
||||
final SimplexPluginFactory simplexFailFactory =
|
||||
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||
TransportId simplexId = new TransportId("simplex");
|
||||
SimplexPluginFactory simplexFailFactory =
|
||||
context.mock(SimplexPluginFactory.class, "simplexFailFactory");
|
||||
final SimplexPlugin simplexFailPlugin =
|
||||
SimplexPlugin simplexFailPlugin =
|
||||
context.mock(SimplexPlugin.class, "simplexFailPlugin");
|
||||
final TransportId simplexFailId = new TransportId("simplex1");
|
||||
TransportId simplexFailId = new TransportId("simplex1");
|
||||
|
||||
// Two duplex plugin factories: one creates a plugin, the other fails
|
||||
final DuplexPluginFactory duplexFactory =
|
||||
DuplexPluginFactory duplexFactory =
|
||||
context.mock(DuplexPluginFactory.class);
|
||||
final DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||
final TransportId duplexId = new TransportId("duplex");
|
||||
final DuplexPluginFactory duplexFailFactory =
|
||||
DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||
TransportId duplexId = new TransportId("duplex");
|
||||
DuplexPluginFactory duplexFailFactory =
|
||||
context.mock(DuplexPluginFactory.class, "duplexFailFactory");
|
||||
final TransportId duplexFailId = new TransportId("duplex1");
|
||||
TransportId duplexFailId = new TransportId("duplex1");
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(simplexPlugin).getId();
|
||||
|
||||
@@ -42,35 +42,35 @@ public class PollerTest extends BrambleTestCase {
|
||||
public void testConnectOnContactStatusChanged() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||
final Executor ioExecutor = new ImmediateExecutor();
|
||||
final ScheduledExecutorService scheduler =
|
||||
Executor ioExecutor = new ImmediateExecutor();
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final ConnectionManager connectionManager =
|
||||
ConnectionManager connectionManager =
|
||||
context.mock(ConnectionManager.class);
|
||||
final ConnectionRegistry connectionRegistry =
|
||||
ConnectionRegistry connectionRegistry =
|
||||
context.mock(ConnectionRegistry.class);
|
||||
final PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
final SecureRandom random = context.mock(SecureRandom.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
SecureRandom random = context.mock(SecureRandom.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
// Two simplex plugins: one supports polling, the other doesn't
|
||||
final SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||
final SimplexPlugin simplexPlugin1 =
|
||||
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||
SimplexPlugin simplexPlugin1 =
|
||||
context.mock(SimplexPlugin.class, "simplexPlugin1");
|
||||
final TransportId simplexId1 = new TransportId("simplex1");
|
||||
final List<SimplexPlugin> simplexPlugins = Arrays.asList(simplexPlugin,
|
||||
TransportId simplexId1 = new TransportId("simplex1");
|
||||
List<SimplexPlugin> simplexPlugins = Arrays.asList(simplexPlugin,
|
||||
simplexPlugin1);
|
||||
final TransportConnectionWriter simplexWriter =
|
||||
TransportConnectionWriter simplexWriter =
|
||||
context.mock(TransportConnectionWriter.class);
|
||||
|
||||
// Two duplex plugins: one supports polling, the other doesn't
|
||||
final DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||
final TransportId duplexId = new TransportId("duplex");
|
||||
final DuplexPlugin duplexPlugin1 =
|
||||
DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||
TransportId duplexId = new TransportId("duplex");
|
||||
DuplexPlugin duplexPlugin1 =
|
||||
context.mock(DuplexPlugin.class, "duplexPlugin1");
|
||||
final List<DuplexPlugin> duplexPlugins = Arrays.asList(duplexPlugin,
|
||||
List<DuplexPlugin> duplexPlugins = Arrays.asList(duplexPlugin,
|
||||
duplexPlugin1);
|
||||
final DuplexTransportConnection duplexConnection =
|
||||
DuplexTransportConnection duplexConnection =
|
||||
context.mock(DuplexTransportConnection.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -129,20 +129,20 @@ public class PollerTest extends BrambleTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||
final Executor ioExecutor = new ImmediateExecutor();
|
||||
final ScheduledExecutorService scheduler =
|
||||
Executor ioExecutor = new ImmediateExecutor();
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final ConnectionManager connectionManager =
|
||||
ConnectionManager connectionManager =
|
||||
context.mock(ConnectionManager.class);
|
||||
final ConnectionRegistry connectionRegistry =
|
||||
ConnectionRegistry connectionRegistry =
|
||||
context.mock(ConnectionRegistry.class);
|
||||
final PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
final SecureRandom random = context.mock(SecureRandom.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
SecureRandom random = context.mock(SecureRandom.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
final TransportId transportId = new TransportId("id");
|
||||
final DuplexTransportConnection duplexConnection =
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
TransportId transportId = new TransportId("id");
|
||||
DuplexTransportConnection duplexConnection =
|
||||
context.mock(DuplexTransportConnection.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -194,19 +194,19 @@ public class PollerTest extends BrambleTestCase {
|
||||
public void testRescheduleOnConnectionOpened() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||
final Executor ioExecutor = new ImmediateExecutor();
|
||||
final ScheduledExecutorService scheduler =
|
||||
Executor ioExecutor = new ImmediateExecutor();
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final ConnectionManager connectionManager =
|
||||
ConnectionManager connectionManager =
|
||||
context.mock(ConnectionManager.class);
|
||||
final ConnectionRegistry connectionRegistry =
|
||||
ConnectionRegistry connectionRegistry =
|
||||
context.mock(ConnectionRegistry.class);
|
||||
final PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
final SecureRandom random = context.mock(SecureRandom.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
SecureRandom random = context.mock(SecureRandom.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
final TransportId transportId = new TransportId("id");
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
TransportId transportId = new TransportId("id");
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
@@ -239,19 +239,19 @@ public class PollerTest extends BrambleTestCase {
|
||||
public void testRescheduleDoesNotReplaceEarlierTask() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||
final Executor ioExecutor = new ImmediateExecutor();
|
||||
final ScheduledExecutorService scheduler =
|
||||
Executor ioExecutor = new ImmediateExecutor();
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final ConnectionManager connectionManager =
|
||||
ConnectionManager connectionManager =
|
||||
context.mock(ConnectionManager.class);
|
||||
final ConnectionRegistry connectionRegistry =
|
||||
ConnectionRegistry connectionRegistry =
|
||||
context.mock(ConnectionRegistry.class);
|
||||
final PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
final SecureRandom random = context.mock(SecureRandom.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
SecureRandom random = context.mock(SecureRandom.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
final TransportId transportId = new TransportId("id");
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
TransportId transportId = new TransportId("id");
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
@@ -299,20 +299,20 @@ public class PollerTest extends BrambleTestCase {
|
||||
public void testPollOnTransportEnabled() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||
final Executor ioExecutor = new ImmediateExecutor();
|
||||
final ScheduledExecutorService scheduler =
|
||||
Executor ioExecutor = new ImmediateExecutor();
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final ConnectionManager connectionManager =
|
||||
ConnectionManager connectionManager =
|
||||
context.mock(ConnectionManager.class);
|
||||
final ConnectionRegistry connectionRegistry =
|
||||
ConnectionRegistry connectionRegistry =
|
||||
context.mock(ConnectionRegistry.class);
|
||||
final PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
final SecureRandom random = context.mock(SecureRandom.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
PluginManager pluginManager = context.mock(PluginManager.class);
|
||||
SecureRandom random = context.mock(SecureRandom.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final Plugin plugin = context.mock(Plugin.class);
|
||||
final TransportId transportId = new TransportId("id");
|
||||
final List<ContactId> connected = Collections.singletonList(contactId);
|
||||
Plugin plugin = context.mock(Plugin.class);
|
||||
TransportId transportId = new TransportId("id");
|
||||
List<ContactId> connected = Collections.singletonList(contactId);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
|
||||
@@ -145,11 +145,11 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
assertEquals(2, split.length);
|
||||
String addrString = split[0];
|
||||
// Listen on the same interface as the plugin
|
||||
final ServerSocket ss = new ServerSocket();
|
||||
ServerSocket ss = new ServerSocket();
|
||||
ss.bind(new InetSocketAddress(addrString, 0), 10);
|
||||
int port = ss.getLocalPort();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final AtomicBoolean error = new AtomicBoolean(false);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicBoolean error = new AtomicBoolean(false);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -239,10 +239,10 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
assertEquals(2, split.length);
|
||||
String addrString = split[0];
|
||||
// Listen on the same interface as the plugin
|
||||
final ServerSocket ss = new ServerSocket();
|
||||
ServerSocket ss = new ServerSocket();
|
||||
ss.bind(new InetSocketAddress(addrString, 0), 10);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final AtomicBoolean error = new AtomicBoolean(false);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicBoolean error = new AtomicBoolean(false);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -87,11 +87,11 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreatesGroupsAtStartup() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Contact contact1 = getContact(true);
|
||||
final Contact contact2 = getContact(true);
|
||||
final List<Contact> contacts = Arrays.asList(contact1, contact2);
|
||||
final Group contactGroup1 = getGroup(), contactGroup2 = getGroup();
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact1 = getContact(true);
|
||||
Contact contact2 = getContact(true);
|
||||
List<Contact> contacts = Arrays.asList(contact1, contact2);
|
||||
Group contactGroup1 = getGroup(), contactGroup2 = getGroup();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).addGroup(txn, localGroup);
|
||||
@@ -124,9 +124,9 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreatesGroupWhenAddingContact() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Contact contact = getContact(true);
|
||||
final Group contactGroup = getGroup();
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Create the group and share it with the contact
|
||||
@@ -151,9 +151,9 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovesGroupWhenRemovingContact() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Contact contact = getContact(true);
|
||||
final Group contactGroup = getGroup();
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
||||
@@ -168,17 +168,17 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testDoesNotDeleteAnythingWhenFirstUpdateIsDelivered()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final GroupId contactGroupId = new GroupId(getRandomId());
|
||||
final long timestamp = 123456789;
|
||||
final Message message = getMessage(contactGroupId, timestamp);
|
||||
final Metadata meta = new Metadata();
|
||||
final BdfDictionary metaDictionary = BdfDictionary.of(
|
||||
Transaction txn = new Transaction(null, false);
|
||||
GroupId contactGroupId = new GroupId(getRandomId());
|
||||
long timestamp = 123456789;
|
||||
Message message = getMessage(contactGroupId, timestamp);
|
||||
Metadata meta = new Metadata();
|
||||
BdfDictionary metaDictionary = BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 2),
|
||||
new BdfEntry("local", false)
|
||||
);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<>();
|
||||
// A remote update for another transport should be ignored
|
||||
MessageId barUpdateId = new MessageId(getRandomId());
|
||||
@@ -210,32 +210,32 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testDeletesOlderUpdatesWhenUpdateIsDelivered()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final GroupId contactGroupId = new GroupId(getRandomId());
|
||||
final long timestamp = 123456789;
|
||||
final Message message = getMessage(contactGroupId, timestamp);
|
||||
final Metadata meta = new Metadata();
|
||||
final BdfDictionary metaDictionary = BdfDictionary.of(
|
||||
Transaction txn = new Transaction(null, false);
|
||||
GroupId contactGroupId = new GroupId(getRandomId());
|
||||
long timestamp = 123456789;
|
||||
Message message = getMessage(contactGroupId, timestamp);
|
||||
Metadata meta = new Metadata();
|
||||
BdfDictionary metaDictionary = BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 4),
|
||||
new BdfEntry("local", false)
|
||||
);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<>();
|
||||
// Old remote updates for the same transport should be deleted
|
||||
final MessageId fooVersion2 = new MessageId(getRandomId());
|
||||
MessageId fooVersion2 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion2, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 2),
|
||||
new BdfEntry("local", false)
|
||||
));
|
||||
final MessageId fooVersion1 = new MessageId(getRandomId());
|
||||
MessageId fooVersion1 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion1, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 1),
|
||||
new BdfEntry("local", false)
|
||||
));
|
||||
final MessageId fooVersion3 = new MessageId(getRandomId());
|
||||
MessageId fooVersion3 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion3, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 3),
|
||||
@@ -263,33 +263,33 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testDeletesObsoleteUpdateWhenDelivered() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final GroupId contactGroupId = new GroupId(getRandomId());
|
||||
final long timestamp = 123456789;
|
||||
final Message message = getMessage(contactGroupId, timestamp);
|
||||
final Metadata meta = new Metadata();
|
||||
final BdfDictionary metaDictionary = BdfDictionary.of(
|
||||
Transaction txn = new Transaction(null, false);
|
||||
GroupId contactGroupId = new GroupId(getRandomId());
|
||||
long timestamp = 123456789;
|
||||
Message message = getMessage(contactGroupId, timestamp);
|
||||
Metadata meta = new Metadata();
|
||||
BdfDictionary metaDictionary = BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 3),
|
||||
new BdfEntry("local", false)
|
||||
);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<>();
|
||||
// Old remote updates for the same transport should be deleted
|
||||
final MessageId fooVersion2 = new MessageId(getRandomId());
|
||||
MessageId fooVersion2 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion2, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 2),
|
||||
new BdfEntry("local", false)
|
||||
));
|
||||
final MessageId fooVersion1 = new MessageId(getRandomId());
|
||||
MessageId fooVersion1 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion1, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 1),
|
||||
new BdfEntry("local", false)
|
||||
));
|
||||
// A newer remote update for the same transport should not be deleted
|
||||
final MessageId fooVersion4 = new MessageId(getRandomId());
|
||||
MessageId fooVersion4 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion4, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 4),
|
||||
@@ -318,9 +318,9 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testStoresRemotePropertiesWithVersion0() throws Exception {
|
||||
final Contact contact = getContact(true);
|
||||
final Group contactGroup = getGroup();
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Map<TransportId, TransportProperties> properties =
|
||||
new LinkedHashMap<>();
|
||||
properties.put(new TransportId("foo"), fooProperties);
|
||||
@@ -357,8 +357,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testReturnsEmptyPropertiesIfNoLocalPropertiesAreFound()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<>();
|
||||
// A local update for another transport should be ignored
|
||||
MessageId barUpdateId = new MessageId(getRandomId());
|
||||
@@ -384,8 +384,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testReturnsLocalProperties() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<>();
|
||||
// A local update for another transport should be ignored
|
||||
MessageId barUpdateId = new MessageId(getRandomId());
|
||||
@@ -395,13 +395,13 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry("local", true)
|
||||
));
|
||||
// A local update for the right transport should be returned
|
||||
final MessageId fooUpdateId = new MessageId(getRandomId());
|
||||
MessageId fooUpdateId = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooUpdateId, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 1),
|
||||
new BdfEntry("local", true)
|
||||
));
|
||||
final BdfList fooUpdate = BdfList.of("foo", 1, fooPropertiesDict);
|
||||
BdfList fooUpdate = BdfList.of("foo", 1, fooPropertiesDict);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -423,15 +423,15 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testReturnsRemotePropertiesOrEmptyProperties()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact1 = getContact(false);
|
||||
final Contact contact2 = getContact(true);
|
||||
final Contact contact3 = getContact(true);
|
||||
final List<Contact> contacts =
|
||||
Contact contact2 = getContact(true);
|
||||
Contact contact3 = getContact(true);
|
||||
List<Contact> contacts =
|
||||
Arrays.asList(contact1, contact2, contact3);
|
||||
final Group contactGroup2 = getGroup();
|
||||
final Group contactGroup3 = getGroup();
|
||||
final Map<MessageId, BdfDictionary> messageMetadata3 =
|
||||
Group contactGroup2 = getGroup();
|
||||
Group contactGroup3 = getGroup();
|
||||
Map<MessageId, BdfDictionary> messageMetadata3 =
|
||||
new LinkedHashMap<>();
|
||||
// A remote update for another transport should be ignored
|
||||
MessageId barUpdateId = new MessageId(getRandomId());
|
||||
@@ -448,13 +448,13 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry("local", true)
|
||||
));
|
||||
// A remote update for the right transport should be returned
|
||||
final MessageId fooUpdateId = new MessageId(getRandomId());
|
||||
MessageId fooUpdateId = new MessageId(getRandomId());
|
||||
messageMetadata3.put(fooUpdateId, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 1),
|
||||
new BdfEntry("local", false)
|
||||
));
|
||||
final BdfList fooUpdate = BdfList.of("foo", 1, fooPropertiesDict);
|
||||
BdfList fooUpdate = BdfList.of("foo", 1, fooPropertiesDict);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -492,15 +492,15 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testMergingUnchangedPropertiesDoesNotCreateUpdate()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final MessageId updateId = new MessageId(getRandomId());
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
Transaction txn = new Transaction(null, false);
|
||||
MessageId updateId = new MessageId(getRandomId());
|
||||
Map<MessageId, BdfDictionary> messageMetadata =
|
||||
Collections.singletonMap(updateId, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 1),
|
||||
new BdfEntry("local", true)
|
||||
));
|
||||
final BdfList update = BdfList.of("foo", 1, fooPropertiesDict);
|
||||
BdfList update = BdfList.of("foo", 1, fooPropertiesDict);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -522,9 +522,9 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testMergingNewPropertiesCreatesUpdate() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Contact contact = getContact(true);
|
||||
final Group contactGroup = getGroup();
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -556,21 +556,21 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testMergingUpdatedPropertiesCreatesUpdate() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Contact contact = getContact(true);
|
||||
final Group contactGroup = getGroup();
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
BdfDictionary oldMetadata = BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 1),
|
||||
new BdfEntry("local", true)
|
||||
);
|
||||
final MessageId localGroupUpdateId = new MessageId(getRandomId());
|
||||
final Map<MessageId, BdfDictionary> localGroupMessageMetadata =
|
||||
MessageId localGroupUpdateId = new MessageId(getRandomId());
|
||||
Map<MessageId, BdfDictionary> localGroupMessageMetadata =
|
||||
Collections.singletonMap(localGroupUpdateId, oldMetadata);
|
||||
final MessageId contactGroupUpdateId = new MessageId(getRandomId());
|
||||
final Map<MessageId, BdfDictionary> contactGroupMessageMetadata =
|
||||
MessageId contactGroupUpdateId = new MessageId(getRandomId());
|
||||
Map<MessageId, BdfDictionary> contactGroupMessageMetadata =
|
||||
Collections.singletonMap(contactGroupUpdateId, oldMetadata);
|
||||
final BdfList oldUpdate = BdfList.of("foo", 1, BdfDictionary.of(
|
||||
BdfList oldUpdate = BdfList.of("foo", 1, BdfDictionary.of(
|
||||
new BdfEntry("fooKey1", "oldFooValue1")
|
||||
));
|
||||
|
||||
@@ -638,36 +638,36 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
return new Message(messageId, g, timestamp, raw);
|
||||
}
|
||||
|
||||
private void expectGetLocalProperties(final Transaction txn)
|
||||
private void expectGetLocalProperties(Transaction txn)
|
||||
throws Exception {
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<>();
|
||||
// The only update for transport "foo" should be returned
|
||||
final MessageId fooVersion999 = new MessageId(getRandomId());
|
||||
MessageId fooVersion999 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion999, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 999)
|
||||
));
|
||||
// An old update for transport "bar" should be deleted
|
||||
final MessageId barVersion2 = new MessageId(getRandomId());
|
||||
MessageId barVersion2 = new MessageId(getRandomId());
|
||||
messageMetadata.put(barVersion2, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "bar"),
|
||||
new BdfEntry("version", 2)
|
||||
));
|
||||
// An even older update for transport "bar" should be deleted
|
||||
final MessageId barVersion1 = new MessageId(getRandomId());
|
||||
MessageId barVersion1 = new MessageId(getRandomId());
|
||||
messageMetadata.put(barVersion1, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "bar"),
|
||||
new BdfEntry("version", 1)
|
||||
));
|
||||
// The latest update for transport "bar" should be returned
|
||||
final MessageId barVersion3 = new MessageId(getRandomId());
|
||||
MessageId barVersion3 = new MessageId(getRandomId());
|
||||
messageMetadata.put(barVersion3, BdfDictionary.of(
|
||||
new BdfEntry("transportId", "bar"),
|
||||
new BdfEntry("version", 3)
|
||||
));
|
||||
final BdfList fooUpdate = BdfList.of("foo", 999, fooPropertiesDict);
|
||||
final BdfList barUpdate = BdfList.of("bar", 3, barPropertiesDict);
|
||||
BdfList fooUpdate = BdfList.of("foo", 999, fooPropertiesDict);
|
||||
BdfList barUpdate = BdfList.of("bar", 3, barPropertiesDict);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Find the latest local update for each transport
|
||||
@@ -684,13 +684,13 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectStoreMessage(final Transaction txn, final GroupId g,
|
||||
String transportId, final BdfDictionary properties, long version,
|
||||
boolean local, final boolean shared) throws Exception {
|
||||
final long timestamp = 123456789;
|
||||
final BdfList body = BdfList.of(transportId, version, properties);
|
||||
final Message message = getMessage(g, timestamp);
|
||||
final BdfDictionary meta = BdfDictionary.of(
|
||||
private void expectStoreMessage(Transaction txn, GroupId g,
|
||||
String transportId, BdfDictionary properties, long version,
|
||||
boolean local, boolean shared) throws Exception {
|
||||
long timestamp = 123456789;
|
||||
BdfList body = BdfList.of(transportId, version, properties);
|
||||
Message message = getMessage(g, timestamp);
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry("transportId", transportId),
|
||||
new BdfEntry("version", version),
|
||||
new BdfEntry("local", local)
|
||||
|
||||
@@ -6,10 +6,10 @@ import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.sync.Ack;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.sync.RecordWriter;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.api.sync.RecordWriter;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.Test;
|
||||
@@ -44,10 +44,10 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testNothingToSend() throws Exception {
|
||||
final SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
dbExecutor, eventBus, contactId, maxLatency, recordWriter);
|
||||
final Transaction noAckTxn = new Transaction(null, false);
|
||||
final Transaction noMsgTxn = new Transaction(null, false);
|
||||
Transaction noAckTxn = new Transaction(null, false);
|
||||
Transaction noMsgTxn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Add listener
|
||||
@@ -80,14 +80,14 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testSomethingToSend() throws Exception {
|
||||
final Ack ack = new Ack(Collections.singletonList(messageId));
|
||||
final byte[] raw = new byte[1234];
|
||||
final SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
Ack ack = new Ack(Collections.singletonList(messageId));
|
||||
byte[] raw = new byte[1234];
|
||||
SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
dbExecutor, eventBus, contactId, maxLatency, recordWriter);
|
||||
final Transaction ackTxn = new Transaction(null, false);
|
||||
final Transaction noAckTxn = new Transaction(null, false);
|
||||
final Transaction msgTxn = new Transaction(null, false);
|
||||
final Transaction noMsgTxn = new Transaction(null, false);
|
||||
Transaction ackTxn = new Transaction(null, false);
|
||||
Transaction noAckTxn = new Transaction(null, false);
|
||||
Transaction msgTxn = new Transaction(null, false);
|
||||
Transaction noMsgTxn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Add listener
|
||||
|
||||
@@ -92,9 +92,9 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testStartAndStop() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, true);
|
||||
final Transaction txn2 = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, true);
|
||||
Transaction txn2 = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// validateOutstandingMessages()
|
||||
@@ -126,13 +126,13 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testMessagesAreValidatedAtStartup() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, true);
|
||||
final Transaction txn2 = new Transaction(null, false);
|
||||
final Transaction txn3 = new Transaction(null, true);
|
||||
final Transaction txn4 = new Transaction(null, false);
|
||||
final Transaction txn5 = new Transaction(null, true);
|
||||
final Transaction txn6 = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, true);
|
||||
Transaction txn2 = new Transaction(null, false);
|
||||
Transaction txn3 = new Transaction(null, true);
|
||||
Transaction txn4 = new Transaction(null, false);
|
||||
Transaction txn5 = new Transaction(null, true);
|
||||
Transaction txn6 = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Get messages to validate
|
||||
@@ -217,11 +217,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testPendingMessagesAreDeliveredAtStartup() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, true);
|
||||
final Transaction txn2 = new Transaction(null, false);
|
||||
final Transaction txn3 = new Transaction(null, false);
|
||||
final Transaction txn4 = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, true);
|
||||
Transaction txn2 = new Transaction(null, false);
|
||||
Transaction txn3 = new Transaction(null, false);
|
||||
Transaction txn4 = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Get messages to validate
|
||||
@@ -303,11 +303,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testMessagesAreSharedAtStartup() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, true);
|
||||
final Transaction txn2 = new Transaction(null, true);
|
||||
final Transaction txn3 = new Transaction(null, false);
|
||||
final Transaction txn4 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, true);
|
||||
Transaction txn2 = new Transaction(null, true);
|
||||
Transaction txn3 = new Transaction(null, false);
|
||||
Transaction txn4 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// No messages to validate
|
||||
@@ -355,9 +355,9 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testIncomingMessagesAreShared() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
final Transaction txn2 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
Transaction txn2 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Load the group
|
||||
@@ -405,12 +405,12 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testValidationContinuesAfterNoSuchMessageException()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, true);
|
||||
final Transaction txn2 = new Transaction(null, true);
|
||||
final Transaction txn3 = new Transaction(null, false);
|
||||
final Transaction txn4 = new Transaction(null, true);
|
||||
final Transaction txn5 = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, true);
|
||||
Transaction txn2 = new Transaction(null, true);
|
||||
Transaction txn3 = new Transaction(null, false);
|
||||
Transaction txn4 = new Transaction(null, true);
|
||||
Transaction txn5 = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Get messages to validate
|
||||
@@ -476,12 +476,12 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testValidationContinuesAfterNoSuchGroupException()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, true);
|
||||
final Transaction txn2 = new Transaction(null, true);
|
||||
final Transaction txn3 = new Transaction(null, false);
|
||||
final Transaction txn4 = new Transaction(null, true);
|
||||
final Transaction txn5 = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, true);
|
||||
Transaction txn2 = new Transaction(null, true);
|
||||
Transaction txn3 = new Transaction(null, false);
|
||||
Transaction txn4 = new Transaction(null, true);
|
||||
Transaction txn5 = new Transaction(null, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Get messages to validate
|
||||
@@ -551,8 +551,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testNonLocalMessagesAreValidatedWhenAdded() throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Load the group
|
||||
@@ -591,8 +591,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testMessagesWithUndeliveredDependenciesArePending()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Load the group
|
||||
@@ -624,8 +624,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testMessagesWithDeliveredDependenciesGetDelivered()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Load the group
|
||||
@@ -663,9 +663,9 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testMessagesWithInvalidDependenciesAreInvalid()
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
final Transaction txn2 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
Transaction txn2 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Load the group
|
||||
@@ -716,18 +716,18 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRecursiveInvalidation() throws Exception {
|
||||
final MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
final MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
||||
final Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
||||
MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
||||
Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
||||
twoDependents.put(messageId1, PENDING);
|
||||
twoDependents.put(messageId2, PENDING);
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
final Transaction txn2 = new Transaction(null, false);
|
||||
final Transaction txn3 = new Transaction(null, false);
|
||||
final Transaction txn4 = new Transaction(null, false);
|
||||
final Transaction txn5 = new Transaction(null, false);
|
||||
final Transaction txn6 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
Transaction txn2 = new Transaction(null, false);
|
||||
Transaction txn3 = new Transaction(null, false);
|
||||
Transaction txn4 = new Transaction(null, false);
|
||||
Transaction txn5 = new Transaction(null, false);
|
||||
Transaction txn6 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Load the group
|
||||
@@ -819,25 +819,25 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testPendingDependentsGetDelivered() throws Exception {
|
||||
final MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
final MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
||||
final Message message3 = new Message(messageId3, groupId, timestamp,
|
||||
MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
||||
Message message3 = new Message(messageId3, groupId, timestamp,
|
||||
raw);
|
||||
final Message message4 = new Message(messageId4, groupId, timestamp,
|
||||
Message message4 = new Message(messageId4, groupId, timestamp,
|
||||
raw);
|
||||
final Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
||||
Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
||||
twoDependents.put(messageId1, PENDING);
|
||||
twoDependents.put(messageId2, PENDING);
|
||||
final Map<MessageId, State> twoDependencies = new LinkedHashMap<>();
|
||||
Map<MessageId, State> twoDependencies = new LinkedHashMap<>();
|
||||
twoDependencies.put(messageId1, DELIVERED);
|
||||
twoDependencies.put(messageId2, DELIVERED);
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
final Transaction txn2 = new Transaction(null, false);
|
||||
final Transaction txn3 = new Transaction(null, false);
|
||||
final Transaction txn4 = new Transaction(null, false);
|
||||
final Transaction txn5 = new Transaction(null, false);
|
||||
final Transaction txn6 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
Transaction txn2 = new Transaction(null, false);
|
||||
Transaction txn3 = new Transaction(null, false);
|
||||
Transaction txn4 = new Transaction(null, false);
|
||||
Transaction txn5 = new Transaction(null, false);
|
||||
Transaction txn6 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Load the group
|
||||
@@ -976,12 +976,12 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testOnlyReadyPendingDependentsGetDelivered() throws Exception {
|
||||
final Map<MessageId, State> twoDependencies = new LinkedHashMap<>();
|
||||
Map<MessageId, State> twoDependencies = new LinkedHashMap<>();
|
||||
twoDependencies.put(messageId, DELIVERED);
|
||||
twoDependencies.put(messageId2, UNKNOWN);
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
final Transaction txn2 = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
Transaction txn2 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Load the group
|
||||
|
||||
@@ -58,21 +58,21 @@ public class KeyManagerImplTest extends BrambleTestCase {
|
||||
|
||||
@Before
|
||||
public void testStartService() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
AuthorId remoteAuthorId = new AuthorId(getRandomId());
|
||||
Author remoteAuthor = new Author(remoteAuthorId, "author",
|
||||
getRandomBytes(42));
|
||||
AuthorId localAuthorId = new AuthorId(getRandomId());
|
||||
final Collection<Contact> contacts = new ArrayList<>();
|
||||
Collection<Contact> contacts = new ArrayList<>();
|
||||
contacts.add(new Contact(contactId, remoteAuthor, localAuthorId, true,
|
||||
true));
|
||||
contacts.add(new Contact(inactiveContactId, remoteAuthor, localAuthorId,
|
||||
true, false));
|
||||
final SimplexPluginFactory pluginFactory =
|
||||
SimplexPluginFactory pluginFactory =
|
||||
context.mock(SimplexPluginFactory.class);
|
||||
final Collection<SimplexPluginFactory> factories = Collections
|
||||
Collection<SimplexPluginFactory> factories = Collections
|
||||
.singletonList(pluginFactory);
|
||||
final int maxLatency = 1337;
|
||||
int maxLatency = 1337;
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(pluginConfig).getSimplexFactories();
|
||||
@@ -100,9 +100,9 @@ public class KeyManagerImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddContact() throws Exception {
|
||||
final SecretKey secretKey = getSecretKey();
|
||||
final long timestamp = 42L;
|
||||
final boolean alice = true;
|
||||
SecretKey secretKey = getSecretKey();
|
||||
long timestamp = 42L;
|
||||
boolean alice = true;
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(transportKeyManager)
|
||||
|
||||
@@ -14,7 +14,7 @@ public class StreamReaderImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testEmptyFramesAreSkipped() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
||||
will(returnValue(0)); // Empty frame
|
||||
@@ -37,7 +37,7 @@ public class StreamReaderImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testEmptyFramesAreSkippedWithBuffer() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
||||
will(returnValue(0)); // Empty frame
|
||||
@@ -63,7 +63,7 @@ public class StreamReaderImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testMultipleReadsPerFrame() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
||||
will(returnValue(MAX_PAYLOAD_LENGTH)); // Nice long frame
|
||||
@@ -85,7 +85,7 @@ public class StreamReaderImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testMultipleReadsPerFrameWithOffsets() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||
StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(decrypter).readFrame(with(any(byte[].class)));
|
||||
will(returnValue(MAX_PAYLOAD_LENGTH)); // Nice long frame
|
||||
|
||||
@@ -14,7 +14,7 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testCloseWithoutWritingWritesFinalFrame() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Write an empty final frame
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
|
||||
@@ -31,7 +31,7 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
||||
public void testFlushWithoutBufferedDataWritesFrameAndFlushes()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||
context.checking(new Expectations() {{
|
||||
// Write a non-final frame with an empty payload
|
||||
@@ -58,7 +58,7 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
||||
public void testFlushWithBufferedDataWritesFrameAndFlushes()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||
context.checking(new Expectations() {{
|
||||
// Write a non-final frame with one payload byte
|
||||
@@ -85,7 +85,7 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testSingleByteWritesWriteFullFrame() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||
context.checking(new Expectations() {{
|
||||
// Write a full non-final frame
|
||||
@@ -109,7 +109,7 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testMultiByteWritesWriteFullFrames() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||
context.checking(new Expectations() {{
|
||||
// Write two full non-final frames
|
||||
@@ -140,7 +140,7 @@ public class StreamWriterImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testLargeMultiByteWriteWritesFullFrames() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
|
||||
StreamWriterImpl w = new StreamWriterImpl(encrypter);
|
||||
context.checking(new Expectations() {{
|
||||
// Write two full non-final frames
|
||||
|
||||
@@ -56,20 +56,20 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testKeysAreRotatedAtStartup() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final Executor dbExecutor = context.mock(Executor.class);
|
||||
final ScheduledExecutorService scheduler =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
Executor dbExecutor = context.mock(Executor.class);
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final Map<ContactId, TransportKeys> loaded = new LinkedHashMap<>();
|
||||
final TransportKeys shouldRotate = createTransportKeys(900, 0);
|
||||
final TransportKeys shouldNotRotate = createTransportKeys(1000, 0);
|
||||
Map<ContactId, TransportKeys> loaded = new LinkedHashMap<>();
|
||||
TransportKeys shouldRotate = createTransportKeys(900, 0);
|
||||
TransportKeys shouldNotRotate = createTransportKeys(1000, 0);
|
||||
loaded.put(contactId, shouldRotate);
|
||||
loaded.put(contactId1, shouldNotRotate);
|
||||
final TransportKeys rotated = createTransportKeys(1000, 0);
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
TransportKeys rotated = createTransportKeys(1000, 0);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Get the current time (1 ms after start of rotation period 1000)
|
||||
@@ -108,17 +108,17 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testKeysAreRotatedWhenAddingContact() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final Executor dbExecutor = context.mock(Executor.class);
|
||||
final ScheduledExecutorService scheduler =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
Executor dbExecutor = context.mock(Executor.class);
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final boolean alice = true;
|
||||
final TransportKeys transportKeys = createTransportKeys(999, 0);
|
||||
final TransportKeys rotated = createTransportKeys(1000, 0);
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
boolean alice = true;
|
||||
TransportKeys transportKeys = createTransportKeys(999, 0);
|
||||
TransportKeys rotated = createTransportKeys(1000, 0);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(crypto).deriveTransportKeys(transportId, masterKey, 999,
|
||||
@@ -155,14 +155,14 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
public void testOutgoingStreamContextIsNullIfContactIsNotFound()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final Executor dbExecutor = context.mock(Executor.class);
|
||||
final ScheduledExecutorService scheduler =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
Executor dbExecutor = context.mock(Executor.class);
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
TransportKeyManager
|
||||
transportKeyManager = new TransportKeyManagerImpl(db,
|
||||
@@ -176,18 +176,18 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
public void testOutgoingStreamContextIsNullIfStreamCounterIsExhausted()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final Executor dbExecutor = context.mock(Executor.class);
|
||||
final ScheduledExecutorService scheduler =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
Executor dbExecutor = context.mock(Executor.class);
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final boolean alice = true;
|
||||
boolean alice = true;
|
||||
// The stream counter has been exhausted
|
||||
final TransportKeys transportKeys = createTransportKeys(1000,
|
||||
TransportKeys transportKeys = createTransportKeys(1000,
|
||||
MAX_32_BIT_UNSIGNED + 1);
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(crypto).deriveTransportKeys(transportId, masterKey, 1000,
|
||||
@@ -224,18 +224,18 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testOutgoingStreamCounterIsIncremented() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final Executor dbExecutor = context.mock(Executor.class);
|
||||
final ScheduledExecutorService scheduler =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
Executor dbExecutor = context.mock(Executor.class);
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final boolean alice = true;
|
||||
boolean alice = true;
|
||||
// The stream counter can be used one more time before being exhausted
|
||||
final TransportKeys transportKeys = createTransportKeys(1000,
|
||||
TransportKeys transportKeys = createTransportKeys(1000,
|
||||
MAX_32_BIT_UNSIGNED);
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(crypto).deriveTransportKeys(transportId, masterKey, 1000,
|
||||
@@ -285,16 +285,16 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
public void testIncomingStreamContextIsNullIfTagIsNotFound()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final Executor dbExecutor = context.mock(Executor.class);
|
||||
final ScheduledExecutorService scheduler =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
Executor dbExecutor = context.mock(Executor.class);
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final boolean alice = true;
|
||||
final TransportKeys transportKeys = createTransportKeys(1000, 0);
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
boolean alice = true;
|
||||
TransportKeys transportKeys = createTransportKeys(1000, 0);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(crypto).deriveTransportKeys(transportId, masterKey, 1000,
|
||||
@@ -332,18 +332,18 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testTagIsNotRecognisedTwice() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final Executor dbExecutor = context.mock(Executor.class);
|
||||
final ScheduledExecutorService scheduler =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
Executor dbExecutor = context.mock(Executor.class);
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final boolean alice = true;
|
||||
final TransportKeys transportKeys = createTransportKeys(1000, 0);
|
||||
boolean alice = true;
|
||||
TransportKeys transportKeys = createTransportKeys(1000, 0);
|
||||
// Keep a copy of the tags
|
||||
final List<byte[]> tags = new ArrayList<>();
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
List<byte[]> tags = new ArrayList<>();
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(crypto).deriveTransportKeys(transportId, masterKey, 1000,
|
||||
@@ -402,19 +402,19 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testKeysAreRotatedToCurrentPeriod() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final Executor dbExecutor = context.mock(Executor.class);
|
||||
final ScheduledExecutorService scheduler =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
Executor dbExecutor = context.mock(Executor.class);
|
||||
ScheduledExecutorService scheduler =
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
Clock clock = context.mock(Clock.class);
|
||||
|
||||
final TransportKeys transportKeys = createTransportKeys(1000, 0);
|
||||
final Map<ContactId, TransportKeys> loaded =
|
||||
TransportKeys transportKeys = createTransportKeys(1000, 0);
|
||||
Map<ContactId, TransportKeys> loaded =
|
||||
Collections.singletonMap(contactId, transportKeys);
|
||||
final TransportKeys rotated = createTransportKeys(1001, 0);
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Transaction txn1 = new Transaction(null, false);
|
||||
TransportKeys rotated = createTransportKeys(1001, 0);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Transaction txn1 = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Get the current time (the start of rotation period 1000)
|
||||
|
||||
@@ -110,7 +110,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
||||
public void run() {
|
||||
try {
|
||||
// Load user32.dll
|
||||
final User32 user32 = (User32) Native.loadLibrary("user32",
|
||||
User32 user32 = (User32) Native.loadLibrary("user32",
|
||||
User32.class, options);
|
||||
// Create a callback to handle the WM_QUERYENDSESSION message
|
||||
WindowProc proc = (hwnd, msg, wp, lp) -> {
|
||||
|
||||
@@ -41,9 +41,9 @@ public class DesktopPluginModule extends PluginModule {
|
||||
backoffFactory, shutdownManager);
|
||||
SimplexPluginFactory removable =
|
||||
new RemovableDrivePluginFactory(ioExecutor);
|
||||
final Collection<SimplexPluginFactory> simplex =
|
||||
Collection<SimplexPluginFactory> simplex =
|
||||
Collections.singletonList(removable);
|
||||
final Collection<DuplexPluginFactory> duplex =
|
||||
Collection<DuplexPluginFactory> duplex =
|
||||
Arrays.asList(bluetooth, modem, lan, wan);
|
||||
@NotNullByDefault
|
||||
PluginConfig pluginConfig = new PluginConfig() {
|
||||
|
||||
@@ -204,18 +204,18 @@ class BluetoothPlugin implements DuplexPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void poll(final Collection<ContactId> connected) {
|
||||
public void poll(Collection<ContactId> connected) {
|
||||
if (!running) return;
|
||||
backoff.increment();
|
||||
// Try to connect to known devices in parallel
|
||||
Map<ContactId, TransportProperties> remote =
|
||||
callback.getRemoteProperties();
|
||||
for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
|
||||
final ContactId c = e.getKey();
|
||||
ContactId c = e.getKey();
|
||||
if (connected.contains(c)) continue;
|
||||
final String address = e.getValue().get(PROP_ADDRESS);
|
||||
String address = e.getValue().get(PROP_ADDRESS);
|
||||
if (StringUtils.isNullOrEmpty(address)) continue;
|
||||
final String uuid = e.getValue().get(PROP_UUID);
|
||||
String uuid = e.getValue().get(PROP_UUID);
|
||||
if (StringUtils.isNullOrEmpty(uuid)) continue;
|
||||
ioExecutor.execute(() -> {
|
||||
if (!running) return;
|
||||
@@ -270,7 +270,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
||||
// Make the device discoverable if possible
|
||||
makeDeviceDiscoverable();
|
||||
// Bind a server socket for receiving key agreementconnections
|
||||
final StreamConnectionNotifier ss;
|
||||
StreamConnectionNotifier ss;
|
||||
try {
|
||||
ss = (StreamConnectionNotifier) Connector.open(url);
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -26,10 +26,10 @@ public class PollingRemovableDriveMonitorTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testOneCallbackPerFile() throws Exception {
|
||||
// Create a finder that returns no files the first time, then two files
|
||||
final File file1 = new File("foo");
|
||||
final File file2 = new File("bar");
|
||||
File file1 = new File("foo");
|
||||
File file2 = new File("bar");
|
||||
@NotNullByDefault
|
||||
final RemovableDriveFinder finder = new RemovableDriveFinder() {
|
||||
RemovableDriveFinder finder = new RemovableDriveFinder() {
|
||||
|
||||
private AtomicBoolean firstCall = new AtomicBoolean(true);
|
||||
|
||||
@@ -40,8 +40,8 @@ public class PollingRemovableDriveMonitorTest extends BrambleTestCase {
|
||||
}
|
||||
};
|
||||
// Create a callback that waits for two files
|
||||
final CountDownLatch latch = new CountDownLatch(2);
|
||||
final List<File> detected = new ArrayList<>();
|
||||
CountDownLatch latch = new CountDownLatch(2);
|
||||
List<File> detected = new ArrayList<>();
|
||||
@NotNullByDefault
|
||||
Callback callback = new Callback() {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class PollingRemovableDriveMonitorTest extends BrambleTestCase {
|
||||
}
|
||||
};
|
||||
// Create the monitor and start it
|
||||
final RemovableDriveMonitor monitor = new PollingRemovableDriveMonitor(
|
||||
RemovableDriveMonitor monitor = new PollingRemovableDriveMonitor(
|
||||
Executors.newCachedThreadPool(), finder, 1);
|
||||
monitor.start(callback);
|
||||
// Wait for the monitor to detect the files
|
||||
@@ -72,7 +72,7 @@ public class PollingRemovableDriveMonitorTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testExceptionCallback() throws Exception {
|
||||
// Create a finder that throws an exception the second time it's polled
|
||||
final RemovableDriveFinder finder = new RemovableDriveFinder() {
|
||||
RemovableDriveFinder finder = new RemovableDriveFinder() {
|
||||
|
||||
private AtomicBoolean firstCall = new AtomicBoolean(true);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class PollingRemovableDriveMonitorTest extends BrambleTestCase {
|
||||
}
|
||||
};
|
||||
// Create a callback that waits for an exception
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
@NotNullByDefault
|
||||
Callback callback = new Callback() {
|
||||
|
||||
@@ -98,7 +98,7 @@ public class PollingRemovableDriveMonitorTest extends BrambleTestCase {
|
||||
}
|
||||
};
|
||||
// Create the monitor and start it
|
||||
final RemovableDriveMonitor monitor = new PollingRemovableDriveMonitor(
|
||||
RemovableDriveMonitor monitor = new PollingRemovableDriveMonitor(
|
||||
Executors.newCachedThreadPool(), finder, 1);
|
||||
monitor.start(callback);
|
||||
assertTrue(latch.await(10, SECONDS));
|
||||
|
||||
@@ -41,17 +41,17 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testWriterIsNullIfNoDrivesAreFound() throws Exception {
|
||||
final List<File> drives = Collections.emptyList();
|
||||
List<File> drives = Collections.emptyList();
|
||||
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor executor = context.mock(Executor.class);
|
||||
final SimplexPluginCallback callback =
|
||||
Executor executor = context.mock(Executor.class);
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -71,21 +71,21 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testWriterIsNullIfNoDriveIsChosen() throws Exception {
|
||||
final File drive1 = new File(testDir, "1");
|
||||
final File drive2 = new File(testDir, "2");
|
||||
final List<File> drives = new ArrayList<>();
|
||||
File drive1 = new File(testDir, "1");
|
||||
File drive2 = new File(testDir, "2");
|
||||
List<File> drives = new ArrayList<>();
|
||||
drives.add(drive1);
|
||||
drives.add(drive2);
|
||||
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor executor = context.mock(Executor.class);
|
||||
final SimplexPluginCallback callback =
|
||||
Executor executor = context.mock(Executor.class);
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -110,21 +110,21 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testWriterIsNullIfOutputDirDoesNotExist() throws Exception {
|
||||
final File drive1 = new File(testDir, "1");
|
||||
final File drive2 = new File(testDir, "2");
|
||||
final List<File> drives = new ArrayList<>();
|
||||
File drive1 = new File(testDir, "1");
|
||||
File drive2 = new File(testDir, "2");
|
||||
List<File> drives = new ArrayList<>();
|
||||
drives.add(drive1);
|
||||
drives.add(drive2);
|
||||
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor executor = context.mock(Executor.class);
|
||||
final SimplexPluginCallback callback =
|
||||
Executor executor = context.mock(Executor.class);
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -149,9 +149,9 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testWriterIsNullIfOutputDirIsAFile() throws Exception {
|
||||
final File drive1 = new File(testDir, "1");
|
||||
final File drive2 = new File(testDir, "2");
|
||||
final List<File> drives = new ArrayList<>();
|
||||
File drive1 = new File(testDir, "1");
|
||||
File drive2 = new File(testDir, "2");
|
||||
List<File> drives = new ArrayList<>();
|
||||
drives.add(drive1);
|
||||
drives.add(drive2);
|
||||
// Create drive1 as a file rather than a directory
|
||||
@@ -160,12 +160,12 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor executor = context.mock(Executor.class);
|
||||
final SimplexPluginCallback callback =
|
||||
Executor executor = context.mock(Executor.class);
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -190,9 +190,9 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testWriterIsNotNullIfOutputDirIsADir() throws Exception {
|
||||
final File drive1 = new File(testDir, "1");
|
||||
final File drive2 = new File(testDir, "2");
|
||||
final List<File> drives = new ArrayList<>();
|
||||
File drive1 = new File(testDir, "1");
|
||||
File drive2 = new File(testDir, "2");
|
||||
List<File> drives = new ArrayList<>();
|
||||
drives.add(drive1);
|
||||
drives.add(drive2);
|
||||
// Create drive1 as a directory
|
||||
@@ -201,12 +201,12 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor executor = context.mock(Executor.class);
|
||||
final SimplexPluginCallback callback =
|
||||
Executor executor = context.mock(Executor.class);
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -234,9 +234,9 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testWritingToWriter() throws Exception {
|
||||
final File drive1 = new File(testDir, "1");
|
||||
final File drive2 = new File(testDir, "2");
|
||||
final List<File> drives = new ArrayList<>();
|
||||
File drive1 = new File(testDir, "1");
|
||||
File drive2 = new File(testDir, "2");
|
||||
List<File> drives = new ArrayList<>();
|
||||
drives.add(drive1);
|
||||
drives.add(drive2);
|
||||
// Create drive1 as a directory
|
||||
@@ -245,12 +245,12 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor executor = context.mock(Executor.class);
|
||||
final SimplexPluginCallback callback =
|
||||
Executor executor = context.mock(Executor.class);
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -292,12 +292,12 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor executor = context.mock(Executor.class);
|
||||
final SimplexPluginCallback callback =
|
||||
Executor executor = context.mock(Executor.class);
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -318,12 +318,12 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final Executor executor = context.mock(Executor.class);
|
||||
final SimplexPluginCallback callback =
|
||||
Executor executor = context.mock(Executor.class);
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
@@ -344,11 +344,11 @@ public class RemovableDrivePluginTest extends BrambleTestCase {
|
||||
Mockery context = new Mockery() {{
|
||||
setThreadingPolicy(new Synchroniser());
|
||||
}};
|
||||
final SimplexPluginCallback callback =
|
||||
SimplexPluginCallback callback =
|
||||
context.mock(SimplexPluginCallback.class);
|
||||
final RemovableDriveFinder finder =
|
||||
RemovableDriveFinder finder =
|
||||
context.mock(RemovableDriveFinder.class);
|
||||
final RemovableDriveMonitor monitor =
|
||||
RemovableDriveMonitor monitor =
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -61,10 +61,10 @@ public class UnixRemovableDriveMonitorTest extends BrambleTestCase {
|
||||
return;
|
||||
}
|
||||
// Create a callback that will wait for two files before stopping
|
||||
final List<File> detected = new ArrayList<>();
|
||||
final CountDownLatch latch = new CountDownLatch(2);
|
||||
List<File> detected = new ArrayList<>();
|
||||
CountDownLatch latch = new CountDownLatch(2);
|
||||
@NotNullByDefault
|
||||
final Callback callback = new Callback() {
|
||||
Callback callback = new Callback() {
|
||||
|
||||
@Override
|
||||
public void driveInserted(File f) {
|
||||
@@ -99,7 +99,7 @@ public class UnixRemovableDriveMonitorTest extends BrambleTestCase {
|
||||
TestUtils.deleteTestDirectory(testDir);
|
||||
}
|
||||
|
||||
private RemovableDriveMonitor createMonitor(final File dir) {
|
||||
private RemovableDriveMonitor createMonitor(File dir) {
|
||||
@NotNullByDefault
|
||||
RemovableDriveMonitor monitor = new UnixRemovableDriveMonitor() {
|
||||
@Override
|
||||
|
||||
@@ -21,12 +21,12 @@ public class ModemPluginTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testModemCreation() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final ModemFactory modemFactory = context.mock(ModemFactory.class);
|
||||
final SerialPortList serialPortList =
|
||||
ModemFactory modemFactory = context.mock(ModemFactory.class);
|
||||
SerialPortList serialPortList =
|
||||
context.mock(SerialPortList.class);
|
||||
final ModemPlugin plugin = new ModemPlugin(modemFactory,
|
||||
ModemPlugin plugin = new ModemPlugin(modemFactory,
|
||||
serialPortList, null, 0);
|
||||
final Modem modem = context.mock(Modem.class);
|
||||
Modem modem = context.mock(Modem.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(serialPortList).getPortNames();
|
||||
will(returnValue(new String[] { "foo", "bar", "baz" }));
|
||||
@@ -53,20 +53,20 @@ public class ModemPluginTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testCreateConnection() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final ModemFactory modemFactory = context.mock(ModemFactory.class);
|
||||
final SerialPortList serialPortList =
|
||||
ModemFactory modemFactory = context.mock(ModemFactory.class);
|
||||
SerialPortList serialPortList =
|
||||
context.mock(SerialPortList.class);
|
||||
final DuplexPluginCallback callback =
|
||||
DuplexPluginCallback callback =
|
||||
context.mock(DuplexPluginCallback.class);
|
||||
final ModemPlugin plugin = new ModemPlugin(modemFactory,
|
||||
ModemPlugin plugin = new ModemPlugin(modemFactory,
|
||||
serialPortList, callback, 0);
|
||||
final Modem modem = context.mock(Modem.class);
|
||||
final TransportProperties local = new TransportProperties();
|
||||
Modem modem = context.mock(Modem.class);
|
||||
TransportProperties local = new TransportProperties();
|
||||
local.put("iso3166", ISO_1336);
|
||||
final TransportProperties remote = new TransportProperties();
|
||||
TransportProperties remote = new TransportProperties();
|
||||
remote.put("iso3166", ISO_1336);
|
||||
remote.put("number", NUMBER);
|
||||
final ContactId contactId = new ContactId(234);
|
||||
ContactId contactId = new ContactId(234);
|
||||
context.checking(new Expectations() {{
|
||||
// start()
|
||||
oneOf(serialPortList).getPortNames();
|
||||
@@ -92,20 +92,20 @@ public class ModemPluginTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testCreateConnectionWhenDialReturnsFalse() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final ModemFactory modemFactory = context.mock(ModemFactory.class);
|
||||
final SerialPortList serialPortList =
|
||||
ModemFactory modemFactory = context.mock(ModemFactory.class);
|
||||
SerialPortList serialPortList =
|
||||
context.mock(SerialPortList.class);
|
||||
final DuplexPluginCallback callback =
|
||||
DuplexPluginCallback callback =
|
||||
context.mock(DuplexPluginCallback.class);
|
||||
final ModemPlugin plugin = new ModemPlugin(modemFactory,
|
||||
ModemPlugin plugin = new ModemPlugin(modemFactory,
|
||||
serialPortList, callback, 0);
|
||||
final Modem modem = context.mock(Modem.class);
|
||||
final TransportProperties local = new TransportProperties();
|
||||
Modem modem = context.mock(Modem.class);
|
||||
TransportProperties local = new TransportProperties();
|
||||
local.put("iso3166", ISO_1336);
|
||||
final TransportProperties remote = new TransportProperties();
|
||||
TransportProperties remote = new TransportProperties();
|
||||
remote.put("iso3166", ISO_1336);
|
||||
remote.put("number", NUMBER);
|
||||
final ContactId contactId = new ContactId(234);
|
||||
ContactId contactId = new ContactId(234);
|
||||
context.checking(new Expectations() {{
|
||||
// start()
|
||||
oneOf(serialPortList).getPortNames();
|
||||
@@ -131,20 +131,20 @@ public class ModemPluginTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testCreateConnectionWhenDialThrowsException() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final ModemFactory modemFactory = context.mock(ModemFactory.class);
|
||||
final SerialPortList serialPortList =
|
||||
ModemFactory modemFactory = context.mock(ModemFactory.class);
|
||||
SerialPortList serialPortList =
|
||||
context.mock(SerialPortList.class);
|
||||
final DuplexPluginCallback callback =
|
||||
DuplexPluginCallback callback =
|
||||
context.mock(DuplexPluginCallback.class);
|
||||
final ModemPlugin plugin = new ModemPlugin(modemFactory,
|
||||
ModemPlugin plugin = new ModemPlugin(modemFactory,
|
||||
serialPortList, callback, 0);
|
||||
final Modem modem = context.mock(Modem.class);
|
||||
final TransportProperties local = new TransportProperties();
|
||||
Modem modem = context.mock(Modem.class);
|
||||
TransportProperties local = new TransportProperties();
|
||||
local.put("iso3166", ISO_1336);
|
||||
final TransportProperties remote = new TransportProperties();
|
||||
TransportProperties remote = new TransportProperties();
|
||||
remote.put("iso3166", ISO_1336);
|
||||
remote.put("number", NUMBER);
|
||||
final ContactId contactId = new ContactId(234);
|
||||
ContactId contactId = new ContactId(234);
|
||||
context.checking(new Expectations() {{
|
||||
// start()
|
||||
oneOf(serialPortList).getPortNames();
|
||||
|
||||
@@ -242,7 +242,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
});
|
||||
}
|
||||
|
||||
private void showContactNotification(final ContactId c) {
|
||||
private void showContactNotification(ContactId c) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
if (blockContacts) return;
|
||||
if (c.equals(blockedContact)) return;
|
||||
@@ -255,7 +255,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContactNotification(final ContactId c) {
|
||||
public void clearContactNotification(ContactId c) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
Integer count = contactCounts.remove(c);
|
||||
if (count == null) return; // Already cleared
|
||||
@@ -350,7 +350,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void showGroupMessageNotification(final GroupId g) {
|
||||
private void showGroupMessageNotification(GroupId g) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
if (blockGroups) return;
|
||||
if (g.equals(blockedGroup)) return;
|
||||
@@ -363,7 +363,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearGroupMessageNotification(final GroupId g) {
|
||||
public void clearGroupMessageNotification(GroupId g) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
Integer count = groupCounts.remove(g);
|
||||
if (count == null) return; // Already cleared
|
||||
@@ -427,7 +427,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void showForumPostNotification(final GroupId g) {
|
||||
private void showForumPostNotification(GroupId g) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
if (blockForums) return;
|
||||
if (g.equals(blockedGroup)) return;
|
||||
@@ -440,7 +440,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearForumPostNotification(final GroupId g) {
|
||||
public void clearForumPostNotification(GroupId g) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
Integer count = forumCounts.remove(g);
|
||||
if (count == null) return; // Already cleared
|
||||
@@ -504,7 +504,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void showBlogPostNotification(final GroupId g) {
|
||||
private void showBlogPostNotification(GroupId g) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
if (blockBlogs) return;
|
||||
if (g.equals(blockedGroup)) return;
|
||||
@@ -517,7 +517,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearBlogPostNotification(final GroupId g) {
|
||||
public void clearBlogPostNotification(GroupId g) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
Integer count = blogCounts.remove(g);
|
||||
if (count == null) return; // Already cleared
|
||||
@@ -611,24 +611,24 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blockNotification(final GroupId g) {
|
||||
public void blockNotification(GroupId g) {
|
||||
androidExecutor.runOnUiThread((Runnable) () -> blockedGroup = g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unblockNotification(final GroupId g) {
|
||||
public void unblockNotification(GroupId g) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
if (g.equals(blockedGroup)) blockedGroup = null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blockContactNotification(final ContactId c) {
|
||||
public void blockContactNotification(ContactId c) {
|
||||
androidExecutor.runOnUiThread((Runnable) () -> blockedContact = c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unblockContactNotification(final ContactId c) {
|
||||
public void unblockContactNotification(ContactId c) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
if (c.equals(blockedContact)) blockedContact = null;
|
||||
});
|
||||
|
||||
@@ -80,7 +80,7 @@ public class AppModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
DatabaseConfig provideDatabaseConfig(Application app) {
|
||||
final File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||
File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
DatabaseConfig databaseConfig = new DatabaseConfig() {
|
||||
@@ -132,7 +132,7 @@ public class AppModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
DevConfig provideDevConfig(final CryptoComponent crypto) {
|
||||
DevConfig provideDevConfig(CryptoComponent crypto) {
|
||||
@NotNullByDefault
|
||||
DevConfig devConfig = new DevConfig() {
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public class BriarService extends Service {
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void showStartupFailureNotification(final StartResult result) {
|
||||
private void showStartupFailureNotification(StartResult result) {
|
||||
androidExecutor.runOnUiThread(() -> {
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(BriarService.this);
|
||||
|
||||
@@ -151,7 +151,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runOnUiThreadUnlessDestroyed(final Runnable r) {
|
||||
public void runOnUiThreadUnlessDestroyed(Runnable r) {
|
||||
runOnUiThread(() -> {
|
||||
if (!destroyed && !isFinishing()) r.run();
|
||||
});
|
||||
|
||||
@@ -97,7 +97,7 @@ public abstract class BriarActivity extends BaseActivity {
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
protected void signOut(final boolean removeFromRecentApps) {
|
||||
protected void signOut(boolean removeFromRecentApps) {
|
||||
if (briarController.hasEncryptionKey()) {
|
||||
// Don't use UiResultHandler because we want the result even if
|
||||
// this activity has been destroyed
|
||||
|
||||
@@ -84,7 +84,7 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
void onBlogPostAdded(final BlogPostHeader h, final boolean local) {
|
||||
void onBlogPostAdded(BlogPostHeader h, boolean local) {
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onBlogPostAdded(h, local));
|
||||
}
|
||||
@@ -94,8 +94,8 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBlogPosts(final GroupId groupId,
|
||||
final ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
||||
public void loadBlogPosts(GroupId groupId,
|
||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Collection<BlogPostItem> items = loadItems(groupId);
|
||||
@@ -129,8 +129,8 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBlogPost(final BlogPostHeader header,
|
||||
final ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
||||
public void loadBlogPost(BlogPostHeader header,
|
||||
ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
||||
|
||||
String body = bodyCache.get(header.getId());
|
||||
if (body != null) {
|
||||
@@ -155,8 +155,8 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBlogPost(final GroupId g, final MessageId m,
|
||||
final ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
||||
public void loadBlogPost(GroupId g, MessageId m,
|
||||
ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
||||
|
||||
BlogPostHeader header = headerCache.get(m);
|
||||
if (header != null) {
|
||||
@@ -182,9 +182,8 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void repeatPost(final BlogPostItem item,
|
||||
final @Nullable String comment,
|
||||
final ExceptionHandler<DbException> handler) {
|
||||
public void repeatPost(BlogPostItem item, @Nullable String comment,
|
||||
ExceptionHandler<DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
LocalAuthor a = identityManager.getLocalAuthor();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class BlogActivity extends BriarActivity
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
||||
if (b == null) throw new IllegalStateException("No group ID in intent");
|
||||
final GroupId groupId = new GroupId(b);
|
||||
GroupId groupId = new GroupId(b);
|
||||
blogController.setGroupId(groupId);
|
||||
|
||||
setContentView(R.layout.activity_fragment_container_toolbar);
|
||||
|
||||
@@ -125,32 +125,32 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
}
|
||||
}
|
||||
|
||||
private void onBlogInvitationAccepted(final ContactId c) {
|
||||
private void onBlogInvitationAccepted(ContactId c) {
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onBlogInvitationAccepted(c));
|
||||
}
|
||||
|
||||
private void onBlogLeft(final ContactId c) {
|
||||
private void onBlogLeft(ContactId c) {
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> listener.onBlogLeft(c));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBlogPosts(
|
||||
final ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
loadBlogPosts(groupId, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBlogPost(final MessageId m,
|
||||
final ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
||||
public void loadBlogPost(MessageId m,
|
||||
ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
loadBlogPost(groupId, m, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBlog(
|
||||
final ResultExceptionHandler<BlogItem, DbException> handler) {
|
||||
ResultExceptionHandler<BlogItem, DbException> handler) {
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
@@ -173,8 +173,7 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBlog(
|
||||
final ResultExceptionHandler<Void, DbException> handler) {
|
||||
public void deleteBlog(ResultExceptionHandler<Void, DbException> handler) {
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
@@ -195,7 +194,7 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
|
||||
@Override
|
||||
public void loadSharingContacts(
|
||||
final ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
|
||||
@@ -137,7 +137,7 @@ public class BlogFragment extends BaseFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_write_blog_post:
|
||||
Intent i = new Intent(getActivity(),
|
||||
@@ -184,7 +184,7 @@ public class BlogFragment extends BaseFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostAdded(BlogPostHeader header, final boolean local) {
|
||||
public void onBlogPostAdded(BlogPostHeader header, boolean local) {
|
||||
blogController.loadBlogPost(header,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
this) {
|
||||
@@ -224,7 +224,7 @@ public class BlogFragment extends BaseFragment
|
||||
getContext().startActivity(i);
|
||||
}
|
||||
|
||||
private void loadBlogPosts(final boolean reload) {
|
||||
private void loadBlogPosts(boolean reload) {
|
||||
blogController.loadBlogPosts(
|
||||
new UiResultExceptionHandler<Collection<BlogPostItem>,
|
||||
DbException>(this) {
|
||||
|
||||
@@ -88,7 +88,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
return "blogPost" + id.hashCode();
|
||||
}
|
||||
|
||||
void bindItem(@Nullable final BlogPostItem item) {
|
||||
void bindItem(@Nullable BlogPostItem item) {
|
||||
if (item == null) return;
|
||||
|
||||
setTransitionName(item.getId());
|
||||
@@ -152,7 +152,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
}
|
||||
}
|
||||
|
||||
private void onBindComment(final BlogCommentItem item) {
|
||||
private void onBindComment(BlogCommentItem item) {
|
||||
// reblogger
|
||||
reblogger.setAuthor(item.getAuthor());
|
||||
reblogger.setAuthorStatus(item.getAuthorStatus());
|
||||
|
||||
@@ -96,7 +96,7 @@ class FeedControllerImpl extends BaseControllerImpl
|
||||
|
||||
@Override
|
||||
public void loadBlogPosts(
|
||||
final ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -122,7 +122,7 @@ class FeedControllerImpl extends BaseControllerImpl
|
||||
|
||||
@Override
|
||||
public void loadPersonalBlog(
|
||||
final ResultExceptionHandler<Blog, DbException> handler) {
|
||||
ResultExceptionHandler<Blog, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
@@ -135,8 +135,8 @@ public class FeedFragment extends BaseFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
private void loadBlogPosts(final boolean clear) {
|
||||
final int revision = adapter.getRevision();
|
||||
private void loadBlogPosts(boolean clear) {
|
||||
int revision = adapter.getRevision();
|
||||
feedController.loadBlogPosts(
|
||||
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
||||
this) {
|
||||
@@ -167,7 +167,7 @@ public class FeedFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (personalBlog == null) return false;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_write_blog_post:
|
||||
@@ -193,7 +193,7 @@ public class FeedFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostAdded(BlogPostHeader header, final boolean local) {
|
||||
public void onBlogPostAdded(BlogPostHeader header, boolean local) {
|
||||
feedController.loadBlogPost(header,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
this) {
|
||||
|
||||
@@ -34,7 +34,7 @@ class RssFeedAdapter extends BriarAdapter<Feed, RssFeedAdapter.FeedViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(FeedViewHolder ui, int position) {
|
||||
final Feed item = getItemAt(position);
|
||||
Feed item = getItemAt(position);
|
||||
if (item == null) return;
|
||||
|
||||
// Feed Title
|
||||
|
||||
@@ -118,7 +118,7 @@ public class RssFeedImportActivity extends BriarActivity {
|
||||
importFeed(url);
|
||||
}
|
||||
|
||||
private void importFeed(final String url) {
|
||||
private void importFeed(String url) {
|
||||
ioExecutor.execute(() -> {
|
||||
try {
|
||||
feedManager.addFeed(url);
|
||||
|
||||
@@ -103,7 +103,7 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteClick(final Feed feed) {
|
||||
public void onDeleteClick(Feed feed) {
|
||||
DialogInterface.OnClickListener okListener =
|
||||
(dialog, which) -> deleteFeed(feed);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this,
|
||||
@@ -118,7 +118,7 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void loadFeeds() {
|
||||
final int revision = adapter.getRevision();
|
||||
int revision = adapter.getRevision();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
displayFeeds(revision, feedManager.getFeeds());
|
||||
@@ -129,7 +129,7 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void displayFeeds(final int revision, final List<Feed> feeds) {
|
||||
private void displayFeeds(int revision, List<Feed> feeds) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (revision == adapter.getRevision()) {
|
||||
adapter.incrementRevision();
|
||||
@@ -142,7 +142,7 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteFeed(final Feed feed) {
|
||||
private void deleteFeed(Feed feed) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
feedManager.removeFeed(feed);
|
||||
@@ -161,7 +161,7 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void onFeedDeleted(final Feed feed) {
|
||||
private void onFeedDeleted(Feed feed) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
adapter.remove(feed);
|
||||
|
||||
@@ -140,7 +140,7 @@ public class WriteBlogPostActivity extends BriarActivity
|
||||
storePost(body);
|
||||
}
|
||||
|
||||
private void storePost(final String body) {
|
||||
private void storePost(String body) {
|
||||
runOnDbThread(() -> {
|
||||
long now = System.currentTimeMillis();
|
||||
try {
|
||||
|
||||
@@ -23,7 +23,7 @@ public abstract class BaseContactListAdapter<I extends ContactItem, VH extends C
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final VH ui, int position) {
|
||||
public void onBindViewHolder(VH ui, int position) {
|
||||
I item = items.get(position);
|
||||
ui.bind(item, listener);
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ public class ContactItemViewHolder<I extends ContactItem>
|
||||
bulb = (ImageView) v.findViewById(R.id.bulbView);
|
||||
}
|
||||
|
||||
protected void bind(final I item,
|
||||
@Nullable final OnContactClickListener<I> listener) {
|
||||
protected void bind(I item, @Nullable OnContactClickListener<I> listener) {
|
||||
Author author = item.getContact().getAuthor();
|
||||
avatar.setImageDrawable(
|
||||
new IdenticonDrawable(author.getId().getBytes()));
|
||||
|
||||
@@ -158,7 +158,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle presses on the action bar items
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_add_contact:
|
||||
@@ -191,7 +191,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
}
|
||||
|
||||
private void loadContacts() {
|
||||
final int revision = adapter.getRevision();
|
||||
int revision = adapter.getRevision();
|
||||
listener.runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -218,8 +218,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void displayContacts(final int revision,
|
||||
final List<ContactListItem> contacts) {
|
||||
private void displayContacts(int revision, List<ContactListItem> contacts) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (revision == adapter.getRevision()) {
|
||||
adapter.incrementRevision();
|
||||
@@ -282,7 +281,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateItem(final ContactId c, final BaseMessageHeader h) {
|
||||
private void updateItem(ContactId c, BaseMessageHeader h) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
int position = adapter.findItemPosition(c);
|
||||
@@ -295,7 +294,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void removeItem(final ContactId c) {
|
||||
private void removeItem(ContactId c) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
int position = adapter.findItemPosition(c);
|
||||
@@ -304,7 +303,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void setConnected(final ContactId c, final boolean connected) {
|
||||
private void setConnected(ContactId c, boolean connected) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
int position = adapter.findItemPosition(c);
|
||||
|
||||
@@ -268,7 +268,7 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle presses on the action bar items
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
@@ -338,7 +338,7 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void loadMessages() {
|
||||
final int revision = adapter.getRevision();
|
||||
int revision = adapter.getRevision();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -370,10 +370,10 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void displayMessages(final int revision,
|
||||
final Collection<PrivateMessageHeader> headers,
|
||||
final Collection<IntroductionMessage> introductions,
|
||||
final Collection<InvitationMessage> invitations) {
|
||||
private void displayMessages(int revision,
|
||||
Collection<PrivateMessageHeader> headers,
|
||||
Collection<IntroductionMessage> introductions,
|
||||
Collection<InvitationMessage> invitations) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (revision == adapter.getRevision()) {
|
||||
adapter.incrementRevision();
|
||||
@@ -436,7 +436,7 @@ public class ConversationActivity extends BriarActivity
|
||||
return items;
|
||||
}
|
||||
|
||||
private void loadMessageBody(final MessageId m) {
|
||||
private void loadMessageBody(MessageId m) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -451,7 +451,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void displayMessageBody(final MessageId m, final String body) {
|
||||
private void displayMessageBody(MessageId m, String body) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
bodyCache.put(m, body);
|
||||
SparseArray<ConversationItem> messages =
|
||||
@@ -543,7 +543,7 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void addConversationItem(final ConversationItem item) {
|
||||
private void addConversationItem(ConversationItem item) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
adapter.add(item);
|
||||
@@ -552,10 +552,10 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void handleIntroductionRequest(final IntroductionRequest m) {
|
||||
private void handleIntroductionRequest(IntroductionRequest m) {
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(final String contactName) {
|
||||
public void onSuccess(String contactName) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
ConversationItem item = ConversationItem
|
||||
.from(ConversationActivity.this, contactName, m);
|
||||
@@ -563,17 +563,17 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void onFailure(final Throwable exception) {
|
||||
public void onFailure(Throwable exception) {
|
||||
runOnUiThreadUnlessDestroyed(
|
||||
() -> handleDbException((DbException) exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleIntroductionResponse(final IntroductionResponse m) {
|
||||
private void handleIntroductionResponse(IntroductionResponse m) {
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(final String contactName) {
|
||||
public void onSuccess(String contactName) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
ConversationItem item = ConversationItem
|
||||
.from(ConversationActivity.this, contactName, m);
|
||||
@@ -581,17 +581,17 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void onFailure(final Throwable exception) {
|
||||
public void onFailure(Throwable exception) {
|
||||
runOnUiThreadUnlessDestroyed(
|
||||
() -> handleDbException((DbException) exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleInvitationRequest(final InvitationRequest m) {
|
||||
private void handleInvitationRequest(InvitationRequest m) {
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(final String contactName) {
|
||||
public void onSuccess(String contactName) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
ConversationItem item = ConversationItem
|
||||
.from(ConversationActivity.this, contactName, m);
|
||||
@@ -599,17 +599,17 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void onFailure(final Throwable exception) {
|
||||
public void onFailure(Throwable exception) {
|
||||
runOnUiThreadUnlessDestroyed(
|
||||
() -> handleDbException((DbException) exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleInvitationResponse(final InvitationResponse m) {
|
||||
private void handleInvitationResponse(InvitationResponse m) {
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(final String contactName) {
|
||||
public void onSuccess(String contactName) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
ConversationItem item = ConversationItem
|
||||
.from(ConversationActivity.this, contactName, m);
|
||||
@@ -617,15 +617,15 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void onFailure(final Throwable exception) {
|
||||
public void onFailure(Throwable exception) {
|
||||
runOnUiThreadUnlessDestroyed(
|
||||
() -> handleDbException((DbException) exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void markMessages(final Collection<MessageId> messageIds,
|
||||
final boolean sent, final boolean seen) {
|
||||
private void markMessages(Collection<MessageId> messageIds,
|
||||
boolean sent, boolean seen) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
Set<MessageId> messages = new HashSet<>(messageIds);
|
||||
@@ -659,7 +659,7 @@ public class ConversationActivity extends BriarActivity
|
||||
return item == null ? 0 : item.getTime() + 1;
|
||||
}
|
||||
|
||||
private void loadGroupId(final String body, final long timestamp) {
|
||||
private void loadGroupId(String body, long timestamp) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
messagingGroupId =
|
||||
@@ -672,7 +672,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void createMessage(final String body, final long timestamp) {
|
||||
private void createMessage(String body, long timestamp) {
|
||||
cryptoExecutor.execute(() -> {
|
||||
try {
|
||||
//noinspection ConstantConditions init in loadGroupId()
|
||||
@@ -683,7 +683,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void storeMessage(final PrivateMessage m, final String body) {
|
||||
private void storeMessage(PrivateMessage m, String body) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -739,7 +739,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void enableIntroductionActionIfAvailable(final MenuItem item) {
|
||||
private void enableIntroductionActionIfAvailable(MenuItem item) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
if (contactManager.getActiveContacts().size() > 1) {
|
||||
@@ -757,7 +757,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void enableIntroductionAction(final MenuItem item) {
|
||||
private void enableIntroductionAction(MenuItem item) {
|
||||
runOnUiThreadUnlessDestroyed(() -> item.setEnabled(true));
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ public class ConversationActivity extends BriarActivity
|
||||
if (!item.isRead()) markMessageRead(item.getGroupId(), item.getId());
|
||||
}
|
||||
|
||||
private void markMessageRead(final GroupId g, final MessageId m) {
|
||||
private void markMessageRead(GroupId g, MessageId m) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -833,8 +833,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public void respondToRequest(final ConversationRequestItem item,
|
||||
final boolean accept) {
|
||||
public void respondToRequest(ConversationRequestItem item, boolean accept) {
|
||||
item.setAnswered(true);
|
||||
int position = adapter.findItemPosition(item);
|
||||
if (position != INVALID_POSITION) {
|
||||
|
||||
@@ -25,10 +25,10 @@ class ConversationRequestViewHolder extends ConversationNoticeInViewHolder {
|
||||
}
|
||||
|
||||
void bind(ConversationItem conversationItem,
|
||||
final ConversationListener listener) {
|
||||
ConversationListener listener) {
|
||||
super.bind(conversationItem);
|
||||
|
||||
final ConversationRequestItem item =
|
||||
ConversationRequestItem item =
|
||||
(ConversationRequestItem) conversationItem;
|
||||
|
||||
if (item.wasAnswered() && item.canBeOpened()) {
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
|
||||
onSelectionChanged();
|
||||
}
|
||||
|
||||
private void loadContacts(final Collection<ContactId> selection) {
|
||||
private void loadContacts(Collection<ContactId> selection) {
|
||||
getController().loadContacts(groupId, selection,
|
||||
new UiResultExceptionHandler<Collection<I>, DbException>(
|
||||
this) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class ContactSelectorActivity
|
||||
extends BriarActivity
|
||||
implements BaseFragmentListener, ContactSelectorListener {
|
||||
|
||||
final static String CONTACTS = "contacts";
|
||||
protected final static String CONTACTS = "contacts";
|
||||
|
||||
// Subclasses may initialise the group ID in different places
|
||||
protected GroupId groupId;
|
||||
|
||||
@@ -38,9 +38,8 @@ public abstract class ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadContacts(final GroupId g,
|
||||
final Collection<ContactId> selection,
|
||||
final ResultExceptionHandler<Collection<SelectableContactItem>, DbException> handler) {
|
||||
public void loadContacts(GroupId g, Collection<ContactId> selection,
|
||||
ResultExceptionHandler<Collection<SelectableContactItem>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Collection<SelectableContactItem> contacts = new ArrayList<>();
|
||||
|
||||
@@ -36,7 +36,7 @@ public abstract class ContactSelectorFragment extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_contacts_selected:
|
||||
selectedContacts = adapter.getSelectedContactIds();
|
||||
|
||||
@@ -66,7 +66,7 @@ public class BriarControllerImpl implements BriarController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signOut(final ResultHandler<Void> eventHandler) {
|
||||
public void signOut(ResultHandler<Void> eventHandler) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DbControllerImpl implements DbController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runOnDbThread(final Runnable task) {
|
||||
public void runOnDbThread(Runnable task) {
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class SharingControllerImpl implements SharingController, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void setConnected(final ContactId c) {
|
||||
private void setConnected(ContactId c) {
|
||||
if (listener == null) return;
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (contacts.contains(c)) {
|
||||
|
||||
@@ -19,7 +19,7 @@ public abstract class UiExceptionHandler<E extends Exception>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(final E exception) {
|
||||
public void onException(E exception) {
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> onExceptionUi(exception));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class UiResultExceptionHandler<R, E extends Exception>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
public void onResult(R result) {
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> onResultUi(result));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public abstract class UiResultHandler<R> implements ResultHandler<R> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
public void onResult(R result) {
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> onResultUi(result));
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ public class CreateForumActivity extends BriarActivity {
|
||||
storeForum(nameEntry.getText().toString());
|
||||
}
|
||||
|
||||
private void storeForum(final String name) {
|
||||
private void storeForum(String name) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -136,7 +136,7 @@ public class CreateForumActivity extends BriarActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private void displayForum(final Forum f) {
|
||||
private void displayForum(Forum f) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
Intent i = new Intent(CreateForumActivity.this,
|
||||
ForumActivity.class);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ForumActivity extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle presses on the action bar items
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_forum_share:
|
||||
|
||||
@@ -120,7 +120,7 @@ class ForumControllerImpl extends
|
||||
|
||||
@Override
|
||||
public void loadSharingContacts(
|
||||
final ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Collection<Contact> contacts =
|
||||
@@ -137,9 +137,9 @@ class ForumControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndStoreMessage(final String body,
|
||||
@Nullable final ForumItem parentItem,
|
||||
final ResultExceptionHandler<ForumItem, DbException> handler) {
|
||||
public void createAndStoreMessage(String body,
|
||||
@Nullable ForumItem parentItem,
|
||||
ResultExceptionHandler<ForumItem, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
LocalAuthor author = identityManager.getLocalAuthor();
|
||||
@@ -156,9 +156,9 @@ class ForumControllerImpl extends
|
||||
});
|
||||
}
|
||||
|
||||
private void createMessage(final String body, final long timestamp,
|
||||
final @Nullable MessageId parentId, final LocalAuthor author,
|
||||
final ResultExceptionHandler<ForumItem, DbException> handler) {
|
||||
private void createMessage(String body, long timestamp,
|
||||
@Nullable MessageId parentId, LocalAuthor author,
|
||||
ResultExceptionHandler<ForumItem, DbException> handler) {
|
||||
cryptoExecutor.execute(() -> {
|
||||
LOG.info("Creating forum post...");
|
||||
ForumPost msg = forumManager.createLocalPost(getGroupId(), body,
|
||||
@@ -184,17 +184,17 @@ class ForumControllerImpl extends
|
||||
}
|
||||
|
||||
private void onForumPostReceived(ForumPostHeader h, String body) {
|
||||
final ForumItem item = buildItem(h, body);
|
||||
ForumItem item = buildItem(h, body);
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onItemReceived(item));
|
||||
}
|
||||
|
||||
private void onForumInvitationAccepted(final ContactId c) {
|
||||
private void onForumInvitationAccepted(ContactId c) {
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onInvitationAccepted(c));
|
||||
}
|
||||
|
||||
private void onForumLeft(final ContactId c) {
|
||||
private void onForumLeft(ContactId c) {
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> listener.onForumLeft(c));
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class ForumListAdapter
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ForumViewHolder ui, int position) {
|
||||
final ForumListItem item = getItemAt(position);
|
||||
ForumListItem item = getItemAt(position);
|
||||
if (item == null) return;
|
||||
|
||||
// Avatar
|
||||
|
||||
@@ -140,7 +140,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle presses on the action bar items
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_create_forum:
|
||||
@@ -154,7 +154,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
}
|
||||
|
||||
private void loadForums() {
|
||||
final int revision = adapter.getRevision();
|
||||
int revision = adapter.getRevision();
|
||||
listener.runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -178,8 +178,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
private void displayForums(final int revision,
|
||||
final Collection<ForumListItem> forums) {
|
||||
private void displayForums(int revision, Collection<ForumListItem> forums) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (revision == adapter.getRevision()) {
|
||||
adapter.incrementRevision();
|
||||
@@ -207,7 +206,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
private void displayAvailableForums(final int availableCount) {
|
||||
private void displayAvailableForums(int availableCount) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (availableCount == 0) {
|
||||
snackbar.dismiss();
|
||||
@@ -247,7 +246,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
private void updateItem(final GroupId g, final ForumPostHeader m) {
|
||||
private void updateItem(GroupId g, ForumPostHeader m) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
int position = adapter.findItemPosition(g);
|
||||
@@ -259,7 +258,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
private void removeForum(final GroupId g) {
|
||||
private void removeForum(GroupId g) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
int position = adapter.findItemPosition(g);
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class BaseFragment extends Fragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
listener.onBackPressed();
|
||||
@@ -79,8 +79,8 @@ public abstract class BaseFragment extends Fragment
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void runOnUiThreadUnlessDestroyed(final Runnable r) {
|
||||
final Activity activity = getActivity();
|
||||
public void runOnUiThreadUnlessDestroyed(Runnable r) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(() -> {
|
||||
// Note that we don't have to check if the activity has
|
||||
|
||||
@@ -134,7 +134,7 @@ public class ContactChooserFragment extends BaseFragment {
|
||||
});
|
||||
}
|
||||
|
||||
private void displayContacts(final List<ContactListItem> contacts) {
|
||||
private void displayContacts(List<ContactListItem> contacts) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (contacts.isEmpty()) list.showData();
|
||||
else adapter.addAll(contacts);
|
||||
|
||||
@@ -118,8 +118,7 @@ public class IntroductionMessageFragment extends BaseFragment
|
||||
return TAG;
|
||||
}
|
||||
|
||||
private void prepareToSetUpViews(final int contactId1,
|
||||
final int contactId2) {
|
||||
private void prepareToSetUpViews(int contactId1, int contactId2) {
|
||||
introductionActivity.runOnDbThread(() -> {
|
||||
try {
|
||||
Contact c1 = contactManager.getContact(
|
||||
@@ -133,7 +132,7 @@ public class IntroductionMessageFragment extends BaseFragment
|
||||
});
|
||||
}
|
||||
|
||||
private void setUpViews(final Contact c1, final Contact c2) {
|
||||
private void setUpViews(Contact c1, Contact c2) {
|
||||
introductionActivity.runOnUiThreadUnlessDestroyed(() -> {
|
||||
contact1 = c1;
|
||||
contact2 = c2;
|
||||
@@ -159,7 +158,7 @@ public class IntroductionMessageFragment extends BaseFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
introductionActivity.hideSoftKeyboard(ui.message);
|
||||
@@ -185,8 +184,7 @@ public class IntroductionMessageFragment extends BaseFragment
|
||||
introductionActivity.supportFinishAfterTransition();
|
||||
}
|
||||
|
||||
private void makeIntroduction(final Contact c1, final Contact c2,
|
||||
final String msg) {
|
||||
private void makeIntroduction(Contact c1, Contact c2, String msg) {
|
||||
introductionActivity.runOnDbThread(() -> {
|
||||
// actually make the introduction
|
||||
try {
|
||||
|
||||
@@ -352,7 +352,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(final SurfaceHolder holder) {
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
post(() -> {
|
||||
try {
|
||||
surfaceCreatedUi(holder);
|
||||
@@ -375,8 +375,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(final SurfaceHolder holder, int format,
|
||||
final int w, final int h) {
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
post(() -> {
|
||||
try {
|
||||
surfaceChangedUi(holder, w, h);
|
||||
@@ -411,7 +410,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(final SurfaceHolder holder) {
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
post(() -> surfaceDestroyedUi(holder));
|
||||
}
|
||||
|
||||
@@ -427,7 +426,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, final Camera camera) {
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
LOG.info("Auto focus succeeded: " + success);
|
||||
postDelayed(this::retryAutoFocus, AUTO_FOCUS_RETRY_DELAY);
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class KeyAgreementActivity extends BriarActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
@@ -204,11 +204,11 @@ public class KeyAgreementActivity extends BriarActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
private void keyAgreementFinished(final KeyAgreementResult result) {
|
||||
private void keyAgreementFinished(KeyAgreementResult result) {
|
||||
runOnUiThreadUnlessDestroyed(() -> startContactExchange(result));
|
||||
}
|
||||
|
||||
private void startContactExchange(final KeyAgreementResult result) {
|
||||
private void startContactExchange(KeyAgreementResult result) {
|
||||
runOnDbThread(() -> {
|
||||
LocalAuthor localAuthor;
|
||||
// Load the local pseudonym
|
||||
@@ -229,7 +229,7 @@ public class KeyAgreementActivity extends BriarActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contactExchangeSucceeded(final Author remoteAuthor) {
|
||||
public void contactExchangeSucceeded(Author remoteAuthor) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
String contactName = remoteAuthor.getName();
|
||||
String format = getString(string.contact_added_toast);
|
||||
@@ -240,7 +240,7 @@ public class KeyAgreementActivity extends BriarActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void duplicateContact(final Author remoteAuthor) {
|
||||
public void duplicateContact(Author remoteAuthor) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
String contactName = remoteAuthor.getName();
|
||||
String format = getString(string.contact_already_exists);
|
||||
|
||||
@@ -30,8 +30,8 @@ class QrCodeUtils {
|
||||
int smallestDimen = Math.min(dm.widthPixels, dm.heightPixels);
|
||||
try {
|
||||
// Generate QR code
|
||||
final BitMatrix encoded = new QRCodeWriter().encode(
|
||||
input, QR_CODE, smallestDimen, smallestDimen);
|
||||
BitMatrix encoded = new QRCodeWriter().encode(input, QR_CODE,
|
||||
smallestDimen, smallestDimen);
|
||||
// Convert QR code to Bitmap
|
||||
int width = encoded.getWidth();
|
||||
int height = encoded.getHeight();
|
||||
|
||||
@@ -157,8 +157,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
getActivity().registerReceiver(receiver, filter);
|
||||
|
||||
// Enable BT adapter if it is not already on.
|
||||
final BluetoothAdapter adapter =
|
||||
BluetoothAdapter.getDefaultAdapter();
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (adapter != null && !adapter.isEnabled()) {
|
||||
waitingForBluetooth = true;
|
||||
eventBus.broadcast(new EnableBluetoothEvent());
|
||||
@@ -189,8 +188,8 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
|
||||
@UiThread
|
||||
private void startListening() {
|
||||
final KeyAgreementTask oldTask = task;
|
||||
final KeyAgreementTask newTask = keyAgreementTaskFactory.createTask();
|
||||
KeyAgreementTask oldTask = task;
|
||||
KeyAgreementTask newTask = keyAgreementTaskFactory.createTask();
|
||||
task = newTask;
|
||||
ioExecutor.execute(() -> {
|
||||
if (oldTask != null) oldTask.stopListening();
|
||||
@@ -200,7 +199,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
|
||||
@UiThread
|
||||
private void stopListening() {
|
||||
final KeyAgreementTask oldTask = task;
|
||||
KeyAgreementTask oldTask = task;
|
||||
ioExecutor.execute(() -> {
|
||||
if (oldTask != null) oldTask.stopListening();
|
||||
});
|
||||
@@ -257,11 +256,11 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void generateBitmapQR(final Payload payload) {
|
||||
private void generateBitmapQR(Payload payload) {
|
||||
// Get narrowest screen dimension
|
||||
Context context = getContext();
|
||||
if (context == null) return;
|
||||
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
new AsyncTask<Void, Void, Bitmap>() {
|
||||
|
||||
@Override
|
||||
@@ -286,7 +285,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void setQrCode(final Payload localPayload) {
|
||||
private void setQrCode(Payload localPayload) {
|
||||
runOnUiThreadUnlessDestroyed(() -> generateBitmapQR(localPayload));
|
||||
}
|
||||
|
||||
@@ -311,7 +310,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
});
|
||||
}
|
||||
|
||||
private void keyAgreementAborted(final boolean remoteAborted) {
|
||||
private void keyAgreementAborted(boolean remoteAborted) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
reset();
|
||||
mainProgressContainer.setVisibility(INVISIBLE);
|
||||
@@ -325,7 +324,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleResult(final Result result) {
|
||||
public void handleResult(Result result) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
LOG.info("Got result from decoder");
|
||||
// Ignore results until the KeyAgreementTask is ready
|
||||
|
||||
@@ -47,9 +47,9 @@ public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validatePassword(final String password,
|
||||
final ResultHandler<Boolean> resultHandler) {
|
||||
final byte[] encrypted = getEncryptedKey();
|
||||
public void validatePassword(String password,
|
||||
ResultHandler<Boolean> resultHandler) {
|
||||
byte[] encrypted = getEncryptedKey();
|
||||
cryptoExecutor.execute(() -> {
|
||||
byte[] key = crypto.decryptWithPassword(encrypted, password);
|
||||
if (key == null) {
|
||||
@@ -62,9 +62,9 @@ public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePassword(final String password, final String newPassword,
|
||||
final ResultHandler<Boolean> resultHandler) {
|
||||
final byte[] encrypted = getEncryptedKey();
|
||||
public void changePassword(String password, String newPassword,
|
||||
ResultHandler<Boolean> resultHandler) {
|
||||
byte[] encrypted = getEncryptedKey();
|
||||
cryptoExecutor.execute(() -> {
|
||||
byte[] key = crypto.decryptWithPassword(encrypted, password);
|
||||
if (key == null) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
@@ -283,8 +282,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
if (daysUntilExpiry < 0) signOut();
|
||||
|
||||
// show expiry warning text
|
||||
final ViewGroup
|
||||
expiryWarning = (ViewGroup) findViewById(R.id.expiryWarning);
|
||||
ViewGroup expiryWarning = (ViewGroup) findViewById(R.id.expiryWarning);
|
||||
TextView expiryWarningText =
|
||||
(TextView) expiryWarning.findViewById(R.id.expiryWarningText);
|
||||
// make close button functional
|
||||
@@ -320,20 +318,16 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme)
|
||||
.setMessage(R.string.setup_doze_intro)
|
||||
.setPositiveButton(R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog,
|
||||
int which) {
|
||||
Intent i = getDozeWhitelistingIntent(
|
||||
NavDrawerActivity.this);
|
||||
startActivityForResult(i,
|
||||
REQUEST_DOZE_WHITELISTING);
|
||||
}
|
||||
(dialog, which) -> {
|
||||
Intent i = getDozeWhitelistingIntent(
|
||||
NavDrawerActivity.this);
|
||||
startActivityForResult(i,
|
||||
REQUEST_DOZE_WHITELISTING);
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private void initializeTransports(final LayoutInflater inflater) {
|
||||
private void initializeTransports(LayoutInflater inflater) {
|
||||
transports = new ArrayList<>(3);
|
||||
|
||||
Transport tor = new Transport();
|
||||
@@ -407,7 +401,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
};
|
||||
}
|
||||
|
||||
private void setTransport(final TransportId id, final boolean enabled) {
|
||||
private void setTransport(TransportId id, boolean enabled) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (transports == null || transportsAdapter == null) return;
|
||||
for (Transport t : transports) {
|
||||
|
||||
@@ -8,11 +8,11 @@ import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||
@NotNullByDefault
|
||||
public interface NavDrawerController extends ActivityLifecycleController {
|
||||
|
||||
enum ExpiryWarning { SHOW, NO, UPDATE };
|
||||
enum ExpiryWarning { SHOW, NO, UPDATE }
|
||||
|
||||
boolean isTransportRunning(TransportId transportId);
|
||||
|
||||
void showExpiryWarning(final ResultHandler<ExpiryWarning> handler);
|
||||
void showExpiryWarning(ResultHandler<ExpiryWarning> handler);
|
||||
|
||||
void expiryWarningDismissed();
|
||||
|
||||
|
||||
@@ -96,14 +96,13 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
}
|
||||
}
|
||||
|
||||
private void transportStateUpdate(final TransportId id,
|
||||
final boolean enabled) {
|
||||
private void transportStateUpdate(TransportId id, boolean enabled) {
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.stateUpdate(id, enabled));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showExpiryWarning(final ResultHandler<ExpiryWarning> handler) {
|
||||
public void showExpiryWarning(ResultHandler<ExpiryWarning> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Settings settings =
|
||||
|
||||
@@ -110,7 +110,7 @@ public class GroupActivity extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNamedGroupLoaded(final PrivateGroup group) {
|
||||
protected void onNamedGroupLoaded(PrivateGroup group) {
|
||||
setTitle(group.getName());
|
||||
controller.loadLocalAuthor(
|
||||
new UiResultExceptionHandler<LocalAuthor, DbException>(this) {
|
||||
@@ -144,7 +144,7 @@ public class GroupActivity extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_group_member_list:
|
||||
Intent i1 = new Intent(this, GroupMemberListActivity.class);
|
||||
|
||||
@@ -83,13 +83,12 @@ class GroupControllerImpl extends
|
||||
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
||||
if (!g.isLocal() && g.getGroupId().equals(getGroupId())) {
|
||||
LOG.info("Group message received, adding...");
|
||||
final GroupMessageItem item =
|
||||
buildItem(g.getHeader(), g.getBody());
|
||||
GroupMessageItem item = buildItem(g.getHeader(), g.getBody());
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onItemReceived(item));
|
||||
}
|
||||
} else if (e instanceof ContactRelationshipRevealedEvent) {
|
||||
final ContactRelationshipRevealedEvent c =
|
||||
ContactRelationshipRevealedEvent c =
|
||||
(ContactRelationshipRevealedEvent) e;
|
||||
if (getGroupId().equals(c.getGroupId())) {
|
||||
listener.runOnUiThreadUnlessDestroyed(() ->
|
||||
@@ -99,7 +98,7 @@ class GroupControllerImpl extends
|
||||
} else if (e instanceof GroupInvitationResponseReceivedEvent) {
|
||||
GroupInvitationResponseReceivedEvent g =
|
||||
(GroupInvitationResponseReceivedEvent) e;
|
||||
final GroupInvitationResponse r =
|
||||
GroupInvitationResponse r =
|
||||
(GroupInvitationResponse) g.getResponse();
|
||||
if (getGroupId().equals(r.getShareableId()) && r.wasAccepted()) {
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
@@ -141,7 +140,7 @@ class GroupControllerImpl extends
|
||||
|
||||
@Override
|
||||
public void loadSharingContacts(
|
||||
final ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Collection<GroupMember> members =
|
||||
@@ -160,9 +159,9 @@ class GroupControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndStoreMessage(final String body,
|
||||
@Nullable final GroupMessageItem parentItem,
|
||||
final ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||
public void createAndStoreMessage(String body,
|
||||
@Nullable GroupMessageItem parentItem,
|
||||
ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
LocalAuthor author = identityManager.getLocalAuthor();
|
||||
@@ -183,10 +182,10 @@ class GroupControllerImpl extends
|
||||
});
|
||||
}
|
||||
|
||||
private void createMessage(final String body, final long timestamp,
|
||||
final @Nullable MessageId parentId, final LocalAuthor author,
|
||||
final MessageId previousMsgId,
|
||||
final ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||
private void createMessage(String body, long timestamp,
|
||||
@Nullable MessageId parentId, LocalAuthor author,
|
||||
MessageId previousMsgId,
|
||||
ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||
cryptoExecutor.execute(() -> {
|
||||
LOG.info("Creating group message...");
|
||||
GroupMessage msg = groupMessageFactory
|
||||
@@ -218,7 +217,7 @@ class GroupControllerImpl extends
|
||||
|
||||
@Override
|
||||
public void loadLocalAuthor(
|
||||
final ResultExceptionHandler<LocalAuthor, DbException> handler) {
|
||||
ResultExceptionHandler<LocalAuthor, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
LocalAuthor author = identityManager.getLocalAuthor();
|
||||
|
||||
@@ -32,7 +32,7 @@ class JoinMessageItemViewHolder
|
||||
else bind((JoinMessageItem) item);
|
||||
}
|
||||
|
||||
private void bindForCreator(final JoinMessageItem item) {
|
||||
private void bindForCreator(JoinMessageItem item) {
|
||||
if (item.isInitial()) {
|
||||
textView.setText(R.string.groups_member_created_you);
|
||||
} else {
|
||||
@@ -42,8 +42,8 @@ class JoinMessageItemViewHolder
|
||||
}
|
||||
}
|
||||
|
||||
private void bind(final JoinMessageItem item) {
|
||||
final Context ctx = getContext();
|
||||
private void bind(JoinMessageItem item) {
|
||||
Context ctx = getContext();
|
||||
|
||||
if (item.isInitial()) {
|
||||
textView.setText(ctx.getString(R.string.groups_member_created,
|
||||
|
||||
@@ -74,8 +74,8 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createGroup(final String name,
|
||||
final ResultExceptionHandler<GroupId, DbException> handler) {
|
||||
public void createGroup(String name,
|
||||
ResultExceptionHandler<GroupId, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
LocalAuthor author = identityManager.getLocalAuthor();
|
||||
@@ -87,9 +87,8 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
});
|
||||
}
|
||||
|
||||
private void createGroupAndMessages(final LocalAuthor author,
|
||||
final String name,
|
||||
final ResultExceptionHandler<GroupId, DbException> handler) {
|
||||
private void createGroupAndMessages(LocalAuthor author, String name,
|
||||
ResultExceptionHandler<GroupId, DbException> handler) {
|
||||
cryptoExecutor.execute(() -> {
|
||||
LOG.info("Creating group...");
|
||||
PrivateGroup group =
|
||||
@@ -102,9 +101,8 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
});
|
||||
}
|
||||
|
||||
private void storeGroup(final PrivateGroup group,
|
||||
final GroupMessage joinMsg,
|
||||
final ResultExceptionHandler<GroupId, DbException> handler) {
|
||||
private void storeGroup(PrivateGroup group, GroupMessage joinMsg,
|
||||
ResultExceptionHandler<GroupId, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
LOG.info("Adding group to database...");
|
||||
try {
|
||||
@@ -123,9 +121,8 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInvitation(final GroupId g,
|
||||
final Collection<ContactId> contactIds, final String message,
|
||||
final ResultExceptionHandler<Void, DbException> handler) {
|
||||
public void sendInvitation(GroupId g, Collection<ContactId> contactIds,
|
||||
String message, ResultExceptionHandler<Void, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
@@ -145,9 +142,9 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
});
|
||||
}
|
||||
|
||||
private void signInvitations(final GroupId g, final LocalAuthor localAuthor,
|
||||
final Collection<Contact> contacts, final String message,
|
||||
final ResultExceptionHandler<Void, DbException> handler) {
|
||||
private void signInvitations(GroupId g, LocalAuthor localAuthor,
|
||||
Collection<Contact> contacts, String message,
|
||||
ResultExceptionHandler<Void, DbException> handler) {
|
||||
cryptoExecutor.execute(() -> {
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
List<InvitationContext> contexts = new ArrayList<>();
|
||||
@@ -161,9 +158,9 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
});
|
||||
}
|
||||
|
||||
private void sendInvitations(final GroupId g,
|
||||
final Collection<InvitationContext> contexts, final String message,
|
||||
final ResultExceptionHandler<Void, DbException> handler) {
|
||||
private void sendInvitations(GroupId g,
|
||||
Collection<InvitationContext> contexts, String message,
|
||||
ResultExceptionHandler<Void, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
String msg = message.isEmpty() ? null : message;
|
||||
|
||||
@@ -64,9 +64,8 @@ class GroupInvitationControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void respondToInvitation(final GroupInvitationItem item,
|
||||
final boolean accept,
|
||||
final ExceptionHandler<DbException> handler) {
|
||||
public void respondToInvitation(GroupInvitationItem item, boolean accept,
|
||||
ExceptionHandler<DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
PrivateGroup g = item.getShareable();
|
||||
|
||||
@@ -17,8 +17,8 @@ class GroupInvitationViewHolder
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBind(@Nullable final GroupInvitationItem item,
|
||||
final InvitationClickListener<GroupInvitationItem> listener) {
|
||||
public void onBind(@Nullable GroupInvitationItem item,
|
||||
InvitationClickListener<GroupInvitationItem> listener) {
|
||||
super.onBind(item, listener);
|
||||
if (item == null) return;
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ class GroupListControllerImpl extends DbControllerImpl
|
||||
}
|
||||
}
|
||||
|
||||
private void onGroupMessageAdded(final GroupMessageHeader h) {
|
||||
private void onGroupMessageAdded(GroupMessageHeader h) {
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onGroupMessageAdded(h));
|
||||
}
|
||||
@@ -129,22 +129,22 @@ class GroupListControllerImpl extends DbControllerImpl
|
||||
() -> listener.onGroupInvitationReceived());
|
||||
}
|
||||
|
||||
private void onGroupAdded(final GroupId g) {
|
||||
private void onGroupAdded(GroupId g) {
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> listener.onGroupAdded(g));
|
||||
}
|
||||
|
||||
private void onGroupRemoved(final GroupId g) {
|
||||
private void onGroupRemoved(GroupId g) {
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> listener.onGroupRemoved(g));
|
||||
}
|
||||
|
||||
private void onGroupDissolved(final GroupId g) {
|
||||
private void onGroupDissolved(GroupId g) {
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onGroupDissolved(g));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadGroups(
|
||||
final ResultExceptionHandler<Collection<GroupItem>, DbException> handler) {
|
||||
ResultExceptionHandler<Collection<GroupItem>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -173,8 +173,7 @@ class GroupListControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(final GroupId g,
|
||||
final ExceptionHandler<DbException> handler) {
|
||||
public void removeGroup(GroupId g, ExceptionHandler<DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -191,7 +190,7 @@ class GroupListControllerImpl extends DbControllerImpl
|
||||
|
||||
@Override
|
||||
public void loadAvailableGroups(
|
||||
final ResultExceptionHandler<Integer, DbException> handler) {
|
||||
ResultExceptionHandler<Integer, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
handler.onResult(
|
||||
|
||||
@@ -113,7 +113,7 @@ public class GroupListFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_add_group:
|
||||
Intent i = new Intent(getContext(), CreateGroupActivity.class);
|
||||
@@ -184,7 +184,7 @@ public class GroupListFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
private void loadGroups() {
|
||||
final int revision = adapter.getRevision();
|
||||
int revision = adapter.getRevision();
|
||||
controller.loadGroups(
|
||||
new UiResultExceptionHandler<Collection<GroupItem>, DbException>(
|
||||
this) {
|
||||
|
||||
@@ -50,8 +50,8 @@ class GroupViewHolder extends RecyclerView.ViewHolder {
|
||||
remove = (Button) v.findViewById(R.id.removeButton);
|
||||
}
|
||||
|
||||
void bindView(final Context ctx, final GroupItem group,
|
||||
final OnGroupRemoveClickListener listener) {
|
||||
void bindView(Context ctx, GroupItem group,
|
||||
OnGroupRemoveClickListener listener) {
|
||||
// Avatar
|
||||
avatar.setText(group.getName().substring(0, 1));
|
||||
avatar.setBackgroundBytes(group.getId().getBytes());
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GroupMemberListActivity extends BriarActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle state) {
|
||||
public void onCreate(@Nullable Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
setContentView(R.layout.activity_sharing_status);
|
||||
|
||||
@@ -40,7 +40,7 @@ class GroupMemberListControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMembers(final GroupId groupId, final
|
||||
public void loadMembers(GroupId groupId,
|
||||
ResultExceptionHandler<Collection<MemberListItem>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
|
||||
@@ -59,9 +59,8 @@ class RevealContactsControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadContacts(final GroupId g,
|
||||
final Collection<ContactId> selection,
|
||||
final ResultExceptionHandler<Collection<RevealableContactItem>, DbException> handler) {
|
||||
public void loadContacts(GroupId g, Collection<ContactId> selection,
|
||||
ResultExceptionHandler<Collection<RevealableContactItem>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
handler.onResult(getItems(g, selection));
|
||||
@@ -98,7 +97,7 @@ class RevealContactsControllerImpl extends DbControllerImpl
|
||||
|
||||
@Override
|
||||
public void isOnboardingNeeded(
|
||||
final ResultExceptionHandler<Boolean, DbException> handler) {
|
||||
ResultExceptionHandler<Boolean, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Settings settings =
|
||||
@@ -129,8 +128,8 @@ class RevealContactsControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reveal(final GroupId g, final Collection<ContactId> contacts,
|
||||
final ExceptionHandler<DbException> handler) {
|
||||
public void reveal(GroupId g, Collection<ContactId> contacts,
|
||||
ExceptionHandler<DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
for (ContactId c : contacts) {
|
||||
try {
|
||||
|
||||
@@ -93,7 +93,7 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
|
||||
getDelegate().setSupportActionBar(tb);
|
||||
|
||||
final View requestReport = findViewById(R.id.request_report);
|
||||
View requestReport = findViewById(R.id.request_report);
|
||||
userCommentView = (EditText) findViewById(R.id.user_comment);
|
||||
userEmailView = (EditText) findViewById(R.id.user_email);
|
||||
includeDebugReport = (CheckBox) findViewById(R.id.include_debug_report);
|
||||
@@ -170,7 +170,7 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle presses on the action bar items
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
@@ -243,8 +243,7 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
protected CrashReportData doInBackground(Void... args) {
|
||||
File reportFile = (File) getIntent().getSerializableExtra(
|
||||
EXTRA_REPORT_FILE);
|
||||
final CrashReportPersister persister =
|
||||
new CrashReportPersister();
|
||||
CrashReportPersister persister = new CrashReportPersister();
|
||||
try {
|
||||
return persister.load(reportFile);
|
||||
} catch (IOException e) {
|
||||
@@ -293,8 +292,7 @@ public class DevReportActivity extends BaseCrashReportDialog
|
||||
userEmailView.setEnabled(false);
|
||||
sendReport.setEnabled(false);
|
||||
progress.setVisibility(VISIBLE);
|
||||
final boolean includeReport =
|
||||
!isFeedback() || includeDebugReport.isChecked();
|
||||
boolean includeReport = !isFeedback() || includeDebugReport.isChecked();
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
|
||||
@Override
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user