Skip to content

Commit

Permalink
JENKINS-69757 Improve priority sorter plugin automated test coverage (#…
Browse files Browse the repository at this point in the history
…259)

* Create PrioritySorterConfigurationTest.java

* tests add

* tests bug fix

* tests bug fix

* tests bug fix

* revert MatrixTest

* Rerun ci

* Remove unnecessary version specification

---------

Co-authored-by: Huikun Zheng <huikunzheng9955@gmail.com>
Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
  • Loading branch information
3 people committed May 17, 2023
1 parent b0bef79 commit 99f370d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<version>1.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package jenkins.advancedqueue.test;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import hudson.util.ListBoxModel;
import java.util.Arrays;
import java.util.List;
import jenkins.advancedqueue.PrioritySorterConfiguration;
import jenkins.advancedqueue.sorter.SorterStrategy;
import jenkins.advancedqueue.sorter.SorterStrategyDescriptor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.mockito.MockedStatic;

public class PrioritySorterConfigurationTest {
@Rule
public JenkinsRule j = new JenkinsRule();

private PrioritySorterConfiguration prioritySorterConfiguration;
private SorterStrategyDescriptor sorterStrategyDescriptor1, sorterStrategyDescriptor2;

@Before
public void setUp() {
prioritySorterConfiguration = new PrioritySorterConfiguration();
sorterStrategyDescriptor1 = mock(SorterStrategyDescriptor.class);
sorterStrategyDescriptor2 = mock(SorterStrategyDescriptor.class);
}

@Test
public void testDoFillStrategyItems() {
when(sorterStrategyDescriptor1.getDisplayName()).thenReturn("DisplayName1");
when(sorterStrategyDescriptor1.getKey()).thenReturn("Key1");
when(sorterStrategyDescriptor2.getDisplayName()).thenReturn("DisplayName2");
when(sorterStrategyDescriptor2.getKey()).thenReturn("Key2");

List<SorterStrategyDescriptor> mockStrategies =
Arrays.asList(sorterStrategyDescriptor1, sorterStrategyDescriptor2);

try (MockedStatic<SorterStrategy> mocked = mockStatic(SorterStrategy.class)) {
mocked.when(SorterStrategy::getAllSorterStrategies).thenReturn(mockStrategies);

ListBoxModel result = prioritySorterConfiguration.doFillStrategyItems();

assertEquals(2, result.size());
assertEquals("DisplayName1", result.get(0).name);
assertEquals("Key1", result.get(0).value);
assertEquals("DisplayName2", result.get(1).name);
assertEquals("Key2", result.get(1).value);
}
}
}

0 comments on commit 99f370d

Please sign in to comment.