Added test for FilenameGenerator

This commit is contained in:
daniel oeh 2012-11-01 19:16:32 +01:00
parent 0f857e6a3b
commit a0eabe5555
1 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,48 @@
package de.danoeh.antennapod.test;
import java.io.File;
import java.io.IOException;
import de.danoeh.antennapod.util.FileNameGenerator;
import android.test.AndroidTestCase;
public class FilenameGeneratorTest extends AndroidTestCase {
private static final String VALID1 = "abc abc";
private static final String INVALID1 = "ab/c: <abc";
public void testGenerateFileName() throws IOException {
String result = FileNameGenerator.generateFileName(VALID1);
assertEquals(result, VALID1);
createFiles(result);
}
public void testGenerateFileName1() throws IOException {
String result = FileNameGenerator.generateFileName(INVALID1);
assertEquals(result, VALID1);
createFiles(result);
}
/**
* Tests if files can be created.
*
* @throws IOException
*/
private void createFiles(String name) throws IOException {
File cache = getContext().getExternalCacheDir();
File testFile = new File(cache, name);
testFile.mkdir();
assertTrue(testFile.exists());
testFile.delete();
assertTrue(testFile.createNewFile());
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
File f = new File(getContext().getExternalCacheDir(), VALID1);
f.delete();
}
}