-
Notifications
You must be signed in to change notification settings - Fork 74
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 PrioritySorterJobColumn class (#434)
* Add test for PrioritySorterJobColumn class * Make ItemInfo method public to allow instantiation from other classes * Fixed typo * Revert "Fixed typo" This reverts commit 9b9cc1e. * Simplify the test and remove production object change No need to make the ItemInfo constructor publicly visible when the test class can be moved into the same package as the ItemInfo class. --------- Co-authored-by: Mark Waite <[email protected]>
- Loading branch information
1 parent
52d2639
commit ce836d1
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/test/java/jenkins/advancedqueue/sorter/PrioritySorterJobColumnTest.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,61 @@ | ||
package jenkins.advancedqueue.sorter; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Queue; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import jenkins.advancedqueue.PrioritySorterJobColumn; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class PrioritySorterJobColumnTest { | ||
|
||
@ClassRule | ||
public static JenkinsRule j = new JenkinsRule(); | ||
|
||
private static FreeStyleProject project; | ||
private static ItemInfo itemInfo; | ||
private static PrioritySorterJobColumn column; | ||
|
||
@BeforeClass | ||
public static void setUp() throws IOException { | ||
project = j.createFreeStyleProject("test-job"); | ||
Queue.WaitingItem waitingItem = new Queue.WaitingItem(Calendar.getInstance(), project, new ArrayList<>()); | ||
itemInfo = new ItemInfo(waitingItem); | ||
column = new PrioritySorterJobColumn(); | ||
} | ||
|
||
@Test | ||
public void getPriorityReturnsPendingWhenItemInfoIsNull() throws Exception { | ||
assertEquals("Pending", column.getPriority(project)); | ||
} | ||
|
||
@Test | ||
public void getPriorityReturnsCorrectPriority() throws Exception { | ||
QueueItemCache.get().addItem(itemInfo); | ||
assertEquals("0", column.getPriority(project)); | ||
} | ||
|
||
@Test | ||
public void getPriorityReturnsPendingForNonExistentJob() throws Exception { | ||
assertEquals("Pending", column.getPriority(project)); | ||
} | ||
|
||
@Test | ||
public void descriptorImplDisplayNameIsCorrect() { | ||
assertEquals("Priority Value", column.getDescriptor().getDisplayName()); | ||
} | ||
|
||
@Test | ||
public void descriptorImplShownByDefaultIsFalse() { | ||
PrioritySorterJobColumn.DescriptorImpl descriptor = | ||
(PrioritySorterJobColumn.DescriptorImpl) column.getDescriptor(); | ||
assertFalse(descriptor.shownByDefault()); | ||
} | ||
} |