From f9ab0ec7c20e67c89d46f7ab383cd05981d17e64 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 30 Jul 2014 14:46:30 +0200 Subject: [PATCH] =?utf8?q?Add=20test=20for=20=E2=80=9Cremove=20context?= =?utf8?q?=E2=80=9D=20job.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/sone/core/WebOfTrustUpdater.java | 3 ++- .../sone/core/WebOfTrustUpdaterTest.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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)); + } + } -- 2.7.4