package com.ankurm.testing;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class TempDirSetupTest {

    private Path tempDir;

    @BeforeEach
    void prepareFileSystem() throws IOException {
        tempDir = Files.createTempDirectory("junit_test_");
        System.out.println("LOG: Created temporary directory: " + tempDir.getFileName());
    }

    @AfterEach
    void removeTempDir() throws IOException {
        if (tempDir != null) Files.deleteIfExists(tempDir);
    }

    @Test
    void testFileWriteOperation() throws IOException {
        System.out.println("Running: testFileWriteOperation()");
        Path file = Files.writeString(tempDir.resolve("report.txt"), "hello");
        assertTrue(Files.exists(file));
        Files.delete(file);
    }
}
