Adds some tests, cleanup a bit
This commit is contained in:
@@ -6,6 +6,7 @@ import com.github.gtache.autosubtitle.process.ProcessResult;
|
||||
import com.github.gtache.autosubtitle.process.ProcessRunner;
|
||||
import com.github.gtache.autosubtitle.setup.SetupException;
|
||||
import com.github.gtache.autosubtitle.setup.SetupStatus;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -36,26 +37,30 @@ class TestCondaSetupManager {
|
||||
private final CondaSetupConfiguration configuration;
|
||||
private final ProcessRunner processRunner;
|
||||
private final HttpClient httpClient;
|
||||
private final HttpResponse<Path> response;
|
||||
private final CondaSetupManager condaSetupManager;
|
||||
private final ProcessResult systemProcessResult;
|
||||
private final Path systemPath;
|
||||
private final HttpResponse<Path> response;
|
||||
|
||||
TestCondaSetupManager(@Mock final CondaSetupConfiguration configuration, @Mock final ProcessRunner processRunner,
|
||||
@Mock final HttpClient httpClient, @Mock final ProcessResult systemProcessResult, @Mock final HttpResponse<Path> response) throws IOException, InterruptedException {
|
||||
this.configuration = requireNonNull(configuration);
|
||||
this.processRunner = requireNonNull(processRunner);
|
||||
this.httpClient = requireNonNull(httpClient);
|
||||
this.condaSetupManager = new CondaSetupManager(configuration, processRunner, httpClient);
|
||||
this.systemProcessResult = requireNonNull(systemProcessResult);
|
||||
this.systemPath = Paths.get("system");
|
||||
this.response = requireNonNull(response);
|
||||
when(response.statusCode()).thenReturn(200);
|
||||
this.condaSetupManager = new CondaSetupManager(configuration, processRunner, httpClient);
|
||||
this.systemPath = Paths.get("system");
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() throws IOException, InterruptedException {
|
||||
when(configuration.condaSystemPath()).thenReturn(systemPath);
|
||||
when(systemProcessResult.output()).thenReturn(List.of("conda 99.99.99"));
|
||||
when(systemProcessResult.exitCode()).thenReturn(0);
|
||||
when(processRunner.run(List.of(systemPath.toString(), "--version"), Duration.ofSeconds(5))).thenReturn(systemProcessResult);
|
||||
when(httpClient.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(response);
|
||||
when(response.statusCode()).thenReturn(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,10 +122,7 @@ class TestCondaSetupManager {
|
||||
when(processRunner.run(args, Duration.ofMinutes(15))).thenReturn(result);
|
||||
|
||||
assertDoesNotThrow(condaSetupManager::install);
|
||||
final var requestCapture = ArgumentCaptor.forClass(HttpRequest.class);
|
||||
verify(httpClient).send(requestCapture.capture(), any(HttpResponse.BodyHandler.class));
|
||||
final var request = requestCapture.getValue();
|
||||
assertEquals("https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe", request.uri().toString());
|
||||
checkURLRequested("https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe");
|
||||
verify(processRunner).run(args, Duration.ofMinutes(15));
|
||||
}
|
||||
|
||||
@@ -140,10 +142,7 @@ class TestCondaSetupManager {
|
||||
when(processRunner.run(args, Duration.ofMinutes(15))).thenReturn(result);
|
||||
|
||||
assertDoesNotThrow(condaSetupManager::install);
|
||||
final var requestCapture = ArgumentCaptor.forClass(HttpRequest.class);
|
||||
verify(httpClient).send(requestCapture.capture(), any(HttpResponse.BodyHandler.class));
|
||||
final var request = requestCapture.getValue();
|
||||
assertEquals("https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh", request.uri().toString());
|
||||
checkURLRequested("https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh");
|
||||
verify(processRunner).run(args, Duration.ofMinutes(15));
|
||||
}
|
||||
|
||||
@@ -163,10 +162,7 @@ class TestCondaSetupManager {
|
||||
when(processRunner.run(args, Duration.ofMinutes(15))).thenReturn(result);
|
||||
|
||||
assertDoesNotThrow(condaSetupManager::install);
|
||||
final var requestCapture = ArgumentCaptor.forClass(HttpRequest.class);
|
||||
verify(httpClient).send(requestCapture.capture(), any(HttpResponse.BodyHandler.class));
|
||||
final var request = requestCapture.getValue();
|
||||
assertEquals("https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh", request.uri().toString());
|
||||
checkURLRequested("https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh");
|
||||
verify(processRunner).run(args, Duration.ofMinutes(15));
|
||||
}
|
||||
|
||||
@@ -200,10 +196,7 @@ class TestCondaSetupManager {
|
||||
when(processRunner.run(args, Duration.ofMinutes(15))).thenReturn(result);
|
||||
|
||||
assertDoesNotThrow(condaSetupManager::install);
|
||||
final var requestCapture = ArgumentCaptor.forClass(HttpRequest.class);
|
||||
verify(httpClient).send(requestCapture.capture(), any(HttpResponse.BodyHandler.class));
|
||||
final var request = requestCapture.getValue();
|
||||
assertEquals("https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh", request.uri().toString());
|
||||
checkURLRequested("https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh");
|
||||
verify(processRunner).run(args, Duration.ofMinutes(15));
|
||||
}
|
||||
|
||||
@@ -223,10 +216,7 @@ class TestCondaSetupManager {
|
||||
when(processRunner.run(args, Duration.ofMinutes(15))).thenReturn(result);
|
||||
|
||||
assertDoesNotThrow(condaSetupManager::install);
|
||||
final var requestCapture = ArgumentCaptor.forClass(HttpRequest.class);
|
||||
verify(httpClient).send(requestCapture.capture(), any(HttpResponse.BodyHandler.class));
|
||||
final var request = requestCapture.getValue();
|
||||
assertEquals("https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh", request.uri().toString());
|
||||
checkURLRequested("https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh");
|
||||
verify(processRunner).run(args, Duration.ofMinutes(15));
|
||||
}
|
||||
|
||||
@@ -510,4 +500,11 @@ class TestCondaSetupManager {
|
||||
assertThrows(NullPointerException.class, () -> new CondaSetupManager(configuration, processRunner, null));
|
||||
}
|
||||
|
||||
private void checkURLRequested(final String url) throws IOException, InterruptedException {
|
||||
final var requestCapture = ArgumentCaptor.forClass(HttpRequest.class);
|
||||
verify(httpClient).send(requestCapture.capture(), any(HttpResponse.BodyHandler.class));
|
||||
final var request = requestCapture.getValue();
|
||||
assertEquals(url, request.uri().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user