문제

I have an application that allow me to upload files using a addFile() method.

How should a jUnit test that check if a hidden file can be added look like?

I know that may look a bit stupid question, but I couldn't find any examples for this.

도움이 되었습니까?

해결책

This answer is based on the comments above.

Sample code snippet to test if the file is accessible (use your own logic here)

public class PathTest {

    public boolean pathAccessible(String path) {
        File file = new File(path);
        if (!file.isDirectory())
               file = file.getParentFile();
        return file.exists();

    }

}

Sample Junit test case (Assuming you have Junit setup properly)

public void test()
    {
        PathTest test = new PathTest();
        assertTrue(test.pathAccessible("regular file path"));
        assertFalse(test.pathAccessible("hidden file path"));

    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top