1
+ package org .researchstack .molemapper .bridge ;
2
+
3
+ import android .util .Log ;
4
+
5
+ import static org .junit .Assert .assertTrue ;
6
+
7
+ import org .junit .Before ;
8
+ import org .junit .Test ;
9
+ import org .junit .runner .RunWith ;
10
+
11
+ import org .researchstack .molemapper .BuildConfig ;
12
+ import org .robolectric .RobolectricTestRunner ;
13
+ import org .robolectric .annotation .Config ;
14
+
15
+ import java .util .regex .Pattern ;
16
+
17
+
18
+ /**
19
+ * Created by liujoshua on 8/10/16.
20
+ */
21
+ @ RunWith (RobolectricTestRunner .class )
22
+ @ Config (constants = BuildConfig .class )
23
+ public class BridgeDataProviderTest {
24
+ /**
25
+ * For example, "App Name/14".
26
+ */
27
+ private static final Pattern SHORT_STRING = Pattern .compile ("^([^/]+)\\ /(\\ d{1,9})($)" );
28
+ /**
29
+ * For example, "Unknown Client/14 BridgeJavaSDK/10".
30
+ */
31
+ private static final Pattern MEDIUM_STRING = Pattern .compile ("^([^/]+)\\ /(\\ d{1,9})\\ s([^/\\ (]*)\\ /(\\ d{1,9})($)" );
32
+ /**
33
+ * For example, "Asthma/26 (Unknown iPhone; iPhone OS 9.1) BridgeSDK/4" or
34
+ * "Asthma/26 (Unknown iPhone; iPhone OS/9.1) BridgeSDK/4"
35
+ */
36
+ private static final Pattern LONG_STRING = Pattern .compile ("^([^/]+)\\ /(\\ d{1,9})\\ s\\ (([^;]+);([^\\ )]*)\\ )\\ s([^/]*)\\ /(\\ d{1,9})($)" );
37
+
38
+ private BridgeDataProvider bridgeDataProvider ;
39
+
40
+ @ Before
41
+ public void setUp () {
42
+ bridgeDataProvider = new MoleMapperDataProvider ();
43
+ }
44
+
45
+ @ Test
46
+ public void testGetUserAgent_MatchesValidFormat () {
47
+ String userAgent = bridgeDataProvider .getUserAgent ();
48
+
49
+ boolean isMatchForShortString = SHORT_STRING .matcher (userAgent ).matches ();
50
+ boolean isMatchForMediumString = MEDIUM_STRING .matcher (userAgent ).matches ();
51
+ boolean isMatchForLongString = LONG_STRING .matcher (userAgent ).matches ();
52
+
53
+ assertTrue (isMatchForShortString || isMatchForMediumString || isMatchForLongString );
54
+ }
55
+ }
0 commit comments