blob: 90b1224a7518b57958e5bd73046656c45b01521c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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();
}
}
|