From: David ‘Bombe’ Roden Date: Wed, 30 Jul 2014 12:46:30 +0000 (+0200) Subject: Add test for “remove context” job. X-Git-Tag: 0.9-rc1^2~3^2~195 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f9ab0ec7c20e67c89d46f7ab383cd05981d17e64;p=Sone.git Add test for “remove context” job. --- diff --git a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java index 9bd475a..9b49092 100644 --- a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java +++ b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java @@ -511,7 +511,8 @@ public class WebOfTrustUpdater extends AbstractService { * * @author David ‘Bombe’ Roden */ - private class RemoveContextJob extends WebOfTrustContextUpdateJob { + @VisibleForTesting + class RemoveContextJob extends WebOfTrustContextUpdateJob { /** * Creates a new remove-context job. diff --git a/src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java b/src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java index 0589d9d..84dca44 100644 --- a/src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java +++ b/src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java @@ -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)); + } + }