Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Sep 11, 2024
1 parent 7bc52c4 commit 22afcb3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/test/java/io/jenkins/plugins/jfrog/JfStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.util.ArgumentListBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -51,13 +52,17 @@ void isCliVersionGreaterThanTest() {

@Test
void getJfrogCliVersionTest() throws IOException, InterruptedException {
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
// Mock the Launcher
Launcher launcher = mock(Launcher.class);
// Mock the Launcher.ProcStarter
Launcher.ProcStarter procStarter = mock(Launcher.ProcStarter.class);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Mocks the return value of --version command
outputStream.write("jf version 2.31.0 ".getBytes());
// Mock the behavior of the ProcStarter
when(procStarter.cmds("jf", "--version")).thenReturn(procStarter);
// Mock the behavior of the Launcher and ProcStarter
when(launcher.launch()).thenReturn(procStarter);
when(procStarter.cmds(any(ArgumentListBuilder.class))).thenReturn(procStarter);
when(procStarter.pwd((FilePath) any())).thenReturn(procStarter);
when(procStarter.stdout(any(ByteArrayOutputStream.class))).thenAnswer(invocation -> {
ByteArrayOutputStream out = invocation.getArgument(0);
Expand All @@ -68,7 +73,7 @@ void getJfrogCliVersionTest() throws IOException, InterruptedException {

// Create an instance of JfStep and call the method
JfStep jfStep = new JfStep("--version");
String version = jfStep.getJfrogCliVersion(procStarter, getJFrogCLIPath(new EnvVars(),false));
String version = jfStep.getJfrogCliVersion(procStarter, JfStep.getJFrogCLIPath(new EnvVars(), isWindows));

// Verify the result
assertEquals("2.31.0", version);
Expand Down

0 comments on commit 22afcb3

Please sign in to comment.