Skip to content

Commit 510e3f4

Browse files
kinowmr-c
authored andcommitted
Fix unit tests
1 parent 2663eac commit 510e3f4

11 files changed

+125
-135
lines changed

src/test/java/org/commonwl/view/CwlViewerApplicationTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222
import org.junit.jupiter.api.Test;
2323
import org.junit.jupiter.api.extension.ExtendWith;
2424
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.context.ApplicationContext;
2526
import org.springframework.test.context.junit.jupiter.SpringExtension;
2627

28+
import static org.assertj.core.api.Assertions.assertThat;
29+
2730
@ExtendWith(SpringExtension.class)
28-
@SpringBootTest
31+
@SpringBootTest(classes={WebConfig.class})
2932
public class CwlViewerApplicationTests {
3033

3134
@Test
32-
public void contextLoads() {
35+
public void contextLoads(ApplicationContext context) {
36+
assertThat(context).isNotNull();
3337
}
3438

3539
}

src/test/java/org/commonwl/view/cwl/CWLServiceTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@
3535
import org.junit.jupiter.api.Assertions;
3636
import org.junit.jupiter.api.BeforeEach;
3737
import org.junit.jupiter.api.Test;
38-
import org.junit.jupiter.api.extension.ExtendWith;
3938
import org.mockito.Mockito;
4039
import org.mockito.invocation.InvocationOnMock;
4140
import org.mockito.stubbing.Answer;
42-
import org.springframework.boot.test.context.SpringBootTest;
43-
import org.springframework.test.context.junit.jupiter.SpringExtension;
4441

4542
import java.io.ByteArrayInputStream;
4643
import java.io.File;
@@ -54,12 +51,9 @@
5451
import static org.junit.jupiter.api.Assertions.assertNotNull;
5552
import static org.junit.jupiter.api.Assertions.assertNull;
5653
import static org.junit.jupiter.api.Assertions.assertTrue;
57-
import static org.mockito.Matchers.anyObject;
58-
import static org.mockito.Matchers.anyString;
54+
import static org.mockito.ArgumentMatchers.any;
5955
import static org.mockito.Mockito.when;
6056

61-
@ExtendWith(SpringExtension.class)
62-
@SpringBootTest
6357
public class CWLServiceTest {
6458

6559
/**
@@ -87,8 +81,8 @@ public ResultSet answer(InvocationOnMock invocation) throws Throwable {
8781
};
8882

8983
this.rdfService = Mockito.spy(new RDFService("http://localhost:3030/cwlviewer/"));
90-
Mockito.doAnswer(queryRdf).when(rdfService).runQuery(anyObject());
91-
Mockito.doReturn(true).when(rdfService).graphExists(anyString());
84+
Mockito.doAnswer(queryRdf).when(rdfService).runQuery(any());
85+
Mockito.doReturn(true).when(rdfService).graphExists(any(String.class));
9286
}
9387

9488
@Test
@@ -149,7 +143,7 @@ public void parseWorkflowWithCwltool() throws Exception {
149143
// Mock CWLTool
150144
CWLTool mockCwlTool = Mockito.mock(CWLTool.class);
151145
File packedWorkflowRdf = new File("src/test/resources/cwl/make_to_cwl/dna.ttl");
152-
when(mockCwlTool.getRDF(anyString()))
146+
when(mockCwlTool.getRDF(any(String.class)))
153147
.thenReturn(readFileToString(packedWorkflowRdf));
154148

155149
// CWLService to test

src/test/java/org/commonwl/view/cwl/RDFServiceTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
package org.commonwl.view.cwl;
2121

22+
import org.commonwl.view.CwlViewerApplication;
23+
import org.commonwl.view.MongoConfig;
24+
import org.commonwl.view.WebConfig;
2225
import org.junit.jupiter.api.Test;
2326
import org.junit.jupiter.api.extension.ExtendWith;
2427
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,7 +31,7 @@
2831
import static org.junit.jupiter.api.Assertions.assertEquals;
2932

3033
@ExtendWith(SpringExtension.class)
31-
@SpringBootTest
34+
@SpringBootTest(classes=RDFService.class)
3235
public class RDFServiceTest {
3336

3437
/**

src/test/java/org/commonwl/view/git/GitServiceTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.IOException;
2424

2525
import org.eclipse.jgit.api.CheckoutCommand;
26+
import org.eclipse.jgit.api.CloneCommand;
2627
import org.eclipse.jgit.api.Git;
2728
import org.eclipse.jgit.api.errors.GitAPIException;
2829
import org.eclipse.jgit.api.errors.RefNotFoundException;
@@ -62,6 +63,7 @@ public void setup() throws GitAPIException {
6263
when(this.mockGit.checkout()).thenReturn(this.mockCheckoutCommand);
6364
when(this.mockBranchNotFoundCommand.call()).thenThrow(branchNotFoundException);
6465
when(this.mockTagNotFoundCommand.call()).thenThrow(tagNotFoundException);
66+
doReturn(this.mockGit).when(this.spyGitService).cloneRepo(Mockito.any(), Mockito.any());
6567
}
6668

6769
@Test

src/test/java/org/commonwl/view/researchobject/ROBundleFactoryTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.commonwl.view.researchobject;
2121

22+
import org.apache.taverna.robundle.Bundle;
2223
import org.commonwl.view.git.GitDetails;
2324
import org.commonwl.view.workflow.Workflow;
2425
import org.commonwl.view.workflow.WorkflowRepository;
@@ -29,7 +30,7 @@
2930
import java.util.HashMap;
3031

3132
import static org.junit.jupiter.api.Assertions.assertEquals;
32-
import static org.mockito.Matchers.anyObject;
33+
import static org.mockito.ArgumentMatchers.any;
3334
import static org.mockito.Mockito.when;
3435

3536
/**
@@ -49,12 +50,12 @@ public void bundleForValidWorkflow() throws Exception {
4950

5051
// Mocked path to a RO bundle
5152
ROBundleService mockROBundleService = Mockito.mock(ROBundleService.class);
52-
when(mockROBundleService.saveToFile(anyObject()))
53+
when(mockROBundleService.saveToFile(any()))
5354
.thenReturn(Paths.get("test/path/to/check/for.zip"));
5455

5556
// Test method retries multiple times to get workflow model before success
5657
WorkflowRepository mockRepository = Mockito.mock(WorkflowRepository.class);
57-
when(mockRepository.findByRetrievedFrom(anyObject()))
58+
when(mockRepository.findByRetrievedFrom(any(GitDetails.class)))
5859
.thenReturn(null)
5960
.thenReturn(null)
6061
.thenReturn(validWorkflow);

src/test/java/org/commonwl/view/researchobject/ROBundleServiceTest.java

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@
1919

2020
package org.commonwl.view.researchobject;
2121

22-
import static org.junit.jupiter.api.Assertions.assertEquals;
23-
import static org.junit.jupiter.api.Assertions.assertNotNull;
24-
import static org.junit.jupiter.api.Assertions.assertNull;
25-
import static org.junit.jupiter.api.Assertions.assertTrue;
26-
import static org.mockito.Matchers.any;
27-
import static org.mockito.Matchers.anyBoolean;
28-
import static org.mockito.Matchers.anyObject;
29-
import static org.mockito.Matchers.anyString;
30-
import static org.mockito.Mockito.when;
31-
32-
import java.io.File;
33-
import java.net.URI;
34-
import java.nio.file.Path;
35-
import java.nio.file.Paths;
36-
import java.util.HashSet;
37-
import java.util.List;
38-
import java.util.Set;
39-
4022
import org.apache.jena.query.ResultSet;
4123
import org.apache.taverna.robundle.Bundle;
4224
import org.apache.taverna.robundle.Bundles;
@@ -59,6 +41,21 @@
5941
import org.mockito.invocation.InvocationOnMock;
6042
import org.mockito.stubbing.Answer;
6143

44+
import java.io.File;
45+
import java.net.URI;
46+
import java.nio.file.Path;
47+
import java.nio.file.Paths;
48+
import java.util.HashSet;
49+
import java.util.List;
50+
import java.util.Set;
51+
52+
import static org.junit.jupiter.api.Assertions.assertEquals;
53+
import static org.junit.jupiter.api.Assertions.assertNotNull;
54+
import static org.junit.jupiter.api.Assertions.assertNull;
55+
import static org.junit.jupiter.api.Assertions.assertTrue;
56+
import static org.mockito.ArgumentMatchers.any;
57+
import static org.mockito.Mockito.when;
58+
6259
public class ROBundleServiceTest {
6360

6461
private static ROBundleService roBundleService;
@@ -75,36 +72,36 @@ public void setUp() throws Exception {
7572

7673
// Get mock Git service
7774
GitService mockGitService = Mockito.mock(GitService.class);
78-
when(mockGitService.getRepository(anyObject(), anyBoolean())).thenReturn(gitRepo);
75+
when(mockGitService.getRepository(any(GitDetails.class), any(Boolean.class))).thenReturn(gitRepo);
7976

8077
Set<HashableAgent> authors = new HashSet<>();
8178
authors.add(new HashableAgent("Mark Robinson", null, new URI("mailto:[email protected]")));
82-
when(mockGitService.getAuthors(anyObject(), anyObject()))
79+
when(mockGitService.getAuthors(any(Git.class), any(String.class)))
8380
.thenReturn(authors);
8481

8582
// Mock Graphviz service
8683
GraphVizService mockGraphvizService = Mockito.mock(GraphVizService.class);
87-
when(mockGraphvizService.getGraphPath(anyString(), anyString(), anyString()))
84+
when(mockGraphvizService.getGraphPath(any(String.class), any(String.class), any(String.class)))
8885
.thenReturn(Paths.get("src/test/resources/graphviz/testVis.png"))
8986
.thenReturn(Paths.get("src/test/resources/graphviz/testVis.svg"));
90-
when(mockGraphvizService.getGraphStream(anyString(), anyString()))
87+
when(mockGraphvizService.getGraphStream(any(), any(String.class)))
9188
.thenReturn(getClass().getResourceAsStream("/graphviz/testVis.png"))
9289
.thenReturn(getClass().getResourceAsStream("/graphviz/testVis.svg"));
9390

9491

9592
// Mock CWLTool
9693
CWLTool mockCwlTool = Mockito.mock(CWLTool.class);
97-
when(mockCwlTool.getPackedVersion(anyString()))
94+
when(mockCwlTool.getPackedVersion(any(String.class)))
9895
.thenReturn("cwlVersion: v1.0");
9996

10097
// Mock RDF Service
10198
ResultSet emptyResult = Mockito.mock(ResultSet.class);
10299
when(emptyResult.hasNext()).thenReturn(false);
103100
RDFService mockRdfService = Mockito.mock(RDFService.class);
104-
when(mockRdfService.getAuthors(anyString(), anyString())).thenReturn(emptyResult);
105-
when(mockRdfService.graphExists(anyString()))
101+
when(mockRdfService.getAuthors(any(String.class), any(String.class))).thenReturn(emptyResult);
102+
when(mockRdfService.graphExists(any(String.class)))
106103
.thenReturn(true);
107-
when(mockRdfService.getModel(anyObject(), anyObject()))
104+
when(mockRdfService.getModel(any(String.class), any(String.class)))
108105
.thenReturn("@prefix cwl: <https://w3id.org/cwl/cwl#> .".getBytes());
109106

110107
// Create new RO bundle

src/test/java/org/commonwl/view/workflow/QueuedWorkflowRepositoryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package org.commonwl.view.workflow;
22

3+
import org.commonwl.view.MongoConfig;
34
import org.commonwl.view.git.GitDetails;
45
import org.junit.jupiter.api.Test;
5-
import org.junit.jupiter.api.extension.ExtendWith;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
8-
import org.springframework.test.context.junit.jupiter.SpringExtension;
8+
import org.springframework.test.context.ContextConfiguration;
99

1010
import static org.junit.jupiter.api.Assertions.assertNotNull;
1111
import static org.junit.jupiter.api.Assertions.assertNull;
1212

1313
@DataMongoTest
14-
@ExtendWith(SpringExtension.class)
14+
@ContextConfiguration(classes={MongoConfig.class})
1515
public class QueuedWorkflowRepositoryTest {
1616

1717
@Autowired

0 commit comments

Comments
 (0)