Fixed breaking test
@@ -2,12 +2,16 @@ package com.quorum.tessera.api;
import com.quorum.tessera.config.Peer;
import com.quorum.tessera.core.config.ConfigService;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import javax.ws.rs.core.Response;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import static org.mockito.ArgumentMatchers.anyString;
+import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -32,13 +36,22 @@ public class ConfigResourceTest {
@Test
public void addPeerIsSucessful() {
+
+ List<Peer> peers = new ArrayList<>();
+ Mockito.doAnswer((inv) -> {
+ peers.add(new Peer(inv.getArgument(0)));
+ return null;
+ }).when(configService).addPeer(anyString());
+ when(configService.getPeers()).thenReturn(peers);
+
Peer peer = new Peer("junit");
Response response = configResource.addPeer(peer);
assertThat(response.getStatus()).isEqualTo(201);
- assertThat(response.getLocation().toString()).isEqualTo("/peers/junit");
-
+ assertThat(response.getLocation().toString()).isEqualTo("config/peers/0");
+ assertThat(peers).containsExactly(peer);
verify(configService).addPeer(peer.getUrl());
+ verify(configService).getPeers();
}
@Test
