Skip to content

Commit 278b549

Browse files
Add UT for cache in FilteredProjectDependencyGraphTest (#2394)
1 parent f7b1a2e commit 278b549

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.graph;
20+
21+
import java.util.List;
22+
23+
import org.apache.maven.execution.ProjectDependencyGraph;
24+
import org.apache.maven.project.MavenProject;
25+
import org.junit.jupiter.api.extension.ExtendWith;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.ValueSource;
28+
import org.mockito.Mock;
29+
import org.mockito.junit.jupiter.MockitoExtension;
30+
31+
import static org.mockito.Mockito.verify;
32+
import static org.mockito.Mockito.when;
33+
34+
@ExtendWith(MockitoExtension.class)
35+
class FilteredProjectDependencyGraphTest {
36+
37+
@Mock
38+
private ProjectDependencyGraph projectDependencyGraph;
39+
40+
private final MavenProject aProject = createProject("A");
41+
42+
private final MavenProject bProject = createProject("B");
43+
44+
private final MavenProject cProject = createProject("C");
45+
46+
@ParameterizedTest
47+
@ValueSource(booleans = {true, false})
48+
void downstreamProjectsShouldBeCached(boolean transitive) {
49+
FilteredProjectDependencyGraph graph =
50+
new FilteredProjectDependencyGraph(projectDependencyGraph, List.of(aProject));
51+
52+
when(projectDependencyGraph.getDownstreamProjects(bProject, transitive)).thenReturn(List.of(cProject));
53+
54+
graph.getDownstreamProjects(bProject, transitive);
55+
graph.getDownstreamProjects(bProject, transitive);
56+
57+
verify(projectDependencyGraph).getDownstreamProjects(bProject, transitive);
58+
}
59+
60+
@ParameterizedTest
61+
@ValueSource(booleans = {true, false})
62+
void upstreamProjectsShouldBeCached(boolean transitive) {
63+
FilteredProjectDependencyGraph graph =
64+
new FilteredProjectDependencyGraph(projectDependencyGraph, List.of(aProject));
65+
66+
when(projectDependencyGraph.getUpstreamProjects(bProject, transitive)).thenReturn(List.of(cProject));
67+
68+
graph.getUpstreamProjects(bProject, transitive);
69+
graph.getUpstreamProjects(bProject, transitive);
70+
71+
verify(projectDependencyGraph).getUpstreamProjects(bProject, transitive);
72+
}
73+
74+
private static MavenProject createProject(String id) {
75+
MavenProject result = new MavenProject();
76+
result.setGroupId("org.apache");
77+
result.setArtifactId(id);
78+
result.setVersion("1.2");
79+
return result;
80+
}
81+
}

0 commit comments

Comments
 (0)