Skip to content

Commit

Permalink
less mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-pol committed Aug 15, 2024
1 parent f92e66a commit 47f9c4f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/test/java/nl/knaw/dans/dvcli/action/SingleOrTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import nl.knaw.dans.lib.dataverse.DatasetApi;
import nl.knaw.dans.lib.dataverse.DataverseApi;
import nl.knaw.dans.lib.dataverse.DataverseClient;
import nl.knaw.dans.lib.dataverse.DataverseClientConfig;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand All @@ -27,6 +28,8 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.List;

Expand All @@ -50,16 +53,22 @@ public void tearDown() {
}

@Test
public void getCollections_should_return_single_value() throws IOException {
public void getCollections_should_return_single_value() throws Exception {
var alias = "xyz";

var dataverseClient = mock(DataverseClient.class);
var dataverse = mock(DataverseApi.class);
Mockito.when(dataverseClient.dataverse(alias)).thenReturn(dataverse);
var collections = new SingleCollectionOrCollectionsFile(alias, getClient())
.getCollections().toList();

assertThat(collections).hasSize(1);
var kv = collections.get(0);
assertThat(kv.getFirst()).isEqualTo(alias);
assertThat(kv.getSecond()).isInstanceOf(DataverseApi.class);
// TODO a DataverseApi.toString() showing the subPath would be nice
}

var datasets = new SingleCollectionOrCollectionsFile(alias, dataverseClient)
.getCollections();
assertThat(datasets).containsExactly(new Pair<>(alias, dataverse));
private static DataverseClient getClient() throws URISyntaxException {
var baseUrl = new URI("http://does.not.exist.dans.knaw.nl");
return new DataverseClient(new DataverseClientConfig(baseUrl, "apiTokenValue"));
}

@Test
Expand Down

0 comments on commit 47f9c4f

Please sign in to comment.