diff --git a/bramble-core/src/main/java/org/briarproject/bramble/BrambleCoreModule.java b/bramble-core/src/main/java/org/briarproject/bramble/BrambleCoreModule.java index 473df2b77..8d34971d3 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/BrambleCoreModule.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/BrambleCoreModule.java @@ -21,7 +21,6 @@ import org.briarproject.bramble.rendezvous.RendezvousModule; import org.briarproject.bramble.settings.SettingsModule; import org.briarproject.bramble.sync.SyncModule; import org.briarproject.bramble.sync.validation.ValidationModule; -import org.briarproject.bramble.system.ClockModule; import org.briarproject.bramble.transport.TransportModule; import org.briarproject.bramble.versioning.VersioningModule; @@ -29,7 +28,6 @@ import dagger.Module; @Module(includes = { ClientModule.class, - ClockModule.class, ConnectionModule.class, ContactModule.class, CryptoModule.class, diff --git a/bramble-core/src/test/java/org/briarproject/bramble/test/BrambleCoreIntegrationTestModule.java b/bramble-core/src/test/java/org/briarproject/bramble/test/BrambleCoreIntegrationTestModule.java index 4ac540199..778219038 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/test/BrambleCoreIntegrationTestModule.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/test/BrambleCoreIntegrationTestModule.java @@ -14,6 +14,7 @@ import dagger.Provides; DefaultEventExecutorModule.class, DefaultTaskSchedulerModule.class, DefaultWakefulIoExecutorModule.class, + TestClockModule.class, TestDatabaseConfigModule.class, TestPluginConfigModule.class, TestSecureRandomModule.class diff --git a/bramble-core/src/test/java/org/briarproject/bramble/test/TestClockModule.java b/bramble-core/src/test/java/org/briarproject/bramble/test/TestClockModule.java new file mode 100644 index 000000000..b40bf54ec --- /dev/null +++ b/bramble-core/src/test/java/org/briarproject/bramble/test/TestClockModule.java @@ -0,0 +1,28 @@ +package org.briarproject.bramble.test; + +import org.briarproject.bramble.api.system.Clock; +import org.briarproject.bramble.system.SystemClock; + +import java.util.concurrent.atomic.AtomicLong; + +import dagger.Module; +import dagger.Provides; + +@Module +public class TestClockModule { + + private final Clock clock; + + public TestClockModule() { + clock = new SystemClock(); + } + + public TestClockModule(AtomicLong time) { + clock = new SettableClock(time); + } + + @Provides + Clock provideClock() { + return clock; + } +} diff --git a/bramble-java/src/main/java/org/briarproject/bramble/BrambleJavaModule.java b/bramble-java/src/main/java/org/briarproject/bramble/BrambleJavaModule.java index 6ef05f5f1..f50ea15ae 100644 --- a/bramble-java/src/main/java/org/briarproject/bramble/BrambleJavaModule.java +++ b/bramble-java/src/main/java/org/briarproject/bramble/BrambleJavaModule.java @@ -8,9 +8,9 @@ import org.briarproject.bramble.system.JavaSystemModule; import dagger.Module; @Module(includes = { + CircumventionModule.class, JavaNetworkModule.class, JavaSystemModule.class, - CircumventionModule.class, SocksModule.class }) public class BrambleJavaModule { diff --git a/briar-android/src/main/java/org/briarproject/briar/android/AndroidComponent.java b/briar-android/src/main/java/org/briarproject/briar/android/AndroidComponent.java index 30d1dc87c..5058cf982 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/AndroidComponent.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/AndroidComponent.java @@ -29,6 +29,7 @@ import org.briarproject.bramble.api.system.AndroidWakeLockManager; import org.briarproject.bramble.api.system.Clock; import org.briarproject.bramble.api.system.LocationUtils; import org.briarproject.bramble.plugin.tor.CircumventionProvider; +import org.briarproject.bramble.system.ClockModule; import org.briarproject.briar.BriarCoreEagerSingletons; import org.briarproject.briar.BriarCoreModule; import org.briarproject.briar.android.attachment.AttachmentModule; @@ -76,6 +77,7 @@ import dagger.Component; BriarAccountModule.class, AppModule.class, AttachmentModule.class, + ClockModule.class, MediaModule.class }) public interface AndroidComponent diff --git a/briar-core/src/test/java/org/briarproject/briar/blog/BlogManagerIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/blog/BlogManagerIntegrationTest.java index 84d104e74..f14a83e6e 100644 --- a/briar-core/src/test/java/org/briarproject/briar/blog/BlogManagerIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/blog/BlogManagerIntegrationTest.java @@ -127,7 +127,7 @@ public class BlogManagerIntegrationTest // add a post to blog0 BlogPost p = blogPostFactory.createBlogPost(blog0.getId(), - clock.currentTimeMillis(), null, author0, text); + c0.getClock().currentTimeMillis(), null, author0, text); blogManager0.addLocalPost(p); // check that post is now in blog0 @@ -158,9 +158,8 @@ public class BlogManagerIntegrationTest public void testBlogPostInWrongBlog() throws Exception { // add a post to blog1 String text = getRandomString(42); - BlogPost p = blogPostFactory - .createBlogPost(blog1.getId(), clock.currentTimeMillis(), null, - author0, text); + BlogPost p = blogPostFactory.createBlogPost(blog1.getId(), + c0.getClock().currentTimeMillis(), null, author0, text); blogManager0.addLocalPost(p); // check that post is now in blog1 @@ -197,9 +196,8 @@ public class BlogManagerIntegrationTest public void testBlogComment() throws Exception { // add a post to blog0 String text = getRandomString(42); - BlogPost p = blogPostFactory - .createBlogPost(blog0.getId(), clock.currentTimeMillis(), null, - author0, text); + BlogPost p = blogPostFactory.createBlogPost(blog0.getId(), + c0.getClock().currentTimeMillis(), null, author0, text); blogManager0.addLocalPost(p); // sync the post over @@ -242,9 +240,8 @@ public class BlogManagerIntegrationTest public void testBlogCommentOnOwnPost() throws Exception { // add a post to blog0 String text = getRandomString(42); - BlogPost p = blogPostFactory - .createBlogPost(blog0.getId(), clock.currentTimeMillis(), null, - author0, text); + BlogPost p = blogPostFactory.createBlogPost(blog0.getId(), + c0.getClock().currentTimeMillis(), null, author0, text); blogManager0.addLocalPost(p); // get header of own post @@ -278,9 +275,8 @@ public class BlogManagerIntegrationTest public void testCommentOnComment() throws Exception { // add a post to blog0 String text = getRandomString(42); - BlogPost p = blogPostFactory - .createBlogPost(blog0.getId(), clock.currentTimeMillis(), null, - author0, text); + BlogPost p = blogPostFactory.createBlogPost(blog0.getId(), + c0.getClock().currentTimeMillis(), null, author0, text); blogManager0.addLocalPost(p); // sync the post over @@ -366,9 +362,8 @@ public class BlogManagerIntegrationTest public void testCommentOnOwnComment() throws Exception { // add a post to blog0 String text = getRandomString(42); - BlogPost p = blogPostFactory - .createBlogPost(blog0.getId(), clock.currentTimeMillis(), null, - author0, text); + BlogPost p = blogPostFactory.createBlogPost(blog0.getId(), + c0.getClock().currentTimeMillis(), null, author0, text); blogManager0.addLocalPost(p); // sync the post over @@ -411,9 +406,8 @@ public class BlogManagerIntegrationTest // add a feed post to rssBlog String text = getRandomString(42); - BlogPost p = blogPostFactory - .createBlogPost(rssBlog.getId(), clock.currentTimeMillis(), - null, author0, text); + BlogPost p = blogPostFactory.createBlogPost(rssBlog.getId(), + c0.getClock().currentTimeMillis(), null, author0, text); blogManager0.addLocalPost(p); // make sure it got saved as an RSS feed post @@ -430,9 +424,8 @@ public class BlogManagerIntegrationTest public void testFeedReblog() throws Exception { // add a feed post to rssBlog String text = getRandomString(42); - BlogPost p = blogPostFactory - .createBlogPost(rssBlog.getId(), clock.currentTimeMillis(), - null, author0, text); + BlogPost p = blogPostFactory.createBlogPost(rssBlog.getId(), + c0.getClock().currentTimeMillis(), null, author0, text); blogManager0.addLocalPost(p); // reblog feed post to own blog diff --git a/briar-core/src/test/java/org/briarproject/briar/forum/ForumManagerTest.java b/briar-core/src/test/java/org/briarproject/briar/forum/ForumManagerTest.java index 65f80d282..05cc4544b 100644 --- a/briar-core/src/test/java/org/briarproject/briar/forum/ForumManagerTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/forum/ForumManagerTest.java @@ -84,9 +84,9 @@ public class ForumManagerTest @Test public void testForumPost() throws Exception { assertEquals(1, forumManager0.getForums().size()); - long ms1 = clock.currentTimeMillis() - 1000L; + long ms1 = c0.getClock().currentTimeMillis() - 1000L; String text1 = "some forum text"; - long ms2 = clock.currentTimeMillis(); + long ms2 = c0.getClock().currentTimeMillis(); String text2 = "some other forum text"; ForumPost post1 = createForumPost(forum0.getGroup().getId(), null, text1, ms1); @@ -136,7 +136,7 @@ public class ForumManagerTest @Test public void testForumPostDelivery() throws Exception { // add one forum post - long time = clock.currentTimeMillis(); + long time = c0.getClock().currentTimeMillis(); ForumPost post1 = createForumPost(groupId0, null, "a", time); forumManager0.addLocalPost(post1); assertEquals(1, forumManager0.getPostHeaders(groupId0).size()); @@ -150,7 +150,7 @@ public class ForumManagerTest assertGroupCount(messageTracker1, groupId0, 1, 1, time); // add another forum post - long time2 = clock.currentTimeMillis(); + long time2 = c0.getClock().currentTimeMillis(); ForumPost post2 = createForumPost(groupId0, null, "b", time2); forumManager1.addLocalPost(post2); assertEquals(1, forumManager0.getPostHeaders(groupId0).size()); @@ -167,7 +167,7 @@ public class ForumManagerTest @Test public void testForumPostDeliveredAfterParent() throws Exception { // add one forum post without the parent - long time = clock.currentTimeMillis(); + long time = c0.getClock().currentTimeMillis(); ForumPost post1 = createForumPost(groupId0, null, "a", time); ForumPost post2 = createForumPost(groupId0, post1, "a", time); forumManager0.addLocalPost(post2); @@ -199,7 +199,7 @@ public class ForumManagerTest sync1To0(1, true); // add one forum post with a parent in another forum - long time = clock.currentTimeMillis(); + long time = c0.getClock().currentTimeMillis(); ForumPost post1 = createForumPost(g1, null, "a", time); ForumPost post = createForumPost(groupId0, post1, "b", time); forumManager0.addLocalPost(post); diff --git a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java index 7ffdc7ccb..0680e3787 100644 --- a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java @@ -1042,10 +1042,12 @@ public class IntroductionIntegrationTest contactManager1.removeContact(contactId0From1); SecretKey rootKey0_1 = getSecretKey(); contactId1From0 = contactManager0.addContact(author1, author0.getId(), - rootKey0_1, clock.currentTimeMillis(), true, true, true); + rootKey0_1, c0.getClock().currentTimeMillis(), true, true, + true); contact1From0 = contactManager0.getContact(contactId1From0); contactId0From1 = contactManager1.addContact(author0, author1.getId(), - rootKey0_1, clock.currentTimeMillis(), false, true, true); + rootKey0_1, c1.getClock().currentTimeMillis(), false, true, + true); contact0From1 = contactManager1.getContact(contactId0From1); // Sync initial client versioning updates and transport properties @@ -1169,7 +1171,7 @@ public class IntroductionIntegrationTest m -> new AcceptMessage(m.getMessageId(), m.getGroupId(), m.getTimestamp(), m.getPreviousMessageId(), m.getSessionId(), m.getEphemeralPublicKey(), - clock.currentTimeMillis(), + c0.getClock().currentTimeMillis(), m.getTransportProperties(), NO_AUTO_DELETE_TIMER) ); } diff --git a/briar-core/src/test/java/org/briarproject/briar/messaging/MessagingManagerIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/messaging/MessagingManagerIntegrationTest.java index ccf1bf72a..2c534363b 100644 --- a/briar-core/src/test/java/org/briarproject/briar/messaging/MessagingManagerIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/messaging/MessagingManagerIntegrationTest.java @@ -256,7 +256,7 @@ public class MessagingManagerIntegrationTest // send legacy message GroupId g = c0.getMessagingManager().getConversationId(contactId); PrivateMessage m0 = messageFactory.createLegacyPrivateMessage(g, - clock.currentTimeMillis(), getRandomString(42)); + c0.getClock().currentTimeMillis(), getRandomString(42)); c0.getMessagingManager().addLocalMessage(m0); syncMessage(c0, c1, contactId, 1, true); @@ -384,7 +384,8 @@ public class MessagingManagerIntegrationTest throws Exception { GroupId g = from.getMessagingManager().getConversationId(contactId); PrivateMessage m = messageFactory.createPrivateMessage(g, - clock.currentTimeMillis(), text, attachments, autoDeleteTimer); + from.getClock().currentTimeMillis(), text, attachments, + autoDeleteTimer); from.getMessagingManager().addLocalMessage(m); syncMessage(from, to, contactId, 1 + attachments.size(), true); return m; @@ -395,7 +396,7 @@ public class MessagingManagerIntegrationTest GroupId g = c.getMessagingManager().getConversationId(contactId); InputStream stream = new ByteArrayInputStream(getRandomBytes(42)); return c.getMessagingManager().addLocalAttachment(g, - clock.currentTimeMillis(), "image/jpeg", stream); + c.getClock().currentTimeMillis(), "image/jpeg", stream); } private Collection getMessages( diff --git a/briar-core/src/test/java/org/briarproject/briar/privategroup/PrivateGroupIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/privategroup/PrivateGroupIntegrationTest.java index 2c5b6cf8d..8d9ebbeb0 100644 --- a/briar-core/src/test/java/org/briarproject/briar/privategroup/PrivateGroupIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/privategroup/PrivateGroupIntegrationTest.java @@ -61,7 +61,7 @@ public class PrivateGroupIntegrationTest privateGroup0 = privateGroupFactory.createPrivateGroup("Test Group", author0); groupId0 = privateGroup0.getId(); - long joinTime = clock.currentTimeMillis(); + long joinTime = c0.getClock().currentTimeMillis(); GroupMessage joinMsg0 = groupMessageFactory .createJoinMessage(groupId0, joinTime, author0); groupManager0.addPrivateGroup(privateGroup0, joinMsg0, true); @@ -92,7 +92,8 @@ public class PrivateGroupIntegrationTest @Test public void testMembership() throws Exception { - sendInvitation(contactId1From0, clock.currentTimeMillis(), "Hi!"); + sendInvitation(contactId1From0, c0.getClock().currentTimeMillis(), + "Hi!"); // our group has only one member (ourselves) Collection members = groupManager0.getMembers(groupId0); @@ -135,8 +136,10 @@ public class PrivateGroupIntegrationTest @Test public void testRevealContacts() throws Exception { // invite two contacts - sendInvitation(contactId1From0, clock.currentTimeMillis(), "Hi 1!"); - sendInvitation(contactId2From0, clock.currentTimeMillis(), "Hi 2!"); + sendInvitation(contactId1From0, c0.getClock().currentTimeMillis(), + "Hi 1!"); + sendInvitation(contactId2From0, c0.getClock().currentTimeMillis(), + "Hi 2!"); sync0To1(1, true); sync0To2(1, true); @@ -182,7 +185,7 @@ public class PrivateGroupIntegrationTest getGroupMember(groupManager2, author1.getId()).getVisibility()); // 2 sends a message to the group - long time = clock.currentTimeMillis(); + long time = c2.getClock().currentTimeMillis(); String text = "This is a test message!"; MessageId previousMsgId = groupManager2.getPreviousMsgId(groupId0); GroupMessage msg = groupMessageFactory diff --git a/briar-core/src/test/java/org/briarproject/briar/privategroup/PrivateGroupManagerIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/privategroup/PrivateGroupManagerIntegrationTest.java index 8dd6e855b..60a273145 100644 --- a/briar-core/src/test/java/org/briarproject/briar/privategroup/PrivateGroupManagerIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/privategroup/PrivateGroupManagerIntegrationTest.java @@ -83,7 +83,7 @@ public class PrivateGroupManagerIntegrationTest addGroup(); // create and add test message - long time = clock.currentTimeMillis(); + long time = c0.getClock().currentTimeMillis(); String text = "This is a test message!"; MessageId previousMsgId = groupManager0.getPreviousMsgId(groupId0); @@ -125,7 +125,7 @@ public class PrivateGroupManagerIntegrationTest // create and add test message with no previousMsgId GroupMessage msg = groupMessageFactory.createGroupMessage(groupId0, - clock.currentTimeMillis(), null, author0, "test", null); + c0.getClock().currentTimeMillis(), null, author0, "test", null); groupManager0.addLocalMessage(msg); // sync test message @@ -136,9 +136,9 @@ public class PrivateGroupManagerIntegrationTest // create and add test message with random previousMsgId MessageId previousMsgId = new MessageId(getRandomId()); - msg = groupMessageFactory - .createGroupMessage(groupId0, clock.currentTimeMillis(), null, - author0, "test", previousMsgId); + msg = groupMessageFactory.createGroupMessage(groupId0, + c0.getClock().currentTimeMillis(), null, author0, "test", + previousMsgId); groupManager0.addLocalMessage(msg); // sync test message @@ -149,9 +149,9 @@ public class PrivateGroupManagerIntegrationTest // create and add test message with wrong previousMsgId previousMsgId = groupManager1.getPreviousMsgId(groupId0); - msg = groupMessageFactory - .createGroupMessage(groupId0, clock.currentTimeMillis(), null, - author0, "test", previousMsgId); + msg = groupMessageFactory.createGroupMessage(groupId0, + c0.getClock().currentTimeMillis(), null, author0, "test", + previousMsgId); groupManager0.addLocalMessage(msg); // sync test message @@ -168,9 +168,9 @@ public class PrivateGroupManagerIntegrationTest // create and add test message with random parentMsgId MessageId parentMsgId = new MessageId(getRandomId()); MessageId previousMsgId = groupManager0.getPreviousMsgId(groupId0); - GroupMessage msg = groupMessageFactory - .createGroupMessage(groupId0, clock.currentTimeMillis(), - parentMsgId, author0, "test", previousMsgId); + GroupMessage msg = groupMessageFactory.createGroupMessage(groupId0, + c0.getClock().currentTimeMillis(), parentMsgId, author0, "test", + previousMsgId); groupManager0.addLocalMessage(msg); // sync test message @@ -181,9 +181,9 @@ public class PrivateGroupManagerIntegrationTest // create and add test message with wrong parentMsgId parentMsgId = previousMsgId; - msg = groupMessageFactory - .createGroupMessage(groupId0, clock.currentTimeMillis(), - parentMsgId, author0, "test", previousMsgId); + msg = groupMessageFactory.createGroupMessage(groupId0, + c0.getClock().currentTimeMillis(), parentMsgId, author0, "test", + previousMsgId); groupManager0.addLocalMessage(msg); // sync test message @@ -211,7 +211,7 @@ public class PrivateGroupManagerIntegrationTest assertEquals(2, groupManager1.getHeaders(groupId0).size()); // create and add test message with good timestamp - long time = clock.currentTimeMillis(); + long time = c0.getClock().currentTimeMillis(); msg = groupMessageFactory .createGroupMessage(groupId0, time, null, author0, "test", previousMsgId); @@ -238,7 +238,7 @@ public class PrivateGroupManagerIntegrationTest @Test public void testWrongJoinMessages1() throws Exception { // author0 joins privateGroup0 with wrong join message - long joinTime = clock.currentTimeMillis(); + long joinTime = c0.getClock().currentTimeMillis(); GroupMessage joinMsg0 = groupMessageFactory .createJoinMessage(privateGroup0.getId(), joinTime, author0, joinTime, getRandomBytes(12)); @@ -251,7 +251,7 @@ public class PrivateGroupManagerIntegrationTest contactId1From0, privateGroup0.getId(), SHARED)); // author1 joins privateGroup0 with wrong timestamp - joinTime = clock.currentTimeMillis(); + joinTime = c1.getClock().currentTimeMillis(); long inviteTime = joinTime; Contact c1 = contactManager0.getContact(contactId1From0); byte[] creatorSignature = groupInvitationFactory @@ -283,7 +283,7 @@ public class PrivateGroupManagerIntegrationTest @Test public void testWrongJoinMessages2() throws Exception { // author0 joins privateGroup0 with wrong member's join message - long joinTime = clock.currentTimeMillis(); + long joinTime = c0.getClock().currentTimeMillis(); long inviteTime = joinTime - 1; BdfList toSign = groupInvitationFactory .createInviteToken(author0.getId(), author0.getId(), @@ -303,7 +303,7 @@ public class PrivateGroupManagerIntegrationTest contactId1From0, privateGroup0.getId(), SHARED)); // author1 joins privateGroup0 with wrong signature in join message - joinTime = clock.currentTimeMillis(); + joinTime = c1.getClock().currentTimeMillis(); inviteTime = joinTime - 1; // signature uses joiner's key, not creator's key Contact c1 = contactManager0.getContact(contactId1From0); @@ -365,7 +365,7 @@ public class PrivateGroupManagerIntegrationTest contactId2From0, privateGroup0.getId(), SHARED)); // author2 joins privateGroup0 - long joinTime = clock.currentTimeMillis(); + long joinTime = c2.getClock().currentTimeMillis(); long inviteTime = joinTime - 1; Contact c2 = contactManager0.getContact(contactId2From0); byte[] creatorSignature = groupInvitationFactory @@ -447,7 +447,7 @@ public class PrivateGroupManagerIntegrationTest private void addGroup() throws Exception { // author0 joins privateGroup0 - long joinTime = clock.currentTimeMillis(); + long joinTime = c0.getClock().currentTimeMillis(); GroupMessage joinMsg0 = groupMessageFactory .createJoinMessage(privateGroup0.getId(), joinTime, author0); groupManager0.addPrivateGroup(privateGroup0, joinMsg0, true); @@ -459,7 +459,7 @@ public class PrivateGroupManagerIntegrationTest contactId1From0, privateGroup0.getId(), SHARED)); // author1 joins privateGroup0 - joinTime = clock.currentTimeMillis(); + joinTime = c1.getClock().currentTimeMillis(); long inviteTime = joinTime - 1; Contact c1 = contactManager0.getContact(contactId1From0); byte[] creatorSignature = groupInvitationFactory diff --git a/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationIntegrationTest.java index f4cbd6c7c..64ff67051 100644 --- a/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationIntegrationTest.java @@ -57,7 +57,7 @@ public class GroupInvitationIntegrationTest privateGroup = privateGroupFactory.createPrivateGroup("Testgroup", author0); - long joinTime = clock.currentTimeMillis(); + long joinTime = c0.getClock().currentTimeMillis(); GroupMessage joinMsg0 = groupMessageFactory .createJoinMessage(privateGroup.getId(), joinTime, author0); groupManager0.addPrivateGroup(privateGroup, joinMsg0, true); @@ -88,7 +88,7 @@ public class GroupInvitationIntegrationTest @Test public void testSendInvitation() throws Exception { - long timestamp = clock.currentTimeMillis(); + long timestamp = c0.getClock().currentTimeMillis(); String text = "Hi!"; sendInvitation(timestamp, text); @@ -120,7 +120,7 @@ public class GroupInvitationIntegrationTest @Test public void testInvitationDecline() throws Exception { - long timestamp = clock.currentTimeMillis(); + long timestamp = c0.getClock().currentTimeMillis(); sendInvitation(timestamp, null); sync0To1(1, true); @@ -172,7 +172,7 @@ public class GroupInvitationIntegrationTest setAutoDeleteTimer(c1, contactId0From1, MIN_AUTO_DELETE_TIMER_MS); // Send invitation - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); sync0To1(1, true); // Decline invitation @@ -194,7 +194,7 @@ public class GroupInvitationIntegrationTest @Test public void testInvitationAccept() throws Exception { - long timestamp = clock.currentTimeMillis(); + long timestamp = c0.getClock().currentTimeMillis(); sendInvitation(timestamp, null); // check that invitation message state is correct @@ -257,7 +257,7 @@ public class GroupInvitationIntegrationTest setAutoDeleteTimer(c1, contactId0From1, MIN_AUTO_DELETE_TIMER_MS); // Send invitation - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); sync0To1(1, true); // Accept invitation @@ -281,7 +281,7 @@ public class GroupInvitationIntegrationTest @Test public void testGroupCount() throws Exception { - long timestamp = clock.currentTimeMillis(); + long timestamp = c0.getClock().currentTimeMillis(); sendInvitation(timestamp, null); // 0 has one read outgoing message @@ -313,7 +313,7 @@ public class GroupInvitationIntegrationTest @Test public void testMultipleInvitations() throws Exception { - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); // invitation is not allowed before the first hasn't been answered assertFalse(groupInvitationManager0 @@ -330,7 +330,7 @@ public class GroupInvitationIntegrationTest .isInvitationAllowed(contact1From0, privateGroup.getId())); // send and accept the second invitation - sendInvitation(clock.currentTimeMillis(), "Second Invitation"); + sendInvitation(c0.getClock().currentTimeMillis(), "Second Invitation"); sync0To1(1, true); groupInvitationManager1 .respondToInvitation(contactId0From1, privateGroup, true); @@ -342,7 +342,8 @@ public class GroupInvitationIntegrationTest // don't allow another invitation request try { - sendInvitation(clock.currentTimeMillis(), "Third Invitation"); + sendInvitation(c0.getClock().currentTimeMillis(), + "Third Invitation"); fail(); } catch (ProtocolStateException e) { // expected @@ -351,7 +352,7 @@ public class GroupInvitationIntegrationTest @Test(expected = ProtocolStateException.class) public void testInvitationsWithSameTimestamp() throws Exception { - long timestamp = clock.currentTimeMillis(); + long timestamp = c0.getClock().currentTimeMillis(); sendInvitation(timestamp, null); sync0To1(1, true); @@ -369,7 +370,7 @@ public class GroupInvitationIntegrationTest @Test(expected = ProtocolStateException.class) public void testCreatorLeavesBeforeInvitationAccepted() throws Exception { // Creator invites invitee to join group - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); // Creator's invite message is delivered to invitee sync0To1(1, true); @@ -392,7 +393,7 @@ public class GroupInvitationIntegrationTest @Test public void testCreatorLeavesBeforeInvitationDeclined() throws Exception { // Creator invites invitee to join group - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); // Creator's invite message is delivered to invitee sync0To1(1, true); @@ -419,7 +420,7 @@ public class GroupInvitationIntegrationTest public void testCreatorLeavesConcurrentlyWithInvitationAccepted() throws Exception { // Creator invites invitee to join group - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); // Creator's invite message is delivered to invitee sync0To1(1, true); @@ -450,7 +451,7 @@ public class GroupInvitationIntegrationTest public void testCreatorLeavesConcurrentlyWithInvitationDeclined() throws Exception { // Creator invites invitee to join group - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); // Creator's invite message is delivered to invitee sync0To1(1, true); @@ -477,7 +478,7 @@ public class GroupInvitationIntegrationTest public void testCreatorLeavesConcurrentlyWithMemberLeaving() throws Exception { // Creator invites invitee to join group - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); // Creator's invite message is delivered to invitee sync0To1(1, true); @@ -517,7 +518,7 @@ public class GroupInvitationIntegrationTest public void testDeletingAllMessagesWhenCompletingSession() throws Exception { // send invitation - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); sync0To1(1, true); // messages can not be deleted @@ -572,7 +573,7 @@ public class GroupInvitationIntegrationTest @Test public void testDeletingAllMessagesWhenDeclining() throws Exception { // send invitation - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); sync0To1(1, true); // respond @@ -608,7 +609,7 @@ public class GroupInvitationIntegrationTest assertGroupCount(messageTracker1, g0From1.getId(), 0, 0); // creator can re-invite - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); sync0To1(1, true); // now new messages can not be deleted anymore @@ -639,7 +640,7 @@ public class GroupInvitationIntegrationTest @Test public void testDeletingSomeMessages() throws Exception { // send invitation - sendInvitation(clock.currentTimeMillis(), null); + sendInvitation(c0.getClock().currentTimeMillis(), null); sync0To1(1, true); // deleting the invitation will fail for both diff --git a/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java index f46b494aa..342a08afb 100644 --- a/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java @@ -725,7 +725,7 @@ public class ForumSharingIntegrationTest assertResponseReceived(listener0, contactId1From0, true); // sharer posts into the forum - long time = clock.currentTimeMillis(); + long time = c0.getClock().currentTimeMillis(); String text = getRandomString(42); ForumPost p = forumPostFactory .createPost(forum.getId(), time, null, author0, text); @@ -743,7 +743,7 @@ public class ForumSharingIntegrationTest assertEquals(author0, header.getAuthor()); // now invitee creates a post - time = clock.currentTimeMillis(); + time = c1.getClock().currentTimeMillis(); text = getRandomString(42); p = forumPostFactory .createPost(forum.getId(), time, null, author1, text); @@ -789,7 +789,7 @@ public class ForumSharingIntegrationTest assertResponseReceived(listener0, contactId1From0, true); // now invitee creates a post - time = clock.currentTimeMillis(); + time = c1.getClock().currentTimeMillis(); text = getRandomString(42); p = forumPostFactory .createPost(forum.getId(), time, null, author1, text); @@ -848,7 +848,7 @@ public class ForumSharingIntegrationTest // send an accept message for the same forum Message m = messageEncoder.encodeAcceptMessage( forumSharingManager0.getContactGroup(contact1From0).getId(), - forum.getId(), clock.currentTimeMillis(), invitationId); + forum.getId(), c0.getClock().currentTimeMillis(), invitationId); c0.getClientHelper().addLocalMessage(m, new BdfDictionary(), true); // sync unexpected message and the expected abort message back diff --git a/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java index c2b353811..dfeefae64 100644 --- a/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java @@ -26,7 +26,6 @@ import org.briarproject.bramble.api.sync.MessageFactory; import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.event.MessageStateChangedEvent; import org.briarproject.bramble.api.sync.event.MessagesAckedEvent; -import org.briarproject.bramble.api.system.Clock; import org.briarproject.bramble.test.TestTransportConnectionReader; import org.briarproject.bramble.test.TestTransportConnectionWriter; import org.briarproject.bramble.test.TestUtils; @@ -96,8 +95,6 @@ public abstract class BriarIntegrationTest