diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/activities/FormConfigurationJsonFormActivityTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/activities/FormConfigurationJsonFormActivityTest.java index a60b837c9..014393a3f 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/activities/FormConfigurationJsonFormActivityTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/activities/FormConfigurationJsonFormActivityTest.java @@ -46,18 +46,16 @@ public void setUp() throws Exception { public void getRulesShouldReturnCallFormUtils() throws Exception { FormUtils formUtils = Mockito.mock(FormUtils.class); - ReflectionHelpers.setStaticField(FormUtils.class, "instance", formUtils); - ReflectionHelpers.setField(formUtils, "mContext", RuntimeEnvironment.application); String rulesFileIdentifier = "registration_calculation.yml"; ClientFormContract.Dao clientFormRepository = Mockito.mock(ClientFormContract.Dao.class); - NativeFormLibrary.getInstance().setClientFormDao(clientFormRepository); + ReflectionHelpers.setField(formConfigurationJsonFormActivity, "formUtils", formUtils); Mockito.doReturn(new BufferedReader(new StringReader(""))).when(formUtils).getRulesFromRepository( Mockito.eq(RuntimeEnvironment.application), Mockito.eq(clientFormRepository), - rulesFileIdentifier); + Mockito.eq(rulesFileIdentifier)); formConfigurationJsonFormActivity.getRules(RuntimeEnvironment.application, rulesFileIdentifier); @@ -70,12 +68,12 @@ public void getRulesShouldReturnCallFormUtils() throws Exception { public void getSubFormShouldCallFormUtils() throws Exception { FormUtils formUtils = Mockito.mock(FormUtils.class); - ReflectionHelpers.setStaticField(FormUtils.class, "instance", formUtils); - ReflectionHelpers.setField(formUtils, "mContext", RuntimeEnvironment.application); String subFormIdentifier = "tuberculosis_test"; JSONObject jsonObject = new JSONObject(); ClientFormContract.Dao clientFormRepository = Mockito.mock(ClientFormContract.Dao.class); + NativeFormLibrary.getInstance().setClientFormDao(clientFormRepository); + ReflectionHelpers.setField(formConfigurationJsonFormActivity, "formUtils", formUtils); Mockito.doReturn(jsonObject).when(formUtils).getSubFormJsonFromRepository(RuntimeEnvironment.application, clientFormRepository, subFormIdentifier, null, false); @@ -89,8 +87,9 @@ public void getSubFormShouldCallHandleFormErrorWhenFormReturnedIsCorrupted() thr FormConfigurationJsonFormActivity spiedActivity = Mockito.spy(formConfigurationJsonFormActivity); ClientFormContract.Dao clientFormRepository = Mockito.mock(ClientFormContract.Dao.class); - ReflectionHelpers.setStaticField(FormUtils.class, "instance", formUtils); String subFormIdentifier = "tuberculosis_test.json"; + NativeFormLibrary.getInstance().setClientFormDao(clientFormRepository); + ReflectionHelpers.setField(spiedActivity, "formUtils", formUtils); Mockito.doAnswer(new Answer() { @Override @@ -111,20 +110,20 @@ public void handleFormErrorShouldCallFormUtilsHandleError() { //formConfigurationJsonFormActivity.contex FormConfigurationJsonFormActivity spiedActivity = Mockito.spy(formConfigurationJsonFormActivity); ClientFormContract.Dao clientFormRepository = Mockito.mock(ClientFormContract.Dao.class); + NativeFormLibrary.getInstance().setClientFormDao(clientFormRepository); + ReflectionHelpers.setField(spiedActivity, "formUtils", formUtils); - ReflectionHelpers.setStaticField(FormUtils.class, "instance", formUtils); - ReflectionHelpers.setField(formUtils, "mContext", RuntimeEnvironment.application); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { - OnFormFetchedCallback onFormFetchedCallback = invocation.getArgument(2); + OnFormFetchedCallback onFormFetchedCallback = invocation.getArgument(4); onFormFetchedCallback.onFormFetched(""); return null; } - }).when(formUtils).handleJsonFormOrRulesError(RuntimeEnvironment.application, clientFormRepository, Mockito.eq(false), Mockito.eq(formIdentifier), Mockito.any(OnFormFetchedCallback.class)); + }).when(formUtils).handleJsonFormOrRulesError(Mockito.eq(spiedActivity), Mockito.eq(clientFormRepository), Mockito.eq(false), Mockito.eq(formIdentifier), Mockito.any(OnFormFetchedCallback.class)); spiedActivity.handleFormError(false, formIdentifier); - Mockito.verify(formUtils).handleJsonFormOrRulesError(RuntimeEnvironment.application, clientFormRepository, Mockito.eq(false), Mockito.eq(formIdentifier), Mockito.any(OnFormFetchedCallback.class)); + Mockito.verify(formUtils).handleJsonFormOrRulesError(Mockito.eq(spiedActivity), Mockito.eq(clientFormRepository), Mockito.eq(false), Mockito.eq(formIdentifier), Mockito.any(OnFormFetchedCallback.class)); Mockito.verify(spiedActivity).finish(); } @@ -188,7 +187,9 @@ public void onCreateShouldCallShowFormVersionUpdateDialog() throws JSONException Mockito.doNothing().when(spiedActivity).init(Mockito.anyString()); Mockito.doNothing().when(spiedActivity).showFormVersionUpdateDialog(jsonObject, getString(R.string.form_update_title), getString(R.string.form_update_message)); - spiedActivity.onCreate(new Bundle()); + Bundle bundle = new Bundle(); + bundle.putString(JsonFormBaseActivity.JSON_STATE, "{}"); + spiedActivity.onCreate(bundle); Mockito.verify(spiedActivity).showFormVersionUpdateDialog(jsonObject, getString(R.string.form_update_title), getString(R.string.form_update_message)); } diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormRollbackDialogUtilTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormRollbackDialogUtilTest.java index 06e423ccc..bff520ed5 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormRollbackDialogUtilTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormRollbackDialogUtilTest.java @@ -87,6 +87,7 @@ public void selectFormShouldReturnTrueWhenBaseFormIsSelected() { clientFormsList.add(clientForm); ClientFormContract.Dao clientFormRepository = Mockito.mock(ClientFormContract.Dao.class); + Mockito.doReturn(new TestClientForm()).when(clientFormRepository).createNewClientFormModel(); RollbackDialogCallback rollbackDialogCallback = Mockito.mock(RollbackDialogCallback.class); assertTrue(FormRollbackDialogUtil.selectForm(clientFormRepository,0, "base version" diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormUtilsTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormUtilsTest.java index 14438b730..b6453e110 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormUtilsTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormUtilsTest.java @@ -373,7 +373,6 @@ public void getRulesFromRepositoryShouldCallRepositoryQueryingClientForm() { clientForm.setJson(""); ClientFormContract.Dao clientFormRepository = Mockito.mock(ClientFormContract.Dao.class); Mockito.doReturn(clientForm).when(clientFormRepository).getActiveClientFormByIdentifier(Mockito.eq(rulesFileIdentifier)); - ReflectionHelpers.setField(formUtils, "mContext", RuntimeEnvironment.application); Assert.assertNotNull(formUtils.getRulesFromRepository(context, clientFormRepository, rulesFileIdentifier)); @@ -388,7 +387,6 @@ public void getSubFormFromRepository() throws JSONException { clientForm.setJson("{}"); ClientFormContract.Dao clientFormRepository = Mockito.mock(ClientFormContract.Dao.class); Mockito.doReturn(clientForm).when(clientFormRepository).getActiveClientFormByIdentifier(Mockito.eq("json.form/sub_form/" + subFormIdentifier)); - ReflectionHelpers.setField(formUtils, "mContext", RuntimeEnvironment.application); JSONObject jsonObject = formUtils.getSubFormJsonFromRepository(context, clientFormRepository, subFormIdentifier, null, false);