Add some basic unit tests

And update travis to run them
This commit is contained in:
Jonas Kalderstam 2015-06-01 18:49:37 +02:00
parent 81a9a5cf31
commit 60a971cb76
3 changed files with 73 additions and 1 deletions

View File

@ -21,4 +21,4 @@ before_install:
# - emulator -avd test -no-skin -no-audio -no-window &
script:
- ./gradlew build
- ./gradlew clean build check

View File

@ -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 {

View File

@ -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")));
}
}