package de.retest.recheck.util;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class DeleteOnCloseFileInputStreamTest {

	@Rule
	public TemporaryFolder tempFolder = new TemporaryFolder();

	@Test
	public void file_should_be_deleted_on_close() throws IOException {
		final File file = tempFolder.newFile();
		final InputStream in = new DeleteOnCloseFileInputStream( file );

		in.close();

		assertThat( file ).doesNotExist();
	}

}

package de.retest.recheck.util;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class DeleteOnCloseFileInputStreamTest {

	@Test
	void file_should_be_deleted_on_close( @TempDir final Path temp ) throws IOException {
		final Path file = temp.resolve( "foo" );
		Files.createFile( file );
		final InputStream in = new DeleteOnCloseFileInputStream( file.toFile() );

		in.close();

		assertThat( file ).doesNotExist();
	}

}

Migrate to JUnit 5