blob: a36b3b65a6c1251bdf5627a57f17590065d50adc (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package de.test.antennapod.util;
import android.test.AndroidTestCase;
import android.text.TextUtils;
import java.io.File;
import java.io.IOException;
import de.danoeh.antennapod.core.util.FileNameGenerator;
public class FilenameGeneratorTest extends AndroidTestCase {
private static final String VALID1 = "abc abc";
private static final String INVALID1 = "ab/c: <abc";
private static final String INVALID2 = "abc abc ";
public FilenameGeneratorTest() {
super();
}
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);
}
public void testGenerateFileName2() throws IOException {
String result = FileNameGenerator.generateFileName(INVALID2);
assertEquals(result, VALID1);
createFiles(result);
}
public void testFeedTitleContainsApostrophe() {
String result = FileNameGenerator.generateFileName("Feed's Title ...");
assertEquals("Feeds Title", result);
}
public void testFeedTitleContainsDash() {
String result = FileNameGenerator.generateFileName("Left - Right");
assertEquals("Left - Right", result);
}
public void testInvalidInput() {
String result = FileNameGenerator.generateFileName("???");
assertTrue(!TextUtils.isEmpty(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();
}
}
|