提交 1774927d 编写于 作者: K Kohsuke Kawaguchi

Updating tests to work since these tests now require full-blown Jenkins

environment.
上级 19817fb7
......@@ -24,16 +24,19 @@
package hudson.model;
import junit.framework.TestCase;
import org.jvnet.hudson.test.HudsonTestCase;
import java.io.IOException;
import java.util.GregorianCalendar;
import java.util.List;
/**
* @author Kohsuke Kawaguchi
*/
public class RunTest extends TestCase {
private List<? extends Run<?,?>.Artifact> createArtifactList(String... paths) {
Run<FreeStyleProject,FreeStyleBuild> r = new Run<FreeStyleProject,FreeStyleBuild>(null,new GregorianCalendar()) {};
public class RunTest extends HudsonTestCase {
private List<? extends Run<?,?>.Artifact> createArtifactList(String... paths) throws Exception {
FreeStyleProject prj = createFreeStyleProject();
FreeStyleBuild r = prj.scheduleBuild2(0).get();
Run<FreeStyleProject,FreeStyleBuild>.ArtifactList list = r.new ArtifactList();
for (String p : paths) {
list.add(r.new Artifact(p,p,p,String.valueOf(p.length()),"n"+list.size())); // Assuming all test inputs don't need urlencoding
......@@ -42,21 +45,21 @@ public class RunTest extends TestCase {
return list;
}
public void testArtifactListDisambiguation1() {
public void testArtifactListDisambiguation1() throws Exception {
List<? extends Run<?, ?>.Artifact> a = createArtifactList("a/b/c.xml", "d/f/g.xml", "h/i/j.xml");
assertEquals(a.get(0).getDisplayPath(),"c.xml");
assertEquals(a.get(1).getDisplayPath(),"g.xml");
assertEquals(a.get(2).getDisplayPath(),"j.xml");
}
public void testArtifactListDisambiguation2() {
public void testArtifactListDisambiguation2() throws Exception {
List<? extends Run<?, ?>.Artifact> a = createArtifactList("a/b/c.xml", "d/f/g.xml", "h/i/g.xml");
assertEquals(a.get(0).getDisplayPath(),"c.xml");
assertEquals(a.get(1).getDisplayPath(),"f/g.xml");
assertEquals(a.get(2).getDisplayPath(),"i/g.xml");
}
public void testArtifactListDisambiguation3() {
public void testArtifactListDisambiguation3() throws Exception {
List<? extends Run<?, ?>.Artifact> a = createArtifactList("a.xml","a/a.xml");
assertEquals(a.get(0).getDisplayPath(),"a.xml");
assertEquals(a.get(1).getDisplayPath(),"a/a.xml");
......
......@@ -6,11 +6,13 @@ import java.util.TreeMap;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.jvnet.hudson.test.HudsonTestCase;
import org.mockito.Mockito;
/**
* Unit test for {@link Job}.
*/
public class SimpleJobTest extends TestCase {
public class SimpleJobTest extends HudsonTestCase {
public void testGetEstimatedDuration() throws IOException {
......@@ -93,31 +95,7 @@ public class SimpleJobTest extends TestCase {
}
private Job createMockProject(final SortedMap<Integer, TestBuild> runs) {
Job project = new Job(null, "name") {
int i = 1;
@Override
public int assignBuildNumber() throws IOException {
return i++;
}
@Override
public SortedMap<Integer, ? extends Run> _getRuns() {
return runs;
}
@Override
public boolean isBuildable() {
return true;
}
@Override
protected void removeRun(Run run) {
}
};
return project;
return new TestJob(runs);
}
private static class TestBuild extends Run {
......@@ -145,4 +123,39 @@ public class SimpleJobTest extends TestCase {
}
}
private class TestJob extends Job implements TopLevelItem {
int i;
private final SortedMap<Integer, TestBuild> runs;
public TestJob(SortedMap<Integer, TestBuild> runs) {
super(SimpleJobTest.this.jenkins, "name");
this.runs = runs;
i = 1;
}
@Override
public int assignBuildNumber() throws IOException {
return i++;
}
@Override
public SortedMap<Integer, ? extends Run> _getRuns() {
return runs;
}
@Override
public boolean isBuildable() {
return true;
}
@Override
protected void removeRun(Run run) {
}
public TopLevelItemDescriptor getDescriptor() {
throw new AssertionError();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册