1
1
package hudson.maven.reporters;
3
import static org.junit.Assert.assertEquals;
3
4
import static org.mockito.Mockito.doReturn;
4
5
import static org.mockito.Mockito.mock;
5
6
import static org.mockito.Mockito.spy;
13
14
import hudson.maven.MavenProjectActionBuilder;
14
15
import hudson.maven.MavenReporter;
15
16
import hudson.maven.MojoInfo;
17
import hudson.maven.MojoInfoBuilder;
16
18
import hudson.model.BuildListener;
17
19
import hudson.model.Cause;
18
20
import hudson.model.Result;
28
30
import java.util.List;
30
32
import org.apache.commons.io.output.NullOutputStream;
31
import org.apache.maven.plugin.MojoExecution;
32
import org.apache.maven.plugin.descriptor.MojoDescriptor;
33
import org.apache.maven.plugin.descriptor.PluginDescriptor;
34
import org.apache.tools.ant.types.FileSet;
35
33
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
36
34
import org.junit.Assert;
37
35
import org.junit.Before;
54
52
@SuppressWarnings("unchecked")
55
53
public void before() throws ComponentConfigurationException, URISyntaxException {
56
//suppress(constructor(MavenBuild.class, new Class[0]));
58
54
this.archiver = new SurefireArchiver();
59
55
this.build = mock(MavenBuild.class);
60
56
when(build.getAction(Matchers.any(Class.class))).thenCallRealMethod();
71
67
private MojoInfo createMojoInfo() throws ComponentConfigurationException {
72
PluginDescriptor pluginDescriptor = new PluginDescriptor();
73
pluginDescriptor.setGroupId("org.apache.maven.plugins");
74
pluginDescriptor.setArtifactId("maven-surefire-plugin");
75
pluginDescriptor.setVersion("2.9");
77
MojoDescriptor mojoDescriptor = new MojoDescriptor();
78
mojoDescriptor.setPluginDescriptor(pluginDescriptor);
79
mojoDescriptor.setGoal("test");
81
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
82
MojoInfo info = new MojoInfo(mojoExecution, null, null, null);
68
MojoInfo info = MojoInfoBuilder.mojoBuilder("org.apache.maven.plugins", "maven-surefire-plugin", "test")
69
.version("2.9").build();
84
71
MojoInfo spy = spy(info);
103
90
public void testArchiveResults() throws InterruptedException, IOException, URISyntaxException, ComponentConfigurationException {
104
91
URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test2");
105
92
File reportsDir = new File(resource.toURI().getPath());
106
94
doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class);
107
95
touchReportFiles(reportsDir);
133
public void testAlreadyCheckedFilesAreNotParsedAgain() throws InterruptedException, IOException, URISyntaxException, ComponentConfigurationException {
121
public void testResultsAreNotCountedTwice() throws InterruptedException, IOException, URISyntaxException, ComponentConfigurationException {
134
122
URL resource = SurefireArchiverUnitTest.class.getResource("/surefire-archiver-test2");
135
123
File reportsDir = new File(resource.toURI().getPath());
136
124
doReturn(reportsDir).when(this.mojoInfo).getConfigurationValue("reportsDirectory", File.class);
137
125
touchReportFiles(reportsDir);
139
FileSet fileSet = this.archiver.getFileSet(reportsDir);
140
Assert.assertEquals(2, fileSet.getDirectoryScanner().getIncludedFilesCount());
127
this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null);
128
SurefireReport action = this.build.getAction(SurefireReport.class);
129
TestResult result = action.getResult();
130
assertEquals(2658, result.getTotalCount());
132
// result count shouldn't increase if mojo is called again
142
133
this.archiver.postExecute(buildProxy, null, this.mojoInfo, new NullBuildListener(), null);
144
fileSet = this.archiver.getFileSet(reportsDir);
145
Assert.assertEquals(0, fileSet.getDirectoryScanner().getIncludedFilesCount());
134
action = this.build.getAction(SurefireReport.class);
135
result = action.getResult();
136
assertEquals(2658, result.getTotalCount());