|
5 | 5 | import static android.app.Activity.RESULT_OK; |
6 | 6 | import static android.content.pm.PackageManager.PERMISSION_DENIED; |
7 | 7 | import static org.junit.Assert.assertEquals; |
| 8 | +import static org.junit.Assert.assertTrue; |
8 | 9 | import static org.medicmobile.webapp.mobile.EmbeddedBrowserActivity.RequestCode; |
9 | 10 | import static org.mockito.ArgumentMatchers.any; |
10 | 11 | import static org.mockito.ArgumentMatchers.anyInt; |
11 | 12 | import static org.mockito.ArgumentMatchers.anyString; |
12 | 13 | import static org.mockito.ArgumentMatchers.eq; |
| 14 | +import static org.mockito.ArgumentMatchers.matches; |
13 | 15 | import static org.mockito.Mockito.doNothing; |
14 | 16 | import static org.mockito.Mockito.doThrow; |
15 | 17 | import static org.mockito.Mockito.mock; |
|
35 | 37 | import org.mockito.MockitoAnnotations; |
36 | 38 | import org.robolectric.RobolectricTestRunner; |
37 | 39 |
|
| 40 | +import java.util.regex.Pattern; |
| 41 | + |
38 | 42 | @RunWith(RobolectricTestRunner.class) |
39 | 43 | public class ChtExternalAppHandlerTest { |
40 | 44 | @Mock |
@@ -154,18 +158,19 @@ public void processResult_withBadResultCodeAndData_logError() { |
154 | 158 | //> GIVEN |
155 | 159 | Intent intent = new Intent(); |
156 | 160 | intent.putExtra("name", "Eric"); |
| 161 | + intent.putExtra("duration", 0L); |
157 | 162 | ChtExternalAppHandler chtExternalAppHandler = new ChtExternalAppHandler(contextMock); |
158 | 163 | String expectedMessageWarn = "ChtExternalAppHandler :: Bad result code: %s. The external app either: " + |
159 | | - "explicitly returned this result, did not return any result or crashed during the operation. [{\"name\":\"Eric\"}]"; |
| 164 | + "explicitly returned this result, did not return any result or crashed during the operation. \\[\\{\"duration\":\\d+,\"name\":\"Eric\"}]"; |
160 | 165 | String expectedMessageConsole = "ChtExternalAppHandler :: Bad result code: " + RESULT_CANCELED + ". The external app either: " + |
161 | | - "explicitly returned this result, did not return any result or crashed during the operation. [{\"name\":\"Eric\"}]"; |
| 166 | + "explicitly returned this result, did not return any result or crashed during the operation. \\[\\{\"duration\":\\d+,\"name\":\"Eric\"}]"; |
162 | 167 |
|
163 | 168 | //> WHEN |
164 | 169 | String script = chtExternalAppHandler.processResult(RESULT_CANCELED, intent); |
165 | 170 |
|
166 | 171 | //> THEN |
167 | | - assertEquals("console.error('" + expectedMessageConsole + "')", script); |
168 | | - medicLogMock.verify(() -> MedicLog.warn(eq(chtExternalAppHandler), eq(expectedMessageWarn), eq(RESULT_CANCELED))); |
| 172 | + assertTrue(Pattern.matches("console\\.error\\('" + expectedMessageConsole + "'\\)", script)); |
| 173 | + medicLogMock.verify(() -> MedicLog.warn(eq(chtExternalAppHandler), matches(expectedMessageWarn), eq(RESULT_CANCELED))); |
169 | 174 | } |
170 | 175 | } |
171 | 176 |
|
|
0 commit comments