1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.tools.plugin.util;
20
21 import java.util.Collections;
22
23 import org.apache.maven.plugin.descriptor.PluginDescriptor;
24 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
25 import org.junit.jupiter.api.Test;
26
27 import static org.junit.jupiter.api.Assertions.assertEquals;
28 import static org.junit.jupiter.api.Assertions.assertFalse;
29 import static org.junit.jupiter.api.Assertions.assertTrue;
30
31
32
33
34 class PluginUtilsTest {
35 @Test
36 void testShouldTrimArtifactIdToFindPluginId() {
37 assertEquals("artifactId", PluginDescriptor.getGoalPrefixFromArtifactId("maven-artifactId-plugin"));
38 assertEquals("artifactId", PluginDescriptor.getGoalPrefixFromArtifactId("maven-plugin-artifactId"));
39 assertEquals("artifactId", PluginDescriptor.getGoalPrefixFromArtifactId("artifactId-maven-plugin"));
40 assertEquals("artifactId", PluginDescriptor.getGoalPrefixFromArtifactId("artifactId"));
41 assertEquals("artifactId", PluginDescriptor.getGoalPrefixFromArtifactId("artifactId-plugin"));
42 assertEquals("plugin", PluginDescriptor.getGoalPrefixFromArtifactId("maven-plugin-plugin"));
43 }
44
45 @Test
46 void testShouldFindTwoScriptsWhenNoExcludesAreGiven() {
47 String testScript = "test.txt";
48
49 String basedir = TestUtils.dirname(testScript);
50
51 String includes = "**/*.txt";
52
53 String[] files = PluginUtils.findSources(basedir, includes);
54 assertEquals(2, files.length);
55 }
56
57 @Test
58 void testShouldFindOneScriptsWhenAnExcludeIsGiven() {
59 String testScript = "test.txt";
60
61 String basedir = TestUtils.dirname(testScript);
62
63 String includes = "**/*.txt";
64 String excludes = "**/*Excludes.txt";
65
66 String[] files = PluginUtils.findSources(basedir, includes, excludes);
67 assertEquals(1, files.length);
68 }
69
70 @Test
71 void testIsMavenReport() throws Exception {
72 try {
73 PluginUtils.isMavenReport(null, null);
74 } catch (IllegalArgumentException e) {
75 assertTrue(true);
76 }
77
78 String impl = "org.apache.maven.tools.plugin.util.stubs.MavenReportStub";
79
80 MavenProjectStub stub = new MavenProjectStub();
81 stub.setCompileSourceRoots(Collections.singletonList(System.getProperty("basedir") + "/target/classes"));
82
83 assertTrue(PluginUtils.isMavenReport(impl, stub));
84
85 impl = "org.apache.maven.tools.plugin.util.stubs.MojoStub";
86 assertFalse(PluginUtils.isMavenReport(impl, stub));
87 }
88 }