package com.eactive.eai.rms.onl.common.util;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

import java.io.File;

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

public class FileSystemUtilTest {

    @Test
    @EnabledOnOs(OS.LINUX)
    void testPathNormalize_Linux() {
        assertEquals("/asd1/asd2/asd3", FileSystemUtil.pathNormalize("/asd1/asd2", "asd3"));
        assertEquals("/asd1/asd2/asd3", FileSystemUtil.pathNormalize("/asd1/asd2/", "/asd3"));
        assertEquals("/asd1/asd2/asd3", FileSystemUtil.pathNormalize("/asd1/asd2", "/asd3"));
        assertEquals("/asd1/asd2/asd3", FileSystemUtil.pathNormalize("/asd1/asd2/", "asd3/"));
        assertEquals("/a/b/c", FileSystemUtil.pathNormalize("/a/", "/b/", "/c/"));
        assertEquals("a/b/c", FileSystemUtil.pathNormalize("a", "b", "c"));
        assertEquals("/a", FileSystemUtil.pathNormalize("/a"));
    }

    @Test
    @EnabledOnOs(OS.WINDOWS)
    void testPathNormalize_Windows() {
        assertEquals("\\asd1\\asd2\\asd3", FileSystemUtil.pathNormalize("/asd1/asd2", "asd3"));
        assertEquals("\\asd1\\asd2\\asd3", FileSystemUtil.pathNormalize("/asd1/asd2/", "/asd3"));
        assertEquals("\\asd1\\asd2\\asd3", FileSystemUtil.pathNormalize("/asd1/asd2", "/asd3"));
        assertEquals("\\asd1\\asd2\\asd3", FileSystemUtil.pathNormalize("/asd1/asd2/", "asd3/"));
        assertEquals("C:\\Users\\Test", FileSystemUtil.pathNormalize("C:/Users", "Test"));
        assertEquals("C:\\Users\\Test", FileSystemUtil.pathNormalize("C:\\Users", "Test"));
        assertEquals("\\a\\b\\c", FileSystemUtil.pathNormalize("/a/", "/b/", "/c/"));
        assertEquals("a\\b\\c", FileSystemUtil.pathNormalize("a", "b", "c"));
        assertEquals("\\a", FileSystemUtil.pathNormalize("/a"));
    }

    @Test
    void testPathNormalize_General() {
        String expected = "a" + File.separator + "b" + File.separator + "c";
        assertEquals(expected, FileSystemUtil.pathNormalize("a", "b", "c"));
        assertEquals("", FileSystemUtil.pathNormalize(""));
        assertEquals("", FileSystemUtil.pathNormalize(null));
        assertEquals("", FileSystemUtil.pathNormalize());
        assertEquals("a", FileSystemUtil.pathNormalize("a"));
        assertEquals("a", FileSystemUtil.pathNormalize("a/"));
        assertEquals("a", FileSystemUtil.pathNormalize("/a"));
    }
}
