11package com .teamscale .jacoco .agent .testimpact ;
22
3- import static org .mockito .ArgumentMatchers .any ;
4- import static org .mockito .ArgumentMatchers .anyBoolean ;
5- import static org .mockito .ArgumentMatchers .eq ;
6- import static org .mockito .ArgumentMatchers .matches ;
7- import static org .mockito .Mockito .mock ;
8- import static org .mockito .Mockito .verify ;
9- import static org .mockito .Mockito .when ;
10-
11- import java .io .File ;
12- import java .io .IOException ;
13- import java .util .Collections ;
14- import java .util .List ;
15-
16- import org .junit .jupiter .api .Test ;
17- import org .junit .jupiter .api .extension .ExtendWith ;
18- import org .junit .jupiter .api .io .TempDir ;
19- import org .mockito .Mock ;
20- import org .mockito .junit .jupiter .MockitoExtension ;
21-
223import com .teamscale .client .ClusteredTestDetails ;
234import com .teamscale .client .CommitDescriptor ;
245import com .teamscale .client .EReportFormat ;
3415import com .teamscale .report .testwise .model .TestwiseCoverage ;
3516import com .teamscale .report .testwise .model .builder .FileCoverageBuilder ;
3617import com .teamscale .report .testwise .model .builder .TestCoverageBuilder ;
37-
3818import okhttp3 .HttpUrl ;
19+ import org .junit .jupiter .api .Test ;
20+ import org .junit .jupiter .api .extension .ExtendWith ;
21+ import org .junit .jupiter .api .io .TempDir ;
22+ import org .junit .jupiter .params .ParameterizedTest ;
23+ import org .junit .jupiter .params .provider .ValueSource ;
24+ import org .mockito .Mock ;
25+ import org .mockito .junit .jupiter .MockitoExtension ;
3926import retrofit2 .Response ;
4027
28+ import java .io .File ;
29+ import java .io .IOException ;
30+ import java .util .Collections ;
31+ import java .util .List ;
32+
33+ import static org .mockito .ArgumentMatchers .any ;
34+ import static org .mockito .ArgumentMatchers .anyBoolean ;
35+ import static org .mockito .ArgumentMatchers .eq ;
36+ import static org .mockito .ArgumentMatchers .matches ;
37+ import static org .mockito .Mockito .mock ;
38+ import static org .mockito .Mockito .verify ;
39+ import static org .mockito .Mockito .when ;
40+
4141@ ExtendWith (MockitoExtension .class )
4242public class CoverageToTeamscaleStrategyTest {
4343
@@ -55,7 +55,7 @@ public class CoverageToTeamscaleStrategyTest {
5555
5656 @ Test
5757 public void shouldRecordCoverageForTestsEvenIfNotProvidedAsAvailableTest () throws Exception {
58- AgentOptions options = mockOptions ();
58+ AgentOptions options = mockOptions (false );
5959 CoverageToTeamscaleStrategy strategy = new CoverageToTeamscaleStrategy (controller , options , reportGenerator );
6060
6161 TestwiseCoverage testwiseCoverage = getDummyTestwiseCoverage ("mytest" );
@@ -71,18 +71,20 @@ public void shouldRecordCoverageForTestsEvenIfNotProvidedAsAvailableTest() throw
7171 any (), any (), any (), any (), any ());
7272 }
7373
74- @ Test
75- public void testValidCallSequence () throws Exception {
74+ @ ParameterizedTest
75+ @ ValueSource (booleans = {true , false })
76+ public void testValidCallSequence (boolean useRevision ) throws Exception {
7677 List <PrioritizableTestCluster > clusters = Collections
7778 .singletonList (new PrioritizableTestCluster ("cluster" ,
7879 Collections .singletonList (new PrioritizableTest ("mytest" ))));
79- when (client .getImpactedTests (any (), any (), any (), any (), any (), any (), any (), anyBoolean (), anyBoolean (), anyBoolean ())).thenReturn (
80+ when (client .getImpactedTests (any (), any (), any (), any (), any (), any (), any (), anyBoolean (), anyBoolean (),
81+ anyBoolean ())).thenReturn (
8082 Response .success (clusters ));
8183
8284 TestwiseCoverage testwiseCoverage = getDummyTestwiseCoverage ("mytest" );
8385 when (reportGenerator .convert (any (File .class ))).thenReturn (testwiseCoverage );
8486
85- AgentOptions options = mockOptions ();
87+ AgentOptions options = mockOptions (useRevision );
8688 JacocoRuntimeController controller = mock (JacocoRuntimeController .class );
8789 CoverageToTeamscaleStrategy strategy = new CoverageToTeamscaleStrategy (controller , options , reportGenerator );
8890
@@ -111,13 +113,17 @@ protected static TestwiseCoverage getDummyTestwiseCoverage(String test) {
111113 return testwiseCoverage ;
112114 }
113115
114- private AgentOptions mockOptions () throws IOException {
116+ private AgentOptions mockOptions (boolean useRevision ) throws IOException {
115117 AgentOptions options = mock (AgentOptions .class );
116118 when (options .createTeamscaleClient (true )).thenReturn (client );
117119 when (options .createNewFileInOutputDirectory (any (), any ())).thenReturn (new File (tempDir , "test" ));
118120
119121 TeamscaleServer server = new TeamscaleServer ();
120- server .commit = new CommitDescriptor ("branch" , "12345" );
122+ if (useRevision ) {
123+ server .revision = "rev1" ;
124+ } else {
125+ server .commit = new CommitDescriptor ("branch" , "12345" );
126+ }
121127 server .url = HttpUrl .get ("http://doesnt-exist.io" );
122128 server .userName = "build" ;
123129 server .userAccessToken = "token" ;
0 commit comments