Fixed filename generator test

This commit is contained in:
ByteHamster 2019-10-20 22:09:07 +02:00
parent 381732c582
commit 3c8a650e5b
1 changed files with 57 additions and 55 deletions

View File

@ -1,7 +1,7 @@
package de.test.antennapod.util; package de.test.antennapod.util;
import androidx.test.InstrumentationRegistry; import android.content.Context;
import androidx.test.filters.LargeTest; import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import android.text.TextUtils; import android.text.TextUtils;
@ -13,6 +13,7 @@ import org.junit.After;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@SmallTest @SmallTest
@ -62,7 +63,7 @@ public class FilenameGeneratorTest {
@Test @Test
public void testInvalidInput() { public void testInvalidInput() {
String result = FileNameGenerator.generateFileName("???"); String result = FileNameGenerator.generateFileName("???");
assertTrue(!TextUtils.isEmpty(result)); assertFalse(TextUtils.isEmpty(result));
} }
/** /**
@ -71,7 +72,7 @@ public class FilenameGeneratorTest {
* @throws IOException * @throws IOException
*/ */
private void createFiles(String name) throws IOException { private void createFiles(String name) throws IOException {
File cache = InstrumentationRegistry.getContext().getExternalCacheDir(); File cache = InstrumentationRegistry.getInstrumentation().getTargetContext().getExternalCacheDir();
File testFile = new File(cache, name); File testFile = new File(cache, name);
testFile.mkdir(); testFile.mkdir();
assertTrue(testFile.exists()); assertTrue(testFile.exists());
@ -81,8 +82,9 @@ public class FilenameGeneratorTest {
} }
@After @After
public void tearDown() throws Exception { public void tearDown() {
File f = new File(InstrumentationRegistry.getContext().getExternalCacheDir(), VALID1); Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
File f = new File(context.getExternalCacheDir(), VALID1);
f.delete(); f.delete();
} }