-
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 SorterStrategyDescriptor class (#429)
* Add test for SorterStrategyDescriptor class * Use spotbugs NonNull annotation, not JetBrains The spotbugs annotation is used in the declaration of the method so should be used in this implementation. * Use a single JenkinsRule for the entire test class Individual tests do not need the cost or time delay of starting a new Jenkins controller. * Test more of the private implementation Allocate a strategy and test its descriptor * Remove duplicate test of descriptor not null Other tests will fail if descriptor is null --------- Co-authored-by: Mark Waite <[email protected]>
- Loading branch information
1 parent
8de4326
commit f1aa5dd
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/test/java/jenkins/advancedqueue/sorter/SorterStrategyDescriptorTest.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,82 @@ | ||
package jenkins.advancedqueue.sorter; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Queue; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class SorterStrategyDescriptorTest { | ||
|
||
@ClassRule | ||
public static JenkinsRule j = new JenkinsRule(); | ||
|
||
private static FreeStyleProject project; | ||
private static FreeStyleBuild build; | ||
private static SorterStrategy strategy; | ||
private static SorterStrategyDescriptor descriptor; | ||
|
||
private static final String STRATEGY_NAME = "strategy short name"; | ||
private static final int NUMBER_OF_PRIORITIES = 9; | ||
private static final int DEFAULT_PRIORITY = 4; | ||
|
||
@BeforeClass | ||
public static void runJob() throws Exception { | ||
project = j.createFreeStyleProject(); | ||
build = project.scheduleBuild2(0).get(); | ||
strategy = new TestSorterStrategy(); | ||
descriptor = strategy.getDescriptor(); | ||
j.assertBuildStatusSuccess(build); | ||
} | ||
|
||
@Test | ||
public void getNumberOfPriorities() { | ||
assertEquals(NUMBER_OF_PRIORITIES, strategy.getNumberOfPriorities()); | ||
} | ||
|
||
@Test | ||
public void getDefaultPriority() { | ||
assertEquals(DEFAULT_PRIORITY, strategy.getDefaultPriority()); | ||
} | ||
|
||
@Test | ||
public void getShortNameReturnsCorrectValue() { | ||
assertEquals(STRATEGY_NAME, descriptor.getShortName()); | ||
} | ||
|
||
@Test | ||
public void getKeyReturnsShortName() { | ||
assertEquals(STRATEGY_NAME, descriptor.getKey()); | ||
} | ||
|
||
private static class TestSorterStrategy extends SorterStrategy { | ||
@Override | ||
public SorterStrategyCallback onNewItem(@NonNull Queue.Item item, SorterStrategyCallback weightCallback) { | ||
return weightCallback; | ||
} | ||
|
||
@Override | ||
public int getNumberOfPriorities() { | ||
return NUMBER_OF_PRIORITIES; | ||
} | ||
|
||
@Override | ||
public int getDefaultPriority() { | ||
return DEFAULT_PRIORITY; | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends SorterStrategyDescriptor { | ||
@Override | ||
public String getShortName() { | ||
return STRATEGY_NAME; | ||
} | ||
} | ||
} | ||
} |