From 16da3f2cab4dfc1d776f9330d034f3ea3a9cfe80 Mon Sep 17 00:00:00 2001 From: Torsten Grote <t@grobox.de> Date: Wed, 3 Aug 2016 18:15:14 -0300 Subject: [PATCH] Fix SharerLeavesBeforeResponse Integration Test Closes #575 --- .../ForumSharingIntegrationTest.java | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/briar-android-tests/src/test/java/org/briarproject/ForumSharingIntegrationTest.java b/briar-android-tests/src/test/java/org/briarproject/ForumSharingIntegrationTest.java index 2221f635b4..bc6b3d06fb 100644 --- a/briar-android-tests/src/test/java/org/briarproject/ForumSharingIntegrationTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/ForumSharingIntegrationTest.java @@ -113,6 +113,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase { private final String SHARER = "Sharer"; private final String INVITEE = "Invitee"; private final String SHARER2 = "Sharer2"; + private boolean respond = true; private static final Logger LOG = Logger.getLogger(ForumSharingIntegrationTest.class.getName()); @@ -408,7 +409,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase { public void testSharerLeavesBeforeResponse() throws Exception { startLifecycles(); try { - // initialize and let invitee accept all requests + // initialize except event listeners defaultInit(true); // send invitation @@ -418,17 +419,43 @@ public class ForumSharingIntegrationTest extends BriarTestCase { // sharer un-subscribes from forum forumManager0.removeForum(forum0); - // from here on expect the response to fail with an AssertionError, - // because there is in fact no invited forum available anymore - thrown.expect(AssertionError.class); + // prevent invitee response before syncing messages + respond = false; // sync first request message and leave message syncToInvitee(); eventWaiter.await(TIMEOUT, 1); assertTrue(listener1.requestReceived); - // invitee has no forums available + // wait also for second message to arrive + msgWaiter.await(TIMEOUT, 1); + + // ensure that invitee has no forum invitations available assertEquals(0, forumSharingManager1.getInvited().size()); + assertEquals(0, forumManager1.getForums().size()); + + // Try again, this time allow the response + addForumForSharer(); + respond = true; + + // send invitation + forumSharingManager0 + .sendInvitation(forum0.getId(), contactId1, null); + + // sharer un-subscribes from forum + forumManager0.removeForum(forum0); + + // sync first request message and leave message + syncToInvitee(); + eventWaiter.await(TIMEOUT, 1); + assertTrue(listener1.requestReceived); + + // wait also for second message to arrive + msgWaiter.await(TIMEOUT, 1); + + // ensure that invitee has no forum invitations available + assertEquals(0, forumSharingManager1.getInvited().size()); + assertEquals(1, forumManager1.getForums().size()); } finally { stopLifecycles(); } @@ -979,9 +1006,12 @@ public class ForumSharingIntegrationTest extends BriarTestCase { try { eventWaiter.assertEquals(1, forumSharingManager1.getInvited().size()); - Contact c = - contactManager1.getContact(event.getContactId()); - forumSharingManager1.respondToInvitation(f, c, accept); + if (respond) { + Contact c = + contactManager1 + .getContact(event.getContactId()); + forumSharingManager1.respondToInvitation(f, c, accept); + } } catch (DbException ex) { eventWaiter.rethrow(ex); } finally { -- GitLab