import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.service.AbstractService;
+import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
/**
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
- private class AddContextJob extends WebOfTrustContextUpdateJob {
+ @VisibleForTesting
+ class AddContextJob extends WebOfTrustContextUpdateJob {
/**
* Creates a new add-context job.
--- /dev/null
+package net.pterodactylus.sone.core;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import net.pterodactylus.sone.core.WebOfTrustUpdater.AddContextJob;
+import net.pterodactylus.sone.freenet.plugin.PluginException;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
+import net.pterodactylus.sone.freenet.wot.WebOfTrustConnector;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link WebOfTrustUpdater} and its subclasses.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class WebOfTrustUpdaterTest {
+
+ private static final String CONTEXT = "test-context";
+ private final WebOfTrustConnector webOfTrustConnector = mock(WebOfTrustConnector.class);
+ private final WebOfTrustUpdater webOfTrustUpdater = new WebOfTrustUpdater(webOfTrustConnector);
+ private final OwnIdentity ownIdentity = mock(OwnIdentity.class);
+ private final AddContextJob addContextJob = webOfTrustUpdater.new AddContextJob(ownIdentity, CONTEXT);
+
+ @Test
+ public void addContextJobAddsTheContext() throws PluginException {
+ addContextJob.run();
+ verify(webOfTrustConnector).addContext(eq(ownIdentity), eq(CONTEXT));
+ verify(ownIdentity).addContext(eq(CONTEXT));
+ assertThat(addContextJob.waitForCompletion(), is(true));
+ }
+
+ @Test
+ public void exceptionWhileAddingAContextIsExposed() throws PluginException {
+ doThrow(PluginException.class).when(webOfTrustConnector).addContext(eq(ownIdentity), eq(CONTEXT));
+ addContextJob.run();
+ verify(webOfTrustConnector).addContext(eq(ownIdentity), eq(CONTEXT));
+ verify(ownIdentity, never()).addContext(eq(CONTEXT));
+ assertThat(addContextJob.waitForCompletion(), is(false));
+ }
+
+}