Skip to content

Commit

Permalink
Simplify the test and remove production object change
Browse files Browse the repository at this point in the history
No need to make the ItemInfo constructor publicly visible when the test
class can be moved into the same package as the ItemInfo class.
  • Loading branch information
MarkEWaite committed Jan 7, 2025
1 parent 7de0c38 commit d7c75f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/main/java/jenkins/advancedqueue/sorter/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public class ItemInfo

private List<String> decisionLog = new ArrayList<String>(10);

/* Constructor made public to allow instantiation from other classes */
public ItemInfo(Item item) {
ItemInfo(Item item) {
this.itemId = item.getId();
this.inQueueSince = item.getInQueueSince();
this.jobName = item.task.getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jenkins.advancedqueue;
package jenkins.advancedqueue.sorter;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -8,8 +8,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import jenkins.advancedqueue.sorter.ItemInfo;
import jenkins.advancedqueue.sorter.QueueItemCache;
import jenkins.advancedqueue.PrioritySorterJobColumn;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
Expand All @@ -21,52 +20,42 @@ public class PrioritySorterJobColumnTest {
public static JenkinsRule j = new JenkinsRule();

private static FreeStyleProject project;
private static Calendar calendar;
private static Queue.WaitingItem waitingItem;
private static ItemInfo itemInfo;
private static PrioritySorterJobColumn column;

@BeforeClass
public static void setUp() throws IOException {
project = j.createFreeStyleProject("test-job");
calendar = Calendar.getInstance();
waitingItem = new Queue.WaitingItem(calendar, project, new ArrayList<>());
Queue.WaitingItem waitingItem = new Queue.WaitingItem(Calendar.getInstance(), project, new ArrayList<>());
itemInfo = new ItemInfo(waitingItem);
column = new PrioritySorterJobColumn();
}

@Test
public void getPriorityReturnsPendingWhenItemInfoIsNull() throws Exception {

PrioritySorterJobColumn column = new PrioritySorterJobColumn();
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 {

PrioritySorterJobColumn column = new PrioritySorterJobColumn();
assertEquals("Pending", column.getPriority(project));
}

@Test
public void descriptorImplDisplayNameIsCorrect() {

PrioritySorterJobColumn.DescriptorImpl descriptor = new PrioritySorterJobColumn.DescriptorImpl();
assertEquals("Priority Value", descriptor.getDisplayName());
assertEquals("Priority Value", column.getDescriptor().getDisplayName());
}

@Test
public void descriptorImplShownByDefaultIsFalse() {
PrioritySorterJobColumn.DescriptorImpl descriptor = new PrioritySorterJobColumn.DescriptorImpl();
PrioritySorterJobColumn.DescriptorImpl descriptor =
(PrioritySorterJobColumn.DescriptorImpl) column.getDescriptor();
assertFalse(descriptor.shownByDefault());
}
}

0 comments on commit d7c75f9

Please sign in to comment.