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())); } } }