mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 07:39:53 +01:00
Simplify code.
This commit is contained in:
@@ -28,19 +28,11 @@ abstract class AbstractAttachmentCreationTaskTest {
|
|||||||
|
|
||||||
void testCompress(String filename, String contentType)
|
void testCompress(String filename, String contentType)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
InputStream is = getAssetInputStream(filename);
|
InputStream is = getAssetManager().open(filename);
|
||||||
task.compressImage(is, contentType);
|
task.compressImage(is, contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getAssetInputStream(String name) throws IOException {
|
static AssetManager getAssetManager() {
|
||||||
return getAssetManager().open(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static String[] getAssetFiles(String path) throws IOException {
|
|
||||||
return getAssetManager().list(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AssetManager getAssetManager() {
|
|
||||||
// pm.getResourcesForApplication(packageName).getAssets() did not work
|
// pm.getResourcesForApplication(packageName).getAssets() did not work
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
return getContext().getAssets();
|
return getContext().getAssets();
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package org.briarproject.briar.android.attachment;
|
package org.briarproject.briar.android.attachment;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.Pair;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
@@ -17,36 +16,27 @@ public class PngSuiteAttachmentCreationTaskTest
|
|||||||
extends AbstractAttachmentCreationTaskTest {
|
extends AbstractAttachmentCreationTaskTest {
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
public static Iterable<Pair<String, Boolean>> data() throws IOException {
|
public static Iterable<String> data() throws IOException {
|
||||||
List<Pair<String, Boolean>> data = new ArrayList<>();
|
return asList(requireNonNull(getAssetManager().list("PngSuite")));
|
||||||
for (String file : getAssetFiles("PngSuite")) {
|
|
||||||
if (file.endsWith(".png")) {
|
|
||||||
boolean shouldPass = !file.startsWith("x");
|
|
||||||
data.add(new Pair<>("PngSuite/" + file, shouldPass));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String filename;
|
private final String filename;
|
||||||
private final boolean shouldPass;
|
|
||||||
|
|
||||||
public PngSuiteAttachmentCreationTaskTest(Pair<String, Boolean> data) {
|
public PngSuiteAttachmentCreationTaskTest(String filename) {
|
||||||
filename = data.getFirst();
|
this.filename = filename;
|
||||||
shouldPass = data.getSecond();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPngSuiteCompress() throws Exception {
|
public void testPngSuiteCompress() throws Exception {
|
||||||
if (shouldPass) {
|
if (filename.startsWith("x")) {
|
||||||
testCompress(filename, "image/png");
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
testCompress(filename, "image/png");
|
testCompress("PngSuite/" + filename, "image/png");
|
||||||
fail();
|
fail();
|
||||||
} catch (IOException expected) {
|
} catch (IOException expected) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
testCompress("PngSuite/" + filename, "image/png");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user