Skip to content

Commit 25c80d8

Browse files
TheRealHauiTheRealHaui
andauthored
Add new Unit Tests (#11470)
Co-authored-by: TheRealHaui <[email protected]>
1 parent 8f63dcc commit 25c80d8

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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;
20+
21+
import org.apache.maven.artifact.Artifact;
22+
import org.eclipse.aether.graph.Dependency;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertNull;
26+
27+
class RepositoryUtilsTest {
28+
29+
@Test
30+
void testToArtifactMethodsReturnNullWhenInputParameterIsNull() {
31+
assertNull(RepositoryUtils.toArtifact((Dependency) null));
32+
assertNull(RepositoryUtils.toArtifact((Artifact) null));
33+
assertNull(RepositoryUtils.toArtifact((org.apache.maven.artifact.Artifact) null));
34+
}
35+
}

impl/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.nio.file.Path;
2324
import java.util.List;
2425
import java.util.Map;
2526

27+
import org.apache.maven.api.Language;
28+
import org.apache.maven.api.ProjectScope;
29+
import org.apache.maven.impl.DefaultSourceRoot;
2630
import org.apache.maven.model.DependencyManagement;
2731
import org.apache.maven.model.Model;
2832
import org.apache.maven.model.Parent;
@@ -212,6 +216,36 @@ void testAddDotFile() {
212216
assertEquals(1, project.getCompileSourceRoots().size());
213217
}
214218

219+
@Test
220+
void testRemoveSourceRoot() {
221+
MavenProject project = new MavenProject();
222+
223+
File basedir = new File(System.getProperty("java.io.tmpdir"));
224+
project.setFile(new File(basedir, "file"));
225+
226+
assertEquals(0, project.getSourceRoots().size());
227+
228+
project.addSourceRoot(new DefaultSourceRoot(
229+
ProjectScope.MAIN, Language.JAVA_FAMILY, Path.of(basedir.getAbsolutePath(), "src/main/java")));
230+
231+
assertEquals(1, project.getSourceRoots().size());
232+
233+
// Try to remove a different directory
234+
project.removeSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, "src/test/java");
235+
236+
assertEquals(1, project.getSourceRoots().size());
237+
238+
// Try to remove a different scope
239+
project.removeSourceRoot(ProjectScope.TEST, Language.JAVA_FAMILY, "src/main/java");
240+
241+
assertEquals(1, project.getSourceRoots().size());
242+
243+
// Remove previously added root
244+
project.removeSourceRoot(ProjectScope.MAIN, Language.JAVA_FAMILY, "src/main/java");
245+
246+
assertEquals(0, project.getSourceRoots().size());
247+
}
248+
215249
private void assertNoNulls(List<String> elements) {
216250
assertFalse(elements.contains(null), "Expected " + elements + " to not contain " + null);
217251
}

0 commit comments

Comments
 (0)