X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FWebOfTrustUpdaterTest.java;h=0c923fc416a13049d57b949300dd124ebebada4c;hb=ed0b70c34c926fbb44ec61c8be9b9b9af26b1770;hp=aa810ee381c470e2b250c872cfa128f20ee1205b;hpb=56f597f201108f12f11c55cd3d201a1ffa76799e;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java b/src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java
index aa810ee..0c923fc 100644
--- a/src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java
+++ b/src/test/java/net/pterodactylus/sone/core/WebOfTrustUpdaterTest.java
@@ -6,13 +6,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doAnswer;
-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 static org.mockito.Mockito.when;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
import java.util.concurrent.CountDownLatch;
@@ -35,8 +30,6 @@ import org.mockito.stubbing.Answer;
/**
* Unit test for {@link WebOfTrustUpdaterImpl} and its subclasses.
- *
- * @author David âBombeâ Roden
*/
public class WebOfTrustUpdaterTest {
@@ -425,28 +418,24 @@ public class WebOfTrustUpdaterTest {
@Test
public void setTrustRequestsAreCoalesced() throws InterruptedException, PluginException {
- final CountDownLatch trustSetTrigger = new CountDownLatch(1);
- doAnswer(new Answer() {
- @Override
- public Void answer(InvocationOnMock invocation) throws Throwable {
- trustSetTrigger.countDown();
- return null;
- }
+ final CountDownLatch firstTrigger = new CountDownLatch(1);
+ doAnswer((Answer) invocation -> {
+ firstTrigger.countDown();
+ return null;
}).when(trustee).setTrust(eq(ownIdentity), eq(new Trust(SCORE, null, 0)));
- for (int i = 1; i <= 2; i++) {
- /* this is so fucking volatile. */
- if (i > 1) {
- sleep(200);
- }
- new Thread(new Runnable() {
- public void run() {
- webOfTrustUpdater.setTrust(ownIdentity, trustee, SCORE, TRUST_COMMENT);
- }
- }).start();
- }
+ Identity secondTrustee = when(mock(Identity.class).getId()).thenReturn("trustee-id2").getMock();
+ final CountDownLatch secondTrigger = new CountDownLatch(1);
+ doAnswer((Answer) invocation -> {
+ secondTrigger.countDown();
+ return null;
+ }).when(secondTrustee).setTrust(eq(ownIdentity), eq(new Trust(SCORE, null, 0)));
+ webOfTrustUpdater.setTrust(ownIdentity, trustee, SCORE, TRUST_COMMENT);
+ webOfTrustUpdater.setTrust(ownIdentity, secondTrustee, SCORE, TRUST_COMMENT);
+ webOfTrustUpdater.setTrust(ownIdentity, trustee, SCORE, TRUST_COMMENT);
webOfTrustUpdater.start();
- assertThat(trustSetTrigger.await(1, SECONDS), is(true));
- verify(trustee).setTrust(eq(ownIdentity), eq(new Trust(SCORE, null, 0)));
+ assertThat(firstTrigger.await(1, SECONDS), is(true));
+ assertThat(secondTrigger.await(1, SECONDS), is(true));
+ verify(trustee, times(1)).setTrust(eq(ownIdentity), eq(new Trust(SCORE, null, 0)));
verify(webOfTrustConnector).setTrust(eq(ownIdentity), eq(trustee), eq(SCORE), eq(TRUST_COMMENT));
}