// Path: src/main/java/com/tikal/jenkins/plugins/multijob/MultiJobParametersAction.java
// @Restricted(NoExternalUse.class)
// public class MultiJobParametersAction extends ParametersAction {
// 
//     private List<ParameterValue> parameters;
// 
//     public MultiJobParametersAction(@Nonnull List<ParameterValue> parameters) {
//         super(parameters);
//         this.parameters = parameters;
//     }
// 
//     public MultiJobParametersAction(ParameterValue... parameters) {
//         this(Arrays.asList(parameters));
//     }
// 
//     @Override
//     public List<ParameterValue> getParameters() {
//         return Collections.unmodifiableList(parameters);
//     }
// 
//     @Override
//     public ParameterValue getParameter(String name) {
//         for (ParameterValue parameter : parameters) {
//             if (parameter != null && parameter.getName().equals(name)) {
//                 return parameter;
//             }
//         }
// 
//         return null;
//     }
// 
//     @Extension
//     public static final class MultiJobParametersActionEnvironmentContributor extends EnvironmentContributor {
// 
//         @Override
//         public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException {
//             MultiJobParametersAction action = r.getAction(MultiJobParametersAction.class);
//             if (action != null) {
//                 for (ParameterValue p : action.getParameters()) {
//                     envs.putIfNotNull(p.getName(), String.valueOf(p.getValue()));
//                 }
//             }
//         }
//     }
// }


import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import com.tikal.jenkins.plugins.multijob.MultiJobParametersAction;
import hudson.model.Action;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.StringParameterValue;
import java.util.Collections;
import org.junit.Assert;
        MultiJobParametersAction params1 = new MultiJobParametersAction(new StringParameterValue("A", "aValue"), new StringParameterValue("B", "bValue"));
        MultiJobParametersAction params2 = new MultiJobParametersAction();
        ParametersAction params3 = new ParametersAction(new StringParameterValue("A", "aValue"), new StringParameterValue("B", "bValue"));
        ParametersAction params4 = new ParametersAction();
        
        // Empty MultiJob
        Assert.assertTrue("MultiJob Parameters set should not allow merge with empty MultiJob parameters", params1.shouldSchedule(Collections.<Action>singletonList(params2)));
        Assert.assertTrue("Empty parameters MultiJob should not allow merge with non-empty MultiJob parameter set", params2.shouldSchedule(Collections.<Action>singletonList(params1)));
        
        // Empty ParametersAction
        Assert.assertTrue("Parameters set should not allow merge with empty parameters", params1.shouldSchedule(Collections.<Action>singletonList(params4)));
        Assert.assertTrue("Empty parameters should not allow merge with non-empty MultiJob parameter set", params4.shouldSchedule(Collections.<Action>singletonList(params1)));  
    
        // ParametersAction with empty MultiJob
        Assert.assertTrue("Parameters set should not allow merge with empty MultiJob parameters", params3.shouldSchedule(Collections.<Action>singletonList(params2)));
        Assert.assertTrue("Empty parameters MultiJob should not allow merge with non-empty parameter set", params2.shouldSchedule(Collections.<Action>singletonList(params3)));
        
    }
    
    private static void assertShouldNotSchedule(MultiJobParametersAction current, ParameterValue ... scheduled) 
            throws AssertionError {
        assertShouldNotSchedule(current, false, scheduled);
    }
    
    private static void assertShouldNotSchedule(MultiJobParametersAction current, boolean multiJob, ParameterValue ... scheduled) 
            throws AssertionError {
        ParametersAction toSchedule = multiJob ? new MultiJobParametersAction(scheduled) : new ParametersAction(scheduled);
        Assert.assertTrue("Different parameter sets should not be merged", current.shouldSchedule(Collections.<Action>singletonList(toSchedule))); 
    }
    
// Path: src/main/java/com/tikal/jenkins/plugins/multijob/MultiJobParametersAction.java
// @Restricted(NoExternalUse.class)
// public class MultiJobParametersAction extends ParametersAction {
// 
//     private List<ParameterValue> parameters;
// 
//     public MultiJobParametersAction(@Nonnull List<ParameterValue> parameters) {
//         super(parameters);
//         this.parameters = parameters;
//     }
// 
//     public MultiJobParametersAction(ParameterValue... parameters) {
//         this(Arrays.asList(parameters));
//     }
// 
//     @Override
//     public List<ParameterValue> getParameters() {
//         return Collections.unmodifiableList(parameters);
//     }
// 
//     @Override
//     public ParameterValue getParameter(String name) {
//         for (ParameterValue parameter : parameters) {
//             if (parameter != null && parameter.getName().equals(name)) {
//                 return parameter;
//             }
//         }
// 
//         return null;
//     }
// 
//     @Extension
//     public static final class MultiJobParametersActionEnvironmentContributor extends EnvironmentContributor {
// 
//         @Override
//         public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException {
//             MultiJobParametersAction action = r.getAction(MultiJobParametersAction.class);
//             if (action != null) {
//                 for (ParameterValue p : action.getParameters()) {
//                     envs.putIfNotNull(p.getName(), String.valueOf(p.getValue()));
//                 }
//             }
//         }
//     }
// }


// Path: src/test/java/com/tikal/jenkins/plugins/multijob/test/MultiJobParametersActionTest.java
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import com.tikal.jenkins.plugins.multijob.MultiJobParametersAction;
import hudson.model.Action;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.StringParameterValue;
import java.util.Collections;
import org.junit.Assert;

        MultiJobParametersAction params1 = new MultiJobParametersAction(new StringParameterValue("A", "aValue"), new StringParameterValue("B", "bValue"));
        MultiJobParametersAction params2 = new MultiJobParametersAction();
        ParametersAction params3 = new ParametersAction(new StringParameterValue("A", "aValue"), new StringParameterValue("B", "bValue"));
        ParametersAction params4 = new ParametersAction();
        
        // Empty MultiJob
        Assert.assertTrue("MultiJob Parameters set should not allow merge with empty MultiJob parameters", params1.shouldSchedule(Collections.<Action>singletonList(params2)));
        Assert.assertTrue("Empty parameters MultiJob should not allow merge with non-empty MultiJob parameter set", params2.shouldSchedule(Collections.<Action>singletonList(params1)));
        
        // Empty ParametersAction
        Assert.assertTrue("Parameters set should not allow merge with empty parameters", params1.shouldSchedule(Collections.<Action>singletonList(params4)));
        Assert.assertTrue("Empty parameters should not allow merge with non-empty MultiJob parameter set", params4.shouldSchedule(Collections.<Action>singletonList(params1)));  
    
        // ParametersAction with empty MultiJob
        Assert.assertTrue("Parameters set should not allow merge with empty MultiJob parameters", params3.shouldSchedule(Collections.<Action>singletonList(params2)));
        Assert.assertTrue("Empty parameters MultiJob should not allow merge with non-empty parameter set", params2.shouldSchedule(Collections.<Action>singletonList(params3)));
        
    }
    
    private static void assertShouldNotSchedule(MultiJobParametersAction current, ParameterValue ... scheduled) 
            throws AssertionError {
        assertShouldNotSchedule(current, false, scheduled);
    }
    
    private static void assertShouldNotSchedule(MultiJobParametersAction current, boolean multiJob, ParameterValue ... scheduled) 
            throws AssertionError {
        ParametersAction toSchedule = multiJob ? new MultiJobParametersAction(scheduled) : new ParametersAction(scheduled);
        Assert.assertTrue("Different parameter sets should not be merged", current.shouldSchedule(Collections.<Action>singletonList(toSchedule))); 
    }
    
    private static void assertShouldSchedule(MultiJobParametersAction current, ParameterValue ... scheduled) 