Adds tests for FFmpeg
This commit is contained in:
@@ -33,6 +33,10 @@ public record AudioOrVideo(Audio audio, Video video) implements Audio {
|
||||
this(null, video);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param <T> The type of the inner object
|
||||
* @return The inner object (audio or video)
|
||||
*/
|
||||
public <T> T inner() {
|
||||
return (T) (audio == null ? video : audio);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.github.gtache.autosubtitle.subtitle.extractor.whisper;
|
||||
|
||||
import com.github.gtache.autosubtitle.Audio;
|
||||
import com.github.gtache.autosubtitle.AudioInfo;
|
||||
import com.github.gtache.autosubtitle.Video;
|
||||
import com.github.gtache.autosubtitle.VideoInfo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TestAudioOrVideo {
|
||||
|
||||
private final Audio audio;
|
||||
private final Video video;
|
||||
private final InputStream in;
|
||||
|
||||
|
||||
TestAudioOrVideo(@Mock final Audio audio, @Mock final Video video, @Mock final InputStream in) {
|
||||
this.audio = Objects.requireNonNull(audio);
|
||||
this.video = Objects.requireNonNull(video);
|
||||
this.in = Objects.requireNonNull(in);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAudio() throws IOException {
|
||||
final var audioOrVideo = new AudioOrVideo(audio);
|
||||
when(audio.getInputStream()).thenReturn(in);
|
||||
assertEquals(in, audioOrVideo.getInputStream());
|
||||
final var info = mock(AudioInfo.class);
|
||||
when(audio.info()).thenReturn(info);
|
||||
|
||||
assertEquals(info, audioOrVideo.info());
|
||||
assertEquals(audio, audioOrVideo.inner());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVideo() throws IOException {
|
||||
final var audioOrVideo = new AudioOrVideo(video);
|
||||
when(video.getInputStream()).thenReturn(in);
|
||||
assertEquals(in, audioOrVideo.getInputStream());
|
||||
final var info = mock(VideoInfo.class);
|
||||
when(video.info()).thenReturn(info);
|
||||
|
||||
assertEquals(info, audioOrVideo.info());
|
||||
assertEquals(video, audioOrVideo.inner());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIllegal() {
|
||||
assertThrows(NullPointerException.class, () -> new AudioOrVideo((Audio) null));
|
||||
assertThrows(NullPointerException.class, () -> new AudioOrVideo((Video) null));
|
||||
assertThrows(NullPointerException.class, () -> new AudioOrVideo(null, null));
|
||||
assertThrows(IllegalArgumentException.class, () -> new AudioOrVideo(audio, video));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user