Skip to content

Commit

Permalink
[JENKINS-17318] Added unit test to prevent regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
lessonz committed Jul 26, 2013
1 parent b025127 commit 83b3cb7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Expand Up @@ -93,5 +93,14 @@
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

27 changes: 27 additions & 0 deletions src/test/java/hudson/plugins/fitnesse/FitnesseBuilderTest.java
@@ -1,10 +1,19 @@
package hudson.plugins.fitnesse;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import hudson.model.AbstractBuild;
import hudson.model.Node;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.util.DescribableList;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

public class FitnesseBuilderTest {
@Test
Expand Down Expand Up @@ -120,4 +129,22 @@ public void getJavaWorkingDirShouldBeEmptyIfFitnessseJarUnspecified() throws Exc
Assert.assertEquals("",
builder.getFitnesseJavaWorkingDirectory());
}

@SuppressWarnings("unchecked")
@Test
public void getFitnesseHostShouldNotThrowANullPointerWhenNodePropertyIsNull() throws InterruptedException, IOException {
@SuppressWarnings("rawtypes")
AbstractBuild build = Mockito.mock(AbstractBuild.class);
Node node = Mockito.mock(Node.class);
when(build.getBuiltOn()).thenReturn(node);
@SuppressWarnings("rawtypes")
DescribableList describableList = Mockito.mock(DescribableList.class);
when(node.getNodeProperties()).thenReturn(describableList);
when(describableList.get(EnvironmentVariablesNodeProperty.class)).thenReturn(null);

HashMap<String, String> options = new HashMap<String, String>();
options.put(FitnesseBuilder.START_FITNESSE, Boolean.toString(true));
FitnesseBuilder builder = new FitnesseBuilder(options);
assertEquals(FitnesseBuilder._LOCALHOST, builder.getFitnesseHost(build));
}
}

0 comments on commit 83b3cb7

Please sign in to comment.