14
14
15
15
package com .google .firebase .crashlytics .internal .common ;
16
16
17
+ import static java .util .Arrays .stream ;
18
+
17
19
import android .content .Context ;
18
20
import com .google .firebase .crashlytics .internal .CrashlyticsTestCase ;
19
21
import java .io .ByteArrayOutputStream ;
20
22
import java .io .File ;
21
23
import java .io .FileOutputStream ;
22
- import java .io .IOException ;
23
24
import java .util .Arrays ;
24
25
import java .util .List ;
25
26
import org .junit .Test ;
26
27
import org .mockito .internal .util .collections .Sets ;
27
28
29
+ @ SuppressWarnings ("ResultOfMethodCallIgnored" ) // Convenient use of files.
28
30
public class NativeSessionFileGzipperTest extends CrashlyticsTestCase {
29
31
byte [] testContents = {0 , 2 , 20 , 10 };
30
32
File testFile ;
@@ -47,8 +49,17 @@ protected void setUp() throws Exception {
47
49
gzipDir .mkdirs ();
48
50
}
49
51
52
+ @ Override
53
+ protected void tearDown () throws Exception {
54
+ super .tearDown ();
55
+ File [] gzipFiles = gzipDir .listFiles ();
56
+ if (gzipFiles != null ) {
57
+ stream (gzipFiles ).forEach (File ::delete );
58
+ }
59
+ }
60
+
50
61
@ Test
51
- public void testProcessNativeSessions_putsFilesInCorrectLocation () throws IOException {
62
+ public void testProcessNativeSessions_putsFilesInCorrectLocation () {
52
63
String fileBackedSessionName = "file" ;
53
64
String byteBackedSessionName = "byte" ;
54
65
FileBackedNativeSessionFile fileSession =
@@ -58,10 +69,12 @@ public void testProcessNativeSessions_putsFilesInCorrectLocation() throws IOExce
58
69
List <NativeSessionFile > files = Arrays .asList (fileSession , byteSession );
59
70
NativeSessionFileGzipper .processNativeSessions (gzipDir , files );
60
71
72
+ File [] gzipFiles = gzipDir .listFiles ();
73
+ assertNotNull (gzipFiles );
61
74
assertEquals (
62
75
Sets .newSet (
63
76
new File (gzipDir , fileBackedSessionName ), new File (gzipDir , byteBackedSessionName )),
64
- Sets .newSet (gzipDir . listFiles () ));
77
+ Sets .newSet (gzipFiles ));
65
78
}
66
79
67
80
@ Test
@@ -75,7 +88,8 @@ public void testProcessNativeSessionsWhenDataIsNull_putsFilesInCorrectLocation()
75
88
List <NativeSessionFile > files = Arrays .asList (fileSession , byteSession );
76
89
NativeSessionFileGzipper .processNativeSessions (gzipDir , files );
77
90
78
- assertEquals (
79
- Sets .newSet (new File (gzipDir , byteBackedSessionName )), Sets .newSet (gzipDir .listFiles ()));
91
+ File [] gzipFiles = gzipDir .listFiles ();
92
+ assertNotNull (gzipFiles );
93
+ assertEquals (Sets .newSet (new File (gzipDir , byteBackedSessionName )), Sets .newSet (gzipFiles ));
80
94
}
81
95
}
0 commit comments