package deadbeef.utils;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class FilenameUtilsTest {

    private final String unixFilename = "/home/user/someFile.txt";
    private final String winFilename = "C:\\Windows\\someFile.txt";

    @Test
    public void shouldGetExtension() throws Exception {
        assertEquals("txt", FilenameUtils.getExtension(unixFilename));
        assertEquals("txt", FilenameUtils.getExtension(winFilename));
    }

    @Test
    public void shouldReturnEmptyStringIfNoExtensionFound() throws Exception {
        assertEquals("", FilenameUtils.getExtension("someFile"));
        assertEquals("", FilenameUtils.getExtension("../someFile"));
    }

    @Test
    public void shouldRemoveExtension() throws Exception {
        assertEquals("/home/user/someFile", FilenameUtils.removeExtension(unixFilename));
        assertEquals("C:\\Windows\\someFile", FilenameUtils.removeExtension(winFilename));
    }

    @Test
    public void shouldReturnTheOriginalStringIfNoExtensionFound() throws Exception {
        assertEquals("/home/user/someFile", FilenameUtils.removeExtension("/home/user/someFile"));
        assertEquals("C:\\Windows\\someFile", FilenameUtils.removeExtension("C:\\Windows\\someFile"));
    }

    @Test
    public void shouldGetName() throws Exception {
        assertEquals("someFile.txt", FilenameUtils.getName(unixFilename));
    }

    @Test
    public void shouldGetPath() throws Exception {
        assertEquals("/home/user", FilenameUtils.getParent(unixFilename));
    }

    @Test
    public void shouldChangeWindowsSeparatorsToUnix() throws Exception {
        assertEquals("/foo/bar.jar", FilenameUtils.separatorsToUnix("\\foo\\bar.jar"));
    }

    @Test
    public void shouldMakeSurePathEndsWithASeparator() throws Exception {
        assertEquals("/home/", FilenameUtils.addSeparator("/home"));
        assertEquals("/home/", FilenameUtils.addSeparator("/home/"));
    }
}

@@ -42,16 +42,38 @@
 .Test;%0A%0A
+import java.io.File;%0A%0A
 import s
@@ -160,56 +160,216 @@
 ate 
-final String unixFilename = %22/home/user/
+static final char SEPARATOR_CHAR = File.separatorChar;%0A    private static final String PARENT_DIR_PATH = SEPARATOR_CHAR + %22home%22 + SEPARATOR_CHAR + %22user%22;%0A    private static final String BASENAME = %22
 someFile
 .txt
@@ -364,20 +364,16 @@
 someFile
-.txt
 %22;%0A    p
@@ -379,16 +379,23 @@
 private 
+static 
 final St
@@ -403,49 +403,194 @@
 ing 
-winFilename = %22C:%5C%5CWindows%5C%5CsomeFile.txt%22
+EXTENSION = %22txt%22;%0A    private static final String FILENAME = BASENAME + %22.%22 + EXTENSION;%0A    private static final String FILENAME_FULL_PATH = PARENT_DIR_PATH + SEPARATOR_CHAR + FILENAME
 ;%0A%0A 
@@ -667,37 +667,41 @@
    assertEquals(
-%22txt%22
+EXTENSION
 , FilenameUtils.
@@ -717,90 +717,26 @@
 ion(
-unixFilename));%0A        assertEquals(%22txt%22, FilenameUtils.getExtension(winFilename
+FILENAME_FULL_PATH
 ));%0A
@@ -883,26 +883,24 @@
 tension(
-%22someFile%22
+BASENAME
 ));%0A    
@@ -950,26 +950,45 @@
 sion(%22..
-/someFile%22
+%22 + SEPARATOR_CHAR + BASENAME
 ));%0A    
@@ -1084,121 +1084,51 @@
 als(
-%22/home/user/someFile%22, FilenameUtils.removeExtension(unixFilename));%0A        assertEquals(%22C:%5C%5CWindows%5C%5CsomeFile%22
+PARENT_DIR_PATH + SEPARATOR_CHAR + BASENAME
 , Fi
@@ -1159,19 +1159,26 @@
 ion(
-winFilename
+FILENAME_FULL_PATH
 ));%0A
@@ -1574,22 +1574,16 @@
 als(
-%22someFile.txt%22
+FILENAME
 , Fi
@@ -1602,28 +1602,34 @@
 getName(
-unixFilename
+FILENAME_FULL_PATH
 ));%0A    
@@ -1717,20 +1717,23 @@
 als(
-%22/home/user%22
+PARENT_DIR_PATH
 , Fi
@@ -1758,20 +1758,26 @@
 ent(
-unixFilename
+FILENAME_FULL_PATH
 ));%0A
@@ -2062,32 +2062,56 @@
 ssertEquals(
-%22/home/%22
+PARENT_DIR_PATH + SEPARATOR_CHAR
 , FilenameUt
@@ -2131,15 +2131,23 @@
 tor(
-%22/home%22
+PARENT_DIR_PATH
 ));%0A
@@ -2171,53 +2171,101 @@
 als(
-%22/home/%22, FilenameUtils.addSeparator(%22/home/%22
+PARENT_DIR_PATH + SEPARATOR_CHAR, FilenameUtils.addSeparator(PARENT_DIR_PATH + SEPARATOR_CHAR
 ));%0A

Make unit test work in Windows environment.