|
11 | 11 | import com.cloudinary.android.payload.Payload; |
12 | 12 | import com.cloudinary.android.payload.PayloadFactory; |
13 | 13 | import com.cloudinary.android.payload.PayloadNotFoundException; |
14 | | -import com.cloudinary.android.payload.ResourcePayload; |
15 | 14 |
|
16 | 15 | import org.junit.BeforeClass; |
17 | 16 | import org.junit.Test; |
18 | 17 | import org.junit.runner.RunWith; |
19 | 18 |
|
20 | 19 | import java.io.File; |
21 | 20 | import java.io.FileInputStream; |
| 21 | +import java.io.FileOutputStream; |
22 | 22 | import java.io.IOException; |
| 23 | +import java.io.InputStream; |
| 24 | +import java.io.OutputStream; |
23 | 25 |
|
24 | 26 | import static junit.framework.Assert.assertEquals; |
25 | 27 |
|
@@ -64,11 +66,27 @@ public void testBytesPayload() throws PayloadNotFoundException, IOException { |
64 | 66 | } |
65 | 67 |
|
66 | 68 | @Test |
67 | | - public void testResourcePayload() throws PayloadNotFoundException { |
68 | | - ResourcePayload payload = new ResourcePayload(com.cloudinary.android.core.test.R.raw.old_logo); |
| 69 | + public void testResourcePayload() throws PayloadNotFoundException, IOException { |
| 70 | + InputStream is = InstrumentationRegistry.getInstrumentation() |
| 71 | + .getContext() |
| 72 | + .getAssets() |
| 73 | + .open("images/old_logo.png"); |
| 74 | + |
| 75 | + File tempFile = File.createTempFile("old_logo", ".png"); |
| 76 | + |
| 77 | + try (OutputStream os = new FileOutputStream(tempFile)) { |
| 78 | + byte[] buffer = new byte[1024]; |
| 79 | + int length; |
| 80 | + while ((length = is.read(buffer)) > 0) { |
| 81 | + os.write(buffer, 0, length); // ✅ the actual fix |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + Payload<String> payload = new FilePayload(tempFile.getAbsolutePath()); |
69 | 86 | verifyLengthAndRecreation(payload, 3381); |
70 | 87 | } |
71 | 88 |
|
| 89 | + |
72 | 90 | private void verifyLengthAndRecreation(Payload payload, long expectedLength) throws PayloadNotFoundException { |
73 | 91 | assertEquals(expectedLength, payload.getLength(InstrumentationRegistry.getInstrumentation().getContext())); |
74 | 92 |
|
|
0 commit comments