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;
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 {
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));
+ }
+
}