-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-69757 Improve priority sorter plugin automated test coverage (#…
…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
1 parent
b0bef79
commit 99f370d
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
src/test/java/jenkins/advancedqueue/test/PrioritySorterConfigurationTest.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,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); | ||
} | ||
} | ||
} |