|
26 | 26 |
|
27 | 27 | import com.optimizely.ab.android.shared.ServiceScheduler;
|
28 | 28 | import com.optimizely.ab.android.user_profile.AndroidUserProfile;
|
| 29 | +import com.optimizely.ab.config.parser.ConfigParseException; |
29 | 30 |
|
30 | 31 | import org.junit.Before;
|
31 | 32 | import org.junit.Test;
|
@@ -98,6 +99,45 @@ public void initialize() {
|
98 | 99 | assertTrue(intent.getComponent().getShortClassName().contains("DataFileService"));
|
99 | 100 | }
|
100 | 101 |
|
| 102 | + @Test |
| 103 | + public void initializeWithEmptyDatafile() { |
| 104 | + Context context = mock(Context.class); |
| 105 | + Context appContext = mock(Context.class); |
| 106 | + when(context.getApplicationContext()).thenReturn(appContext); |
| 107 | + when(appContext.getPackageName()).thenReturn("com.optly"); |
| 108 | + |
| 109 | + String emptyString = ""; |
| 110 | + |
| 111 | + optimizelyManager.initialize(context, emptyString); |
| 112 | + verify(logger).error(eq("Unable to parse compiled data file"), any(ConfigParseException.class)); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void initializeWithMalformedDatafile() { |
| 117 | + Context context = mock(Context.class); |
| 118 | + Context appContext = mock(Context.class); |
| 119 | + when(context.getApplicationContext()).thenReturn(appContext); |
| 120 | + when(appContext.getPackageName()).thenReturn("com.optly"); |
| 121 | + |
| 122 | + String emptyString = "malformed data"; |
| 123 | + |
| 124 | + optimizelyManager.initialize(context, emptyString); |
| 125 | + verify(logger).error(eq("Unable to parse compiled data file"), any(ConfigParseException.class)); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + public void initializeWithNullDatafile() { |
| 130 | + Context context = mock(Context.class); |
| 131 | + Context appContext = mock(Context.class); |
| 132 | + when(context.getApplicationContext()).thenReturn(appContext); |
| 133 | + when(appContext.getPackageName()).thenReturn("com.optly"); |
| 134 | + |
| 135 | + String emptyString = null; |
| 136 | + |
| 137 | + optimizelyManager.initialize(context, emptyString); |
| 138 | + verify(logger).error(eq("Unable to parse compiled data file"), any(ConfigParseException.class)); |
| 139 | + } |
| 140 | + |
101 | 141 | @Test
|
102 | 142 | public void stop() {
|
103 | 143 | Context context = mock(Context.class);
|
|
0 commit comments