Adds tests for API

This commit is contained in:
Guillaume Tâche
2024-08-09 21:18:47 +02:00
parent 155b011c2b
commit 428edcd806
17 changed files with 515 additions and 41 deletions

View File

@@ -0,0 +1,37 @@
package com.github.gtache.autosubtitle;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class TestFile {
private final File file;
TestFile(@Mock final File file) {
this.file = Objects.requireNonNull(file);
}
@Test
void testGetInputStream(@TempDir final Path dir) throws IOException {
final var path = dir.resolve("path");
Files.writeString(path, "test");
when(file.getInputStream()).thenCallRealMethod();
when(file.path()).thenReturn(path);
try (final var in = file.getInputStream()) {
assertEquals("test", new String(in.readAllBytes()));
}
}
}