/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You 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.
 */
/**
 * @author Anton Avtamonov
 * @version $Revision$
 */
package javax.swing.filechooser;

import java.io.File;

import javax.swing.SwingTestCase;

import org.apache.harmony.misc.SystemUtils;

public class FileSystemViewTest extends SwingTestCase {
    private FileSystemView view;
    private File file;

    public FileSystemViewTest(final String name) {
        super(name);
    }

    protected void setUp() throws Exception {
        super.setUp();
        timeoutDelay = 5 * DEFAULT_TIMEOUT_DELAY;

        view = FileSystemView.getFileSystemView();
        file = new File(new File(System.getProperty("user.home")), new Integer((int)(Math.random() * 1000)).toString());
        file.deleteOnExit();
    }

    protected void tearDown() throws Exception {
        view = null;
        file.delete();
        file = null;
    }

    public void testGetFileSystemView() throws Exception {
        assertNotNull(FileSystemView.getFileSystemView());
        assertEquals(FileSystemView.getFileSystemView(), FileSystemView.getFileSystemView());
    }

    public void testIsRoot() throws Exception {
        assertFalse(view.isRoot(file));
        if (SystemUtils.getOS() == SystemUtils.OS_WINDOWS) {
            assertTrue(view.getRoots().length == 1);
            assertTrue(view.getRoots()[0].getName().equals("Desktop"));
        } else if (SystemUtils.getOS() == SystemUtils.OS_LINUX) {
            assertTrue(view.getRoots().length == 1);
            assertTrue(view.getRoots()[0].getPath().equals("/"));
        }
    }

    public void testIsTraversable() throws Exception {
        assertFalse(view.isTraversable(file).booleanValue());
        file.createNewFile();
        assertTrue(file.isFile());
        assertFalse(view.isTraversable(file).booleanValue());
        file.delete();
        file.mkdir();
        assertTrue(view.isTraversable(file).booleanValue());
        file.delete();
    }

    public void testGetSystemDisplayName() throws Exception {
        assertEquals(file.getName(), view.getSystemDisplayName(file));
        file = new File("a.b");
        assertEquals(file.getName(), view.getSystemDisplayName(file));
        file = new File("/a/b");
        assertEquals(file.getName(), view.getSystemDisplayName(file));
        File f = File.listRoots()[0];
        assertNotSame(f.getName(), view.getSystemDisplayName(f));
    }

    public void testGetSystemTypeDescription() throws Exception {
        file.createNewFile();
        assertEquals("File", view.getSystemTypeDescription(file));

        file.delete();
        file.mkdir();
        if (SystemUtils.getOS() == SystemUtils.OS_WINDOWS) {
            assertEquals("File Folder", view.getSystemTypeDescription(file));
        } else {
            assertEquals("Folder", view.getSystemTypeDescription(file));
        }
    }

    public void testGetRoot() throws Exception {
         assertNotNull(File.listRoots());
         assertTrue(File.listRoots().length > 0);
         assertNotSame(File.listRoots(), File.listRoots());
    }

    public void testGetSystemIcon() throws Exception {
    }

    public void testCreateFileObject() throws Exception {
        File dir = new File(System.getProperty("user.home"));

        assertEquals(new File(dir, "!!!!!!!"), view.createFileObject(dir, "!!!!!!!"));
        assertEquals(new File(dir, "***"), view.createFileObject(dir, "***"));
        assertEquals(new File(dir, "/normal"), view.createFileObject(dir, "/normal"));
        assertEquals(new File(new File("any"), "/normal"), view.createFileObject(new File("any"), "/normal"));
        assertEquals(new File(new File("/"), "/normal"), view.createFileObject(new File("/"), "/normal"));
    }

    public void testGetChild() throws Exception {
        File parent = new File("a");
        assertEquals(new File("a", "b"), view.getChild(parent, "b"));
        assertEquals(new File("b"), view.getChild(null, "b"));
    }

    public void testGetDefaultDirectory() throws Exception {
        assertNotNull(view.getDefaultDirectory());
    }

    public void testGetHomeDirectory() throws Exception {
        assertNotNull(view.getHomeDirectory());
    }

    public void testGetFiles() throws Exception {
        File dir = new File("a");
        File f = new File(dir, "a");
        try {
            dir.mkdir();
            assertEquals(0, view.getFiles(dir, false).length);
            f.createNewFile();
            assertEquals(1, view.getFiles(dir, false).length);
            f.delete();
            assertEquals(0, view.getFiles(dir, false).length);
        } finally {
            f.delete();
            dir.delete();
        }
    }
}

@@ -2019,37 +2019,42 @@
           assert
-True(
+Equals(1, 
 view.getRoots().
@@ -2051,37 +2051,32 @@
 etRoots().length
- == 1
 );%0A            a
@@ -2072,36 +2072,40 @@
           assert
-True
+NotEmpty
 (view.getRoots()
@@ -2121,26 +2121,8 @@
 me()
-.equals(%22Desktop%22)
 );%0A 
@@ -2196,37 +2196,42 @@
           assert
-True(
+Equals(1, 
 view.getRoots().
@@ -2240,13 +2240,8 @@
 ngth
- == 1
 );%0A 
@@ -2253,29 +2253,36 @@
       assert
-True(
+Equals(%22/%22, 
 view.getRoot
@@ -2301,20 +2301,8 @@
 th()
-.equals(%22/%22)
 );%0A 
@@ -3262,23 +3262,17 @@
 sert
-Equals(%22File%22, 
+NotEmpty(
 view
@@ -3363,191 +3363,23 @@
     
-if (SystemUtils.getOS() == SystemUtils.OS_WINDOWS) %7B%0A            assertEquals(%22File Folder%22, view.getSystemTypeDescription(file));%0A        %7D else %7B%0A            assertEquals(%22Folder%22, 
+assertNotEmpty(
 view
@@ -3408,34 +3408,24 @@
 ion(file));%0A
-        %7D%0A
     %7D%0A%0A    p
@@ -5236,11 +5236,163 @@
  %7D%0A    %7D
+%0A%0A    private static void assertNotEmpty(final String name) %7B%0A        assertNotNull(name);%0A        assertTrue(%22name is empty%22, name.length() %3E 0);%0A    %7D
 %0A%7D%0A

Apply patch for HARMONY-1893 ([test][swing] j.s.filechooser.FileSystemViewTest contains locale-dependent tests)