Skip to content

Commit

Permalink
[JENKINS-70560] Improve DescriptorImpl test coverage (#285)
Browse files Browse the repository at this point in the history
* [Jenkins-70560] Improve DescriptorImpl test coverage

* Update
  • Loading branch information
code-arnab authored Dec 13, 2024
1 parent 8f3b4f7 commit cff5087
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/test/java/hudson/plugin/versioncolumn/VersionMonitorTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package hudson.plugin.versioncolumn;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.*;

import hudson.Util;
Expand Down Expand Up @@ -113,7 +117,7 @@ public void testMonitor_DifferentVersion_NotIgnored() throws IOException, Interr
@Test
public void testMonitor_DifferentVersion_Ignored() throws IOException, InterruptedException {
VersionMonitor.DescriptorImpl descriptor = spy(new VersionMonitor.DescriptorImpl());
doReturn(true).when(descriptor).isIgnored(); // Ensure isIgnored returns true
doReturn(true).when(descriptor).isIgnored(); // Ensure isIgnored returns true.

Computer computer = mock(Computer.class);
VirtualChannel channel = mock(VirtualChannel.class);
Expand All @@ -131,7 +135,7 @@ public void testMonitor_DifferentVersion_Ignored() throws IOException, Interrupt
}

@Test
public void testMonitor_VersionIsNull() throws IOException, InterruptedException {
public void testMonitor_VersionIsNull_NotIgnored() throws IOException, InterruptedException {
VersionMonitor.DescriptorImpl descriptor = spy(new VersionMonitor.DescriptorImpl());
doReturn(false).when(descriptor).isIgnored(); // Ensure isIgnored returns false

Expand All @@ -150,6 +154,27 @@ public void testMonitor_VersionIsNull() throws IOException, InterruptedException
verify(computer).setTemporarilyOffline(eq(true), any(VersionMonitor.RemotingVersionMismatchCause.class));
}

@Test
public void testMonitor_VersionIsNull_Ignored() throws IOException, InterruptedException {
VersionMonitor.DescriptorImpl descriptor = spy(new VersionMonitor.DescriptorImpl());
doReturn(true).when(descriptor).isIgnored(); // Ensure isIgnored returns true.

Computer computer = mock(Computer.class);
VirtualChannel channel = mock(VirtualChannel.class);
VersionMonitor.RemotingVersionMismatchCause cause = mock(VersionMonitor.RemotingVersionMismatchCause.class);

when(computer.getChannel()).thenReturn(channel);
when(channel.call(ArgumentMatchers.<MasterToSlaveCallable<String, IOException>>any()))
.thenReturn(null);
when(computer.isOffline()).thenReturn(true);
when(computer.getOfflineCause()).thenReturn(cause);

String result = descriptor.monitor(computer);

assertNull(result);
verify(computer).setTemporarilyOffline(eq(false), isNull());
}

@Test
public void testMonitor_OfflineDueToMismatch_VersionsMatch() throws IOException, InterruptedException {
VersionMonitor.DescriptorImpl descriptor = new VersionMonitor.DescriptorImpl();
Expand Down

0 comments on commit cff5087

Please sign in to comment.