Skip to content

Commit 73c3220

Browse files
test: add test for DescriptorImpl class (jenkinsci#303)
1 parent 206cd42 commit 73c3220

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/java/hudson/plugin/versioncolumn/VersionMonitorTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ public void testMonitor_DifferentVersion_Ignored() throws IOException, Interrupt
107107
verify(computer, never()).setTemporarilyOffline(anyBoolean(), any());
108108
}
109109

110+
@Test
111+
public void testMonitor_DifferentVersion_NotIgnored() throws IOException, InterruptedException {
112+
VersionMonitor.DescriptorImpl mockDescriptor = spy(new VersionMonitor.DescriptorImpl());
113+
doReturn(false).when(mockDescriptor).isIgnored(); // Ensure isIgnored returns false
114+
115+
Computer computer = mock(Computer.class);
116+
VirtualChannel channel = mock(VirtualChannel.class);
117+
String differentVersion = "different-version"; // Different from Launcher.VERSION
118+
119+
// Set up the computer and channel behavior
120+
when(computer.getChannel()).thenReturn(channel);
121+
when(computer.getName()).thenReturn("test-computer");
122+
when(channel.call(ArgumentMatchers.<MasterToSlaveCallable<String, IOException>>any()))
123+
.thenReturn(differentVersion);
124+
125+
String result = mockDescriptor.monitor(computer);
126+
127+
assertEquals(differentVersion, result);
128+
129+
verify(computer).setTemporarilyOffline(eq(true), any(VersionMonitor.RemotingVersionMismatchCause.class));
130+
}
131+
110132
@Test
111133
public void testMonitor_VersionIsNull_Ignored() throws IOException, InterruptedException {
112134
VersionMonitor.DescriptorImpl mockDescriptor = spy(new VersionMonitor.DescriptorImpl());

0 commit comments

Comments
 (0)