Add test for “remove context” job.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Jul 2014 12:46:30 +0000 (14:46 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Jul 2014 12:46:30 +0000 (14:46 +0200)
src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java
src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java

index 9bd475a..9b49092 100644 (file)
@@ -511,7 +511,8 @@ public class WebOfTrustUpdater extends AbstractService {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       private class RemoveContextJob extends WebOfTrustContextUpdateJob {
+       @VisibleForTesting
+       class RemoveContextJob extends WebOfTrustContextUpdateJob {
 
                /**
                 * Creates a new remove-context job.
index 0589d9d..84dca44 100644 (file)
@@ -9,6 +9,7 @@ import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 
 import net.pterodactylus.sone.core.WebOfTrustUpdater.AddContextJob;
+import net.pterodactylus.sone.core.WebOfTrustUpdater.RemoveContextJob;
 import net.pterodactylus.sone.freenet.plugin.PluginException;
 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
 import net.pterodactylus.sone.freenet.wot.WebOfTrustConnector;
@@ -27,6 +28,7 @@ public class WebOfTrustUpdaterTest {
        private final WebOfTrustUpdater webOfTrustUpdater = new WebOfTrustUpdater(webOfTrustConnector);
        private final OwnIdentity ownIdentity = mock(OwnIdentity.class);
        private final AddContextJob addContextJob = webOfTrustUpdater.new AddContextJob(ownIdentity, CONTEXT);
+       private final RemoveContextJob removeContextJob = webOfTrustUpdater.new RemoveContextJob(ownIdentity, CONTEXT);
 
        @Test
        public void addContextJobAddsTheContext() throws PluginException {
@@ -45,4 +47,21 @@ public class WebOfTrustUpdaterTest {
                assertThat(addContextJob.waitForCompletion(), is(false));
        }
 
+       @Test
+       public void removeContextJobRemovesTheContext() throws PluginException {
+               removeContextJob.run();
+               verify(webOfTrustConnector).removeContext(eq(ownIdentity), eq(CONTEXT));
+               verify(ownIdentity).removeContext(eq(CONTEXT));
+               assertThat(removeContextJob.waitForCompletion(), is(true));
+       }
+
+       @Test
+       public void exceptionWhileRemovingAContextIsExposed() throws PluginException {
+               doThrow(PluginException.class).when(webOfTrustConnector).removeContext(eq(ownIdentity), eq(CONTEXT));
+               removeContextJob.run();
+               verify(webOfTrustConnector).removeContext(eq(ownIdentity), eq(CONTEXT));
+               verify(ownIdentity, never()).removeContext(eq(CONTEXT));
+               assertThat(removeContextJob.waitForCompletion(), is(false));
+       }
+
 }