aboutsummaryrefslogtreecommitdiff
path: root/testutil
diff options
context:
space:
mode:
authorAlan Newberger <alann@google.com>2014-12-03 10:47:03 -0800
committerAlan Newberger <alann@google.com>2014-12-03 10:47:03 -0800
commit617200ae32e6671631846ae0f840115c4463c8d4 (patch)
tree17fb77eadd24974e99a5b1a44df32f5ea81f1665 /testutil
parent9dbd132bec874fdb47231ffe45d4df2b1ae05764 (diff)
parenta311d4835cdede5757e203d52a1bb5e707cfd989 (diff)
downloadglide-617200ae32e6671631846ae0f840115c4463c8d4.tar.gz
Merge tag 'v3.4.0' of https://github.com/bumptech/glide into ub-camera-haleakala
Change-Id: Ic290a947323184bfd15576a781bceb88258a5dd1
Diffstat (limited to 'testutil')
-rw-r--r--testutil/src/main/java/com/bumptech/glide/testutil/TestResourceUtil.java23
-rw-r--r--testutil/src/main/java/com/bumptech/glide/testutil/TestUtil.java37
2 files changed, 60 insertions, 0 deletions
diff --git a/testutil/src/main/java/com/bumptech/glide/testutil/TestResourceUtil.java b/testutil/src/main/java/com/bumptech/glide/testutil/TestResourceUtil.java
new file mode 100644
index 00000000..e523b67d
--- /dev/null
+++ b/testutil/src/main/java/com/bumptech/glide/testutil/TestResourceUtil.java
@@ -0,0 +1,23 @@
+package com.bumptech.glide.testutil;
+
+import java.io.InputStream;
+
+/**
+ * Test only utility for opening resources in androidTest/resources.
+ */
+public final class TestResourceUtil {
+ private TestResourceUtil() {
+ // Utility class
+ }
+
+ /**
+ * Returns an InputStream for the given test class and sub-path.
+ *
+ * @param testClass A Junit test class.
+ * @param subPath The sub-path under androidTest/resources where the desired resource is located.
+ * Should not be prefixed with a '/'
+ */
+ public static InputStream openResource(Class testClass, String subPath) {
+ return testClass.getResourceAsStream("/" + subPath);
+ }
+}
diff --git a/testutil/src/main/java/com/bumptech/glide/testutil/TestUtil.java b/testutil/src/main/java/com/bumptech/glide/testutil/TestUtil.java
new file mode 100644
index 00000000..0ad40e0e
--- /dev/null
+++ b/testutil/src/main/java/com/bumptech/glide/testutil/TestUtil.java
@@ -0,0 +1,37 @@
+package com.bumptech.glide.testutil;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Shared utility classes for tests.
+ */
+public final class TestUtil {
+ private TestUtil() {
+ // Utility class.
+ }
+
+ public static byte[] resourceToBytes(Class testClass, String resourceName) throws IOException {
+ return isToBytes(TestResourceUtil.openResource(testClass, resourceName));
+ }
+
+ public static byte[] isToBytes(InputStream is) throws IOException {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int read;
+ try {
+ while ((read = is.read(buffer)) != -1) {
+ os.write(buffer, 0, read);
+ }
+ } finally {
+ is.close();
+ }
+ return os.toByteArray();
+ }
+
+ public static String isToString(InputStream is) throws IOException {
+ return new String(isToBytes(is));
+ }
+
+}