Skip to content

Commit

Permalink
Regression test and changelog for [JENKINS-16573]
Browse files Browse the repository at this point in the history
Originally-Committed-As: bdd8580882295177900855572e41ce891ab9cfaf
  • Loading branch information
kutzi committed Jan 31, 2013
1 parent 94fb9bb commit b476729
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/main/java/hudson/maven/MojoInfo.java
Expand Up @@ -45,6 +45,8 @@
import java.lang.reflect.Proxy;
import java.lang.reflect.Method;

import javax.annotation.CheckForNull;

import hudson.util.InvocationInterceptor;
import hudson.util.ReflectionUtils;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
Expand Down Expand Up @@ -145,13 +147,14 @@ public String getGoal() {
*
* @return
* The configuration value either specified in POM, or inherited from
* parent POM, or default value if one is specified in mojo.
* parent POM, or default value if one is specified in mojo,
* or null if no such configuration value exists.
*
* @throws ComponentConfigurationException
* Not sure when exactly this is thrown, but it's probably when
* the configuration in POM is syntactically incorrect.
*/
public <T> T getConfigurationValue(String configName, Class<T> type) throws ComponentConfigurationException {
@CheckForNull public <T> T getConfigurationValue(String configName, Class<T> type) throws ComponentConfigurationException {
PlexusConfiguration child = configuration.getChild(configName,false);
if(child==null) return null; // no such config

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/hudson/maven/reporters/TestMojo.java
Expand Up @@ -8,6 +8,8 @@
import java.util.Collections;
import java.util.Iterator;

import javax.annotation.CheckForNull;

import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.types.FileSet;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
Expand Down Expand Up @@ -60,7 +62,10 @@ public Collection<File> getReportFiles(MavenProject pom,MojoInfo mojo)
File reportsDir = mojo.getConfigurationValue("jasmineTargetDir", File.class);
String junitFileName = mojo.getConfigurationValue("junitXmlReportFileName", String.class);

return Collections.singleton(new File(reportsDir,junitFileName));
if (reportsDir != null && junitFileName != null) {
return Collections.singleton(new File(reportsDir,junitFileName));
}
return null;
}
},
TOOLKIT_RESOLVER_PLUGIN("org.terracotta.maven.plugins", "toolkit-resolver-plugin", "toolkit-resolve-test","reportsDirectory");
Expand Down Expand Up @@ -98,7 +103,7 @@ public boolean canRunTests(MojoInfo mojo) {
return mojo.pluginName.version.compareTo(this.minimalRequiredVersion) >= 0;
}

public Iterable<File> getReportFiles(MavenProject pom, MojoInfo mojo) throws ComponentConfigurationException {
@CheckForNull public Iterable<File> getReportFiles(MavenProject pom, MojoInfo mojo) throws ComponentConfigurationException {
if (this.reportDirectoryConfigKey != null) {
File reportsDir = mojo.getConfigurationValue(this.reportDirectoryConfigKey, File.class);
if (reportsDir != null && reportsDir.exists()) {
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/hudson/maven/reporters/TestMojoTest.java
@@ -0,0 +1,36 @@
package hudson.maven.reporters;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import hudson.maven.MojoInfo;
import hudson.maven.MojoInfoBuilder;

import java.io.File;

import org.apache.maven.model.Build;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;

public class TestMojoTest {

@Test
@Bug(16573)
public void testGetReportFilesThrowsNoException() throws ComponentConfigurationException {
// no 'reportsDirectory' or so config value set:
MojoInfo mojoInfo = MojoInfoBuilder.mojoBuilder("com.some", "testMojo", "test").build();

MavenProject pom = mock(MavenProject.class);
when(pom.getBasedir()).thenReturn(new File("foo"));

Build build = mock(Build.class);
when(build.getDirectory()).thenReturn("bar");
when(pom.getBuild()).thenReturn(build);

for (TestMojo testMojo : TestMojo.values()) {
testMojo.getReportFiles(pom, mojoInfo);
}
}

}

0 comments on commit b476729

Please sign in to comment.