Adds some tests, cleanup a bit

This commit is contained in:
Guillaume Tâche
2024-09-20 08:36:52 +02:00
parent 17086a87ef
commit 703a4c71ae
47 changed files with 1122 additions and 182 deletions

View File

@@ -4,6 +4,7 @@ import com.github.gtache.autosubtitle.impl.OS;
import com.github.gtache.autosubtitle.process.ProcessRunner;
import com.github.gtache.autosubtitle.setup.SetupException;
import com.github.gtache.autosubtitle.setup.conda.CondaSetupManager;
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;
@@ -34,13 +35,17 @@ class TestAbstractWhisperSetupManager {
TestAbstractWhisperSetupManager(@Mock final CondaSetupManager condaSetupManager, @Mock final WhisperSetupConfiguration configuration,
@Mock final ProcessRunner processRunner, @Mock final HttpClient httpClient) {
this.condaSetupManager = Objects.requireNonNull(condaSetupManager);
when(condaSetupManager.name()).thenReturn("conda");
this.configuration = Objects.requireNonNull(configuration);
this.processRunner = Objects.requireNonNull(processRunner);
this.httpClient = Objects.requireNonNull(httpClient);
this.setupManager = spy(new DummyWhisperSetupManager(condaSetupManager, configuration, processRunner, httpClient));
}
@BeforeEach
void beforeEach() {
when(condaSetupManager.name()).thenReturn("conda");
}
@Test
void testGetStatus() throws SetupException {
assertEquals(NOT_INSTALLED, setupManager.getStatus());
@@ -155,11 +160,11 @@ class TestAbstractWhisperSetupManager {
}
@Override
protected void installWhisper() throws SetupException {
protected void installWhisper() {
}
@Override
protected boolean isWhisperInstalled() throws SetupException {
protected boolean isWhisperInstalled() {
return false;
}

View File

@@ -19,17 +19,18 @@ class TestWhisperSetupConfiguration {
private final Path venvPath;
private final String pythonVersion;
private final OS os;
private final WhisperSetupConfiguration configuration;
TestWhisperSetupConfiguration(@Mock final Path root, @Mock final Path venvPath) {
this.root = Objects.requireNonNull(root);
this.venvPath = Objects.requireNonNull(venvPath);
this.pythonVersion = "3.10";
this.os = OS.LINUX;
this.configuration = new WhisperSetupConfiguration(root, venvPath, pythonVersion, os);
}
@Test
void testGetters() {
final var configuration = new WhisperSetupConfiguration(root, venvPath, pythonVersion, os);
assertEquals(root, configuration.root());
assertEquals(venvPath, configuration.venvPath());
assertEquals(pythonVersion, configuration.pythonVersion());

View File

@@ -20,6 +20,7 @@ import com.github.gtache.autosubtitle.subtitle.extractor.ExtractException;
import com.github.gtache.autosubtitle.subtitle.extractor.ExtractionModel;
import com.github.gtache.autosubtitle.subtitle.extractor.SubtitleExtractorListener;
import com.github.gtache.autosubtitle.subtitle.extractor.impl.ExtractEventImpl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -47,7 +48,7 @@ class TestAbstractWhisperSubtitleExtractor {
private final ProcessListener processListener;
private final ProcessResult processResult;
private final OS os;
private final DummyWhisperSubtitleExtractor extractor;
private DummyWhisperSubtitleExtractor extractor;
private final AudioInfo audioInfo;
private final VideoInfo videoInfo;
@@ -59,27 +60,30 @@ class TestAbstractWhisperSubtitleExtractor {
@Mock final ProcessRunner processRunner, @Mock final ProcessListener processListener,
@Mock final ProcessResult processResult, @Mock final VideoInfo videoInfo,
@Mock final AudioInfo audioInfo, @Mock final ExtractionModel extractionModel,
@Mock final SubtitleCollection<Subtitle> collection) throws IOException {
@Mock final SubtitleCollection<Subtitle> collection) {
this.venvPath = Path.of("venv");
this.os = OS.LINUX;
this.converterProvider = Objects.requireNonNull(converterProvider);
this.converter = Objects.requireNonNull(converter);
doReturn(converter).when(converterProvider).getConverter("json");
this.processRunner = Objects.requireNonNull(processRunner);
this.processListener = Objects.requireNonNull(processListener);
this.processResult = Objects.requireNonNull(processResult);
when(processRunner.startListen(anyList())).thenReturn(processListener);
when(processListener.join(Duration.ofHours(1))).thenReturn(processResult);
this.extractor = new DummyWhisperSubtitleExtractor(venvPath, converterProvider, processRunner, os);
this.audioInfo = Objects.requireNonNull(audioInfo);
when(audioInfo.format()).thenReturn("mp3");
this.videoInfo = Objects.requireNonNull(videoInfo);
when(videoInfo.format()).thenReturn("mp4");
this.extractionModel = Objects.requireNonNull(extractionModel);
this.collection = Objects.requireNonNull(collection);
}
@BeforeEach
void beforeEach() throws IOException {
doReturn(converter).when(converterProvider).getConverter("json");
when(processRunner.startListen(anyList())).thenReturn(processListener);
when(processListener.join(Duration.ofHours(1))).thenReturn(processResult);
when(audioInfo.format()).thenReturn("mp3");
when(videoInfo.format()).thenReturn("mp4");
this.extractor = new DummyWhisperSubtitleExtractor(venvPath, converterProvider, processRunner, os);
}
@Test
void testNotifyListeners() {
final var listener1 = mock(SubtitleExtractorListener.class);