diff --git a/.travis.yml b/.travis.yml index 57489a6..b51c64c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,4 +21,4 @@ before_install: # - emulator -avd test -no-skin -no-audio -no-window & script: - - ./gradlew build + - ./gradlew clean build check diff --git a/library/build.gradle b/library/build.gradle index bc33f4b..1a84417 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -20,6 +20,8 @@ dependencies { compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.android.support:support-v4:22.2.0' compile 'com.android.support:recyclerview-v7:22.1.1' + + testCompile 'junit:junit:4.12' } publish { diff --git a/library/src/test/java/com/nononsenseapps/filepicker/FilePickerFragmentTest.java b/library/src/test/java/com/nononsenseapps/filepicker/FilePickerFragmentTest.java new file mode 100644 index 0000000..53910ff --- /dev/null +++ b/library/src/test/java/com/nononsenseapps/filepicker/FilePickerFragmentTest.java @@ -0,0 +1,70 @@ +package com.nononsenseapps.filepicker; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.*; + + +public class FilePickerFragmentTest { + + private static FilePickerFragment fragment; + private static File somePath; + private static String someName; + + @BeforeClass + public static void runBeforeClass() { + // Runs ONCE, before all tests + fragment = new FilePickerFragment(); + someName = "FileName"; + somePath = new File("/path/to/some/" + someName); + } + + @AfterClass + public static void runAfterClass() { + } + + @Test + public void testGetName() throws Exception { + assertEquals(someName, fragment.getName(somePath)); + } + + @Test + public void testGetParent() throws Exception { + assertEquals("/path/to/some", fragment.getParent(somePath).getPath()); + + // Self + assertEquals(fragment.getRoot().getPath(), fragment.getParent(new File("/path")).getPath()); + assertEquals(fragment.getRoot().getPath(), fragment.getParent(new File("/")).getPath()); + } + + @Test + public void testGetPath() throws Exception { + assertEquals("/some/path", fragment.getPath("/some/path").getPath()); + } + + @Test + public void testGetFullPath() throws Exception { + assertEquals("/some/path", fragment.getFullPath(new File("/some/path"))); + } + + @Test + public void testGetRoot() throws Exception { + assertEquals("/", fragment.getRoot().getPath()); + } + + @Test + public void testCompareFiles() throws Exception { + assertEquals(0, fragment.compareFiles(new File("/A/A"), new File("/A/A"))); + assertEquals(-1, fragment.compareFiles(new File("/A/A"), new File("/A/B"))); + assertEquals(1, fragment.compareFiles(new File("/A/B"), new File("/A/A"))); + + // Dir is assumed to be the same + assertEquals(1, fragment.compareFiles(new File("/A/B"), new File("/B/A"))); + assertEquals(-1, fragment.compareFiles(new File("/B/A"), new File("/A/B"))); + assertEquals(0, fragment.compareFiles(new File("/A/B"), new File("/B/B"))); + } +} \ No newline at end of file