package de.antco.projekt.exporters;

import de.antco.projekt.model.Person;
import org.junit.jupiter.api.Test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;

class CsvPersonExporterTest {

    @Test
    void testExport() throws Exception {
        File tempFile = File.createTempFile("export_test", ".csv");
        tempFile.deleteOnExit();

        List<Person> persons = Arrays.asList(
            new Person(1, "Max", "123", "max@mail.de", "Weg 1"),
            new Person(2, "Moritz", "456", "moritz@mail.de", "Weg 2")
        );

        CsvPersonExporter exporter = new CsvPersonExporter();
        exporter.exportData(persons, tempFile.getAbsolutePath());

        try (BufferedReader br = new BufferedReader(new FileReader(tempFile))) {
            assertEquals("Max;123;max@mail.de;Weg 1", br.readLine());
            assertEquals("Moritz;456;moritz@mail.de;Weg 2", br.readLine());
            assertNull(br.readLine());
        }
    }
}
