-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for BuildParameterStrategy class (#435)
* Add test for BuildParameterStrategy class * remove extra BuildParameterStrategy object * remove unused Exception from the Test methods
- Loading branch information
1 parent
f1aa5dd
commit 52d2639
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/test/java/jenkins/advancedqueue/priority/strategy/BuildParameterStrategyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package jenkins.advancedqueue.priority.strategy; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import hudson.model.ParametersAction; | ||
import hudson.model.Queue; | ||
import hudson.model.StringParameterValue; | ||
import java.io.IOException; | ||
import java.util.Calendar; | ||
import java.util.Collections; | ||
import jenkins.advancedqueue.PrioritySorterConfiguration; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class BuildParameterStrategyTest { | ||
|
||
@ClassRule | ||
public static JenkinsRule j = new JenkinsRule(); | ||
|
||
private static FreeStyleProject project; | ||
private static BuildParameterStrategy strategy; | ||
|
||
@BeforeClass | ||
public static void setUp() throws IOException { | ||
project = j.createFreeStyleProject(); | ||
strategy = new BuildParameterStrategy("priority"); | ||
} | ||
|
||
@Test | ||
public void getPriority_returnsPriorityFromParameter() { | ||
StringParameterValue param = new StringParameterValue("priority", "5"); | ||
ParametersAction action = new ParametersAction(param); | ||
Queue.Item item = new Queue.WaitingItem(Calendar.getInstance(), project, Collections.singletonList(action)); | ||
|
||
int priority = strategy.getPriority(item); | ||
|
||
assertEquals(5, priority); | ||
} | ||
|
||
@Test | ||
public void getPriority_returnsDefaultPriorityWhenParameterIsMissing() { | ||
Queue.Item item = new Queue.WaitingItem(Calendar.getInstance(), project, Collections.emptyList()); | ||
|
||
int priority = strategy.getPriority(item); | ||
|
||
assertEquals(PrioritySorterConfiguration.get().getStrategy().getDefaultPriority(), priority); | ||
} | ||
|
||
@Test | ||
public void getPriority_returnsDefaultPriorityWhenParameterIsNotANumber() { | ||
StringParameterValue param = new StringParameterValue("priority", "not-a-number"); | ||
ParametersAction action = new ParametersAction(param); | ||
Queue.Item item = new Queue.WaitingItem(Calendar.getInstance(), project, Collections.singletonList(action)); | ||
|
||
int priority = strategy.getPriority(item); | ||
|
||
assertEquals(PrioritySorterConfiguration.get().getStrategy().getDefaultPriority(), priority); | ||
} | ||
|
||
@Test | ||
public void isApplicable_returnsTrueWhenParameterIsPresentAndValid() { | ||
StringParameterValue param = new StringParameterValue("priority", "5"); | ||
ParametersAction action = new ParametersAction(param); | ||
Queue.Item item = new Queue.WaitingItem(Calendar.getInstance(), project, Collections.singletonList(action)); | ||
|
||
assertTrue(strategy.isApplicable(item)); | ||
} | ||
|
||
@Test | ||
public void isApplicable_returnsFalseWhenParameterIsMissing() { | ||
Queue.Item item = new Queue.WaitingItem(Calendar.getInstance(), project, Collections.emptyList()); | ||
|
||
assertFalse(strategy.isApplicable(item)); | ||
} | ||
|
||
@Test | ||
public void isApplicable_returnsFalseWhenParameterIsNotANumber() { | ||
StringParameterValue param = new StringParameterValue("priority", "not-a-number"); | ||
ParametersAction action = new ParametersAction(param); | ||
Queue.Item item = new Queue.WaitingItem(Calendar.getInstance(), project, Collections.singletonList(action)); | ||
|
||
assertFalse(strategy.isApplicable(item)); | ||
} | ||
} |