Skip to content

Commit

Permalink
Add test for PrioritySorterJobColumn class (#434)
Browse files Browse the repository at this point in the history
* 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
yashpal2104 and MarkEWaite authored Jan 7, 2025
1 parent 52d2639 commit ce836d1
Showing 1 changed file with 61 additions and 0 deletions.
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());
}
}

0 comments on commit ce836d1

Please sign in to comment.