File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\maven-plugin\src\test\java\hudson\maven\ExecutedMojoTest.java.html

1 package hudson.maven;
2
3 import java.io.IOException;
4 import java.util.logging.Level;
5 import java.util.logging.Logger;
6
7 import org.apache.maven.plugin.MojoExecution;
8 import org.apache.maven.plugin.descriptor.MojoDescriptor;
9 import org.apache.maven.plugin.descriptor.PluginDescriptor;
10 import org.codehaus.plexus.classworlds.realm.ClassRealm;
11 import org.junit.After;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.jvnet.hudson.test.Bug;
16
17 /**
18 * Unit test for {@link ExecutedMojo}.
19 *
20 * @author kutzi
21 */
22 public class ExecutedMojoTest {
23
24 private MojoDescriptor mojoDescriptor;
25 private Level oldLevel;
26
27 @Before
28 public void before() {
29 PluginDescriptor pluginDescriptor = new PluginDescriptor();
30 pluginDescriptor.setGroupId("com.test");
31 pluginDescriptor.setArtifactId("testPlugin");
32 pluginDescriptor.setVersion("1.0");
33
34 ClassRealm classRealm = new ClassRealm(null, "test", getClass().getClassLoader());
35 pluginDescriptor.setClassRealm(classRealm);
36
37 MojoDescriptor descriptor = new MojoDescriptor();
38 descriptor.setPluginDescriptor(pluginDescriptor);
39 this.mojoDescriptor = descriptor;
40
41 // suppress the WARNING logs we expect
42 this.oldLevel = Logger.getLogger(ExecutedMojo.class.getName()).getLevel();
43 Logger.getLogger(ExecutedMojo.class.getName()).setLevel(Level.SEVERE);
44 }
45
46 @After
47 public void after() {
48 Logger.getLogger(ExecutedMojo.class.getName()).setLevel(oldLevel);
49 }
50
51 @Test
52 public void testMojoFromJarFile() throws IOException, InterruptedException {
53 // Faking JUnit's Assert to be the plugin class
54 this.mojoDescriptor.setImplementation(Assert.class.getName());
55 MojoExecution execution = new MojoExecution(this.mojoDescriptor);
56 MojoInfo info = new MojoInfo(execution, null, null, null, -1);
57
58 ExecutedMojo executedMojo = new ExecutedMojo(info, 1L);
59
60 Assert.assertNotNull(executedMojo.digest);
61 }
62
63 @Test
64 @Bug(5044)
65 public void testMojoFromClassesDirectory() throws IOException, InterruptedException {
66 // Faking this class as the mojo impl:
67 this.mojoDescriptor.setImplementation(getClass().getName());
68 MojoExecution execution = new MojoExecution(this.mojoDescriptor);
69 MojoInfo info = new MojoInfo(execution, null, null, null, -1);
70
71 ExecutedMojo executedMojo = new ExecutedMojo(info, 1L);
72
73 Assert.assertEquals("com.test", executedMojo.groupId);
74 }
75 }
76