mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-12-01 12:31:45 +00:00
Added test for FilenameGenerator
This commit is contained in:
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user