FileOpener implements DangerousSupplier<InputStream> { @Override public InputStream get() throws IOException { return Files.newInputStream(path); }  @Override InputStream get();  }
@Test @PrepareForTest(FileOpener.class) public void testOpen() throws IOException { final byte[] content = randomUUID().toString().getBytes(); mockStatic(Files.class); ByteArrayInputStream inMock = new ByteArrayInputStream(content); Mockito.when(Files.newInputStream(any(Path.class))).thenReturn(inMock); final Path path = mock(Path.class); final FileOpener fileOpener = new FileOpener(path); try (final InputStream in = fileOpener.get()) { assertArrayEquals(content, from(in)); } }