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

1 package hudson.maven.reporters;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6 import static org.mockito.Mockito.mock;
7 import static org.mockito.Mockito.when;
8 import hudson.maven.MojoInfo;
9 import hudson.maven.MojoInfoBuilder;
10
11 import java.io.File;
12 import java.io.FileWriter;
13
14 import org.apache.maven.model.Build;
15 import org.apache.maven.project.MavenProject;
16 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
17 import org.junit.Test;
18 import org.jvnet.hudson.test.Bug;
19
20 public class TestMojoTest {
21
22 @Test
23 @Bug(16573)
24 public void testGetReportFilesThrowsNoException() throws ComponentConfigurationException {
25 // no 'reportsDirectory' or so config value set:
26 MojoInfo mojoInfo = MojoInfoBuilder.mojoBuilder("com.some", "testMojo", "test").build();
27
28 MavenProject pom = mock(MavenProject.class);
29 when(pom.getBasedir()).thenReturn(new File("foo"));
30
31 Build build = mock(Build.class);
32 when(build.getDirectory()).thenReturn("bar");
33 when(pom.getBuild()).thenReturn(build);
34
35 for (TestMojo testMojo : TestMojo.values()) {
36 testMojo.getReportFiles(pom, mojoInfo);
37 }
38 }
39
40 @Test
41 public void testGetReportFilesAndroidMavenPlugin() throws ComponentConfigurationException, Exception {
42 // no 'reportsDirectory' or so config value set:
43 MojoInfo mojoInfo = MojoInfoBuilder.mojoBuilder(
44 "com.jayway.maven.plugins.android.generation2",
45 "android-maven-plugin",
46 "internal-integration-test")
47 .version("3.3.0")
48 .build();
49
50 final String testResultsName = "TEST-emulator-5554_device2.1_unknown_google_sdk.xml";
51
52 File testDir = hudson.Util.createTempDir();
53 File targetDir = new File(testDir, "target");
54 File reportsDir = new File(targetDir, "surefire-reports");
55 assertTrue(reportsDir.mkdirs());
56
57 File testResults = new File(reportsDir, testResultsName);
58 try {
59 FileWriter fw = new FileWriter(testResults, false);
60 fw.write("this is a fake surefire reports output file");
61 fw.close();
62
63 MavenProject pom = mock(MavenProject.class);
64 when(pom.getBasedir()).thenReturn(testDir);
65
66 Build build = mock(Build.class);
67 when(build.getDirectory()).thenReturn(targetDir.getAbsolutePath());
68 when(pom.getBuild()).thenReturn(build);
69
70 TestMojo testMojo = TestMojo.ANDROID_MAVEN_PLUGIN;
71 Iterable<File> files = testMojo.getReportFiles(pom, mojoInfo);
72 assertNotNull("no report files returned", files);
73
74 boolean found = false;
75 for (File file : files) {
76 assertEquals(testResultsName, file.getName());
77 found = true;
78 }
79 assertTrue("report file not found", found);
80 } finally {
81 testResults.delete();
82 }
83 }
84 }
85