Merge pull request #8 from AntennaPod/develop

update me
This commit is contained in:
Burt Snyder 2020-07-07 10:44:29 -04:00 committed by GitHub
commit 06f36d12d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 18 deletions

View File

@ -21,32 +21,28 @@ import static org.junit.Assert.assertTrue;
@SmallTest @SmallTest
public class FilenameGeneratorTest { public class FilenameGeneratorTest {
private static final String VALID1 = "abc abc";
private static final String INVALID1 = "ab/c: <abc";
private static final String INVALID2 = "abc abc ";
public FilenameGeneratorTest() { public FilenameGeneratorTest() {
super(); super();
} }
@Test @Test
public void testGenerateFileName() throws IOException { public void testGenerateFileName() throws IOException {
String result = FileNameGenerator.generateFileName(VALID1); String result = FileNameGenerator.generateFileName("abc abc");
assertEquals(result, VALID1); assertEquals(result, "abc abc");
createFiles(result); createFiles(result);
} }
@Test @Test
public void testGenerateFileName1() throws IOException { public void testGenerateFileName1() throws IOException {
String result = FileNameGenerator.generateFileName(INVALID1); String result = FileNameGenerator.generateFileName("ab/c: <abc");
assertEquals(result, VALID1); assertEquals(result, "abc abc");
createFiles(result); createFiles(result);
} }
@Test @Test
public void testGenerateFileName2() throws IOException { public void testGenerateFileName2() throws IOException {
String result = FileNameGenerator.generateFileName(INVALID2); String result = FileNameGenerator.generateFileName("abc abc ");
assertEquals(result, VALID1); assertEquals(result, "abc abc");
createFiles(result); createFiles(result);
} }
@ -62,6 +58,12 @@ public class FilenameGeneratorTest {
assertEquals("Left - Right", result); assertEquals("Left - Right", result);
} }
@Test
public void testFeedTitleContainsAccents() {
String result = FileNameGenerator.generateFileName("Äàáâãå");
assertEquals("Aaaaaa", result);
}
@Test @Test
public void testInvalidInput() { public void testInvalidInput() {
String result = FileNameGenerator.generateFileName("???"); String result = FileNameGenerator.generateFileName("???");
@ -97,14 +99,6 @@ public class FilenameGeneratorTest {
assertTrue(testFile.exists()); assertTrue(testFile.exists());
testFile.delete(); testFile.delete();
assertTrue(testFile.createNewFile()); assertTrue(testFile.createNewFile());
}
@After
public void tearDown() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
File f = new File(context.getExternalCacheDir(), VALID1);
f.delete();
} }
} }

View File

@ -4,6 +4,7 @@ import android.text.TextUtils;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -29,6 +30,7 @@ public class FileNameGenerator {
* characters of the given string. * characters of the given string.
*/ */
public static String generateFileName(String string) { public static String generateFileName(String string) {
string = StringUtils.stripAccents(string);
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
for (int i = 0; i < string.length(); i++) { for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i); char c = string.charAt(i);