/*
 * Copyright 2003-2012 Yusuke Yamamoto
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package samurai.util;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import samurai.swing.FileHistory;

import java.io.File;

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

class TestFileHistory {

    @BeforeEach
    void setUp() {
        String name = "samuraitest";
        String fileName = System.getProperty("user.home") + File.separator + "." +
                name + ".properties";
        //noinspection ResultOfMethodCallIgnored
        new File(fileName).delete();
    }

    @Test
    void testOpenFIFO() {
        String name = "samuraitest";
        Configuration configuration = new Configuration(name);
        configuration.setInt("RecentlyUsedNumber", 4);
        FileHistory history = new FileHistory(configuration);
        history.clearHistory();
//        history.enableCleaningOrphans();
        File file1 = new File("src/main/resources/samurai/swing/close_hover.gif");
        File file2 = new File("src/main/resources/samurai/swing/close_push.gif");
        File file3 = new File("src/main/resources/samurai/swing/close.gif");
        File file4 = new File("src/main/resources/samurai/swing/css.vm");
        File file5 = new File("src/main/resources/samurai/swing/default.properties");
        history.open(file1);
        history.open(file2);
        history.open(file3);
        history.open(file4);
        history.open(file5);
        assertEquals(5, history.getList().size());
        assertEquals(file5, history.getList().get(0));
        assertEquals(file4, history.getList().get(1));
        assertEquals(file3, history.getList().get(2));
        assertEquals(file2, history.getList().get(3));
        assertEquals(file1, history.getList().get(4));
    }

    @Test
    void testValidation() {
        Configuration configuration = new Configuration("samuraitest");
        configuration.setInt("RecentlyUsedNumber", 4);
        FileHistory history = new FileHistory(configuration);
        history.clearHistory();
        history.enableCleaningOrphans();
        File file1 = new File("src/main/resources/samurai/swing/close_hover.gif");
        File file2 = new File("src/main/resources/samurai/swing/close_push.gif");
        File file3 = new File("src/main/resources/samurai/swing/close.gif");
        File doesnotExist1 = new File("foobarfoobar");
        File file4 = new File("testcases/Sun/1.4.2_03Sunstacked.dmp");
        File doesnotExist2 = new File("foobarfoobarbar");
        File directory1 = new File("classes");
        File directory2 = new File("src");
        File file5 = new File("src/main/resources/samurai/swing/default.properties");
        history.open(file1);
        history.open(file2);
        history.open(directory1);
        history.open(file3);
        history.open(directory2);
        history.open(file4);
        history.open(file5);
        history.open(doesnotExist2);
        history.open(doesnotExist1);
        assertEquals(4, history.getList().size());
        assertEquals(file5, history.getList().get(0));
        assertEquals(file3, history.getList().get(1));
        assertEquals(file2, history.getList().get(2));
        assertEquals(file1, history.getList().get(3));
    }
}


@@ -2628,32 +2628,116 @@
 aningOrphans();%0A
+        String base = new File(%22%22).getAbsolutePath().endsWith(%22gui%22) ? %22%22 : %22gui/%22;%0A
         File fil
@@ -2742,32 +2742,39 @@
 ile1 = new File(
+base + 
 %22src/main/resour
@@ -2783,32 +2783,39 @@
 s/samurai/swing/
+images/
 close_hover.gif%22
@@ -2839,32 +2839,39 @@
 ile2 = new File(
+base + 
 %22src/main/resour
@@ -2880,32 +2880,39 @@
 s/samurai/swing/
+images/
 close_push.gif%22)
@@ -2935,32 +2935,39 @@
 ile3 = new File(
+base + 
 %22src/main/resour
@@ -2976,32 +2976,39 @@
 s/samurai/swing/
+images/
 close.gif%22);%0A   
@@ -3034,32 +3034,39 @@
 ist1 = new File(
+base + 
 %22foobarfoobar%22);
@@ -3100,45 +3100,57 @@
 ile(
-%22testcases/Sun/1.4.2_03Sunstacked.dmp
+ %22src/test/java/samurai/util/TestFileHistory.java
 %22);%0A
@@ -3187,16 +3187,23 @@
 ew File(
+base + 
 %22foobarf
@@ -3249,16 +3249,23 @@
 ew File(
+base + 
 %22classes
@@ -3299,24 +3299,31 @@
  = new File(
+base + 
 %22src%22);%0A    
@@ -3340,32 +3340,39 @@
 ile5 = new File(
+base + 
 %22src/main/resour
@@ -3375,37 +3375,36 @@
 sources/samurai/
-swing
+util
 /default.propert

fix outdated testcase