Skip to content
Permalink
Browse files

[JENKINS-45472] Add test

Without the fix, test fails in line 308 with:

org.junit.ComparisonFailure:
Expected :for p2
Actual   :for p1
  • Loading branch information
daniel-beck committed Sep 28, 2017
1 parent e044675 commit 9c939c4eb421f2ab08f27bfef10c1754d5295ab7
Showing with 26 additions and 0 deletions.
  1. +26 −0 test/src/test/java/hudson/model/ParametersAction2Test.java
@@ -2,6 +2,7 @@

import hudson.Functions;
import hudson.Launcher;
import hudson.model.queue.QueueTaskFuture;
import hudson.tasks.BatchFile;
import hudson.tasks.Builder;
import org.junit.Rule;
@@ -11,8 +12,10 @@
import org.jvnet.hudson.test.recipes.LocalData;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -283,6 +286,29 @@ public void nonParameterizedJobButWhitelisted() throws Exception {
}
}

@Test
@Issue("JENKINS-45472")
public void ensureNoListReuse() throws Exception {
FreeStyleProject p1 = j.createFreeStyleProject();
p1.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("foo", "")));
FreeStyleProject p2 = j.createFreeStyleProject();
p2.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("foo", "")));

List<ParameterValue> params = new ArrayList<>();
params.add(new StringParameterValue("foo", "for p1"));
p1.scheduleBuild2(1, new ParametersAction(params));
params.clear();
params.add(new StringParameterValue("foo", "for p2"));
p2.scheduleBuild2(0, new ParametersAction(params));

j.waitUntilNoActivity();

assertEquals(1, p1.getLastBuild().getAction(ParametersAction.class).getParameters().size());
assertEquals(1, p2.getLastBuild().getAction(ParametersAction.class).getParameters().size());
assertEquals(p1.getLastBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), "for p1");
assertEquals(p2.getLastBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), "for p2");
}

public static boolean hasParameterWithName(Iterable<ParameterValue> values, String name) {
for (ParameterValue v : values) {
if (v.getName().equals(name)) {

0 comments on commit 9c939c4

Please sign in to comment.