-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #533 from OpenSRP/only-catch-checked-widget-except…
…ions Only catch checked widget exceptions
- Loading branch information
Showing
9 changed files
with
193 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...on-form-wizard/src/test/java/com/vijay/jsonwizard/interactors/JsonFormInteractorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.vijay.jsonwizard.interactors; | ||
|
||
import android.content.Intent; | ||
import android.view.View; | ||
|
||
import com.vijay.jsonwizard.BaseTest; | ||
import com.vijay.jsonwizard.R; | ||
import com.vijay.jsonwizard.activities.JsonFormActivity; | ||
import com.vijay.jsonwizard.constants.JsonFormConstants; | ||
import com.vijay.jsonwizard.fragments.JsonFormFragment; | ||
import com.vijay.jsonwizard.interfaces.CommonListener; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Captor; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.powermock.reflect.Whitebox; | ||
import org.robolectric.Robolectric; | ||
import org.robolectric.util.ReflectionHelpers; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by Vincent Karuri on 09/12/2020 | ||
*/ | ||
public class JsonFormInteractorTest extends BaseTest { | ||
|
||
private JsonFormInteractor jsonFormInteractor; | ||
|
||
@Captor | ||
private ArgumentCaptor<Intent> intentArgumentCaptor; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
jsonFormInteractor = JsonFormInteractor.getInstance(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
ReflectionHelpers.setField(jsonFormInteractor, "INSTANCE", null); | ||
} | ||
|
||
@Test | ||
public void testFetchViewsShouldSetCorrectResultForRTE() throws Exception { | ||
ReflectionHelpers.setField(jsonFormInteractor, "map", null); | ||
|
||
JsonFormActivity activity = Mockito.spy(Robolectric.buildActivity(JsonFormActivity.class, getJsonFormActivityIntent()).create().start().get()); | ||
JsonFormFragment jsonFormFragment = Mockito.mock(JsonFormFragment.class); | ||
Mockito.doReturn(activity).when(jsonFormFragment).getActivity(); | ||
|
||
Whitebox.invokeMethod(jsonFormInteractor, "fetchViews", new ArrayList<View>(), "", | ||
jsonFormFragment, "", new JSONObject(), Mockito.mock(CommonListener.class), false); | ||
|
||
Mockito.verify(activity).getString(R.string.form_load_error); | ||
Mockito.verify(activity).setResult(Mockito.eq(JsonFormConstants.RESULT_CODE.RUNTIME_EXCEPTION_OCCURRED), intentArgumentCaptor.capture()); | ||
Mockito.verify(activity).finish(); | ||
|
||
Intent intent = intentArgumentCaptor.getValue(); | ||
Assert.assertTrue(intent.getExtras().getSerializable(JsonFormConstants.RESULT_INTENT.RUNTIME_EXCEPTION) instanceof RuntimeException); | ||
|
||
activity.finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters