|
14 | 14 |
|
15 | 15 | package com.google.firebase.crashlytics.internal.common;
|
16 | 16 |
|
17 |
| -import org.junit.Test; |
18 |
| - |
| 17 | +import android.content.Context; |
| 18 | +import com.google.firebase.crashlytics.internal.CrashlyticsTestCase; |
| 19 | +import java.io.ByteArrayOutputStream; |
| 20 | +import java.io.File; |
| 21 | +import java.io.FileOutputStream; |
| 22 | +import java.io.IOException; |
19 | 23 | import java.util.Arrays;
|
20 | 24 | import java.util.List;
|
| 25 | +import org.junit.Test; |
| 26 | +import org.mockito.internal.util.collections.Sets; |
| 27 | + |
| 28 | +public class NativeSessionFileGzipperTest extends CrashlyticsTestCase { |
| 29 | + byte[] testContents = {0, 2, 20, 10}; |
| 30 | + File testFile; |
| 31 | + File missingFile; |
| 32 | + File gzipDir; |
| 33 | + |
| 34 | + @Override |
| 35 | + protected void setUp() throws Exception { |
| 36 | + super.setUp(); |
| 37 | + final Context context = getContext(); |
| 38 | + testFile = new File(context.getFilesDir(), "testFile"); |
| 39 | + try (FileOutputStream fout = new FileOutputStream(testFile); |
| 40 | + ByteArrayOutputStream stream = new ByteArrayOutputStream()) { |
| 41 | + stream.write(testContents); |
| 42 | + stream.writeTo(fout); |
| 43 | + } |
| 44 | + File baseDirectory = context.getFilesDir(); |
| 45 | + missingFile = new File(baseDirectory, "missingFile"); |
| 46 | + gzipDir = new File(baseDirectory, "gzip"); |
| 47 | + gzipDir.mkdirs(); |
| 48 | + } |
21 | 49 |
|
22 |
| -public class NativeSessionFileGzipperTest { |
| 50 | + @Test |
| 51 | + public void testProcessNativeSessions_putsFilesInCorrectLocation() throws IOException { |
| 52 | + String fileBackedSessionName = "file"; |
| 53 | + String byteBackedSessionName = "byte"; |
| 54 | + FileBackedNativeSessionFile fileSession = |
| 55 | + new FileBackedNativeSessionFile(fileBackedSessionName, testFile); |
| 56 | + BytesBackedNativeSessionFile byteSession = |
| 57 | + new BytesBackedNativeSessionFile(byteBackedSessionName, testContents); |
| 58 | + List<NativeSessionFile> files = Arrays.asList(fileSession, byteSession); |
| 59 | + NativeSessionFileGzipper.processNativeSessions(gzipDir, files); |
| 60 | + |
| 61 | + assertEquals( |
| 62 | + Sets.newSet( |
| 63 | + new File(gzipDir, fileBackedSessionName), new File(gzipDir, byteBackedSessionName)), |
| 64 | + Sets.newSet(gzipDir.listFiles())); |
| 65 | + } |
23 | 66 |
|
24 | 67 | @Test
|
25 |
| - public void testProcessNativeSessions_processesNativeSessions() { |
| 68 | + public void testProcessNativeSessionsWhenDataIsNull_putsFilesInCorrectLocation() |
| 69 | + throws IOException { |
| 70 | + // String fileBackedSessionName = "file"; |
| 71 | + // String byteBackedSessionName = "byte"; |
| 72 | + // FileBackedNativeSessionFile fileSession = |
| 73 | + // new FileBackedNativeSessionFile(fileBackedSessionName, missingFile); |
| 74 | + // BytesBackedNativeSessionFile byteSession = |
| 75 | + // new BytesBackedNativeSessionFile(byteBackedSessionName, testContents); |
26 | 76 | // List<NativeSessionFile> files = Arrays.asList(fileSession, byteSession);
|
27 |
| - // NativeSessionFileGzipper.processNativeSessions(directory, files); |
28 |
| - // FIXME: |
29 |
| - |
| 77 | + // NativeSessionFileGzipper.processNativeSessions(gzipDir, files); |
| 78 | + // |
| 79 | + // assertEquals(Sets.newSet( |
| 80 | + // new File(gzipDir, byteBackedSessionName)), |
| 81 | + // Sets.newSet(gzipDir.listFiles())); |
30 | 82 | }
|
31 | 83 | }
|
0 commit comments