From a5e9fec1d155d364810059148d6fdff1184167b7 Mon Sep 17 00:00:00 2001 From: Vincent Karuri Date: Mon, 7 Sep 2020 17:32:34 +0300 Subject: [PATCH 1/2] Add ExpansionPanelUndoButtonClickListener tests --- ...nsionPanelUndoButtonClickListenerTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 android-json-form-wizard/src/test/java/com/vijay/jsonwizard/listeners/ExpansionPanelUndoButtonClickListenerTest.java diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/listeners/ExpansionPanelUndoButtonClickListenerTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/listeners/ExpansionPanelUndoButtonClickListenerTest.java new file mode 100644 index 000000000..e9c80c277 --- /dev/null +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/listeners/ExpansionPanelUndoButtonClickListenerTest.java @@ -0,0 +1,56 @@ +package com.vijay.jsonwizard.listeners; + +import android.content.Context; +import android.view.View; + +import com.vijay.jsonwizard.BaseTest; +import com.vijay.jsonwizard.R; +import com.vijay.jsonwizard.constants.JsonFormConstants; +import com.vijay.jsonwizard.utils.FormUtils; +import com.vijay.jsonwizard.widgets.FactoryTest; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.util.ReflectionHelpers; + +import static org.junit.Assert.*; + +/** + * Created by Vincent Karuri on 07/09/2020 + */ +public class ExpansionPanelUndoButtonClickListenerTest extends FactoryTest { + + private ExpansionPanelUndoButtonClickListener expansionPanelUndoButtonClickListener; + + @Before + public void setUp() { + super.setUp(); + expansionPanelUndoButtonClickListener = new ExpansionPanelUndoButtonClickListener(); + } + + @Test + public void onClickShouldSetUpExpansionPanel() throws JSONException { + View view = new View(RuntimeEnvironment.application); + view.setTag(R.id.key, "key"); + view.setTag(R.id.specify_context, jsonFormActivity); + view.setTag(R.id.specify_step_name, "step1"); + + FormUtils formUtils = Mockito.mock(FormUtils.class); + JSONArray fields = new JSONArray(); + JSONObject field = new JSONObject(); + field.put(JsonFormConstants.KEY, "key"); + field.put(JsonFormConstants.VALUE, "value"); + fields.put(field); + Mockito.doReturn(fields).when(formUtils).getFormFields(ArgumentMatchers.anyString(), ArgumentMatchers.any(Context.class)); + + ReflectionHelpers.setField(expansionPanelUndoButtonClickListener, "formUtils", formUtils); + expansionPanelUndoButtonClickListener.onClick(view); + } +} \ No newline at end of file From 3625cdb373e6d5e891c871557f058bc0d31981ee Mon Sep 17 00:00:00 2001 From: Vincent Karuri Date: Mon, 7 Sep 2020 17:49:51 +0300 Subject: [PATCH 2/2] Assert expansion panel is launched --- ...nsionPanelUndoButtonClickListenerTest.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/listeners/ExpansionPanelUndoButtonClickListenerTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/listeners/ExpansionPanelUndoButtonClickListenerTest.java index e9c80c277..071b796c7 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/listeners/ExpansionPanelUndoButtonClickListenerTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/listeners/ExpansionPanelUndoButtonClickListenerTest.java @@ -3,7 +3,6 @@ import android.content.Context; import android.view.View; -import com.vijay.jsonwizard.BaseTest; import com.vijay.jsonwizard.R; import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.utils.FormUtils; @@ -12,16 +11,15 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.robolectric.RuntimeEnvironment; +import org.robolectric.shadows.ShadowAlertDialog; import org.robolectric.util.ReflectionHelpers; -import static org.junit.Assert.*; - /** * Created by Vincent Karuri on 07/09/2020 */ @@ -37,20 +35,27 @@ public void setUp() { @Test public void onClickShouldSetUpExpansionPanel() throws JSONException { + final String KEY = "key"; + final String VALUE = "value"; + View view = new View(RuntimeEnvironment.application); - view.setTag(R.id.key, "key"); + view.setTag(R.id.key, KEY); view.setTag(R.id.specify_context, jsonFormActivity); view.setTag(R.id.specify_step_name, "step1"); FormUtils formUtils = Mockito.mock(FormUtils.class); JSONArray fields = new JSONArray(); JSONObject field = new JSONObject(); - field.put(JsonFormConstants.KEY, "key"); - field.put(JsonFormConstants.VALUE, "value"); + field.put(JsonFormConstants.KEY, KEY); + field.put(JsonFormConstants.VALUE, VALUE); + field.put(JsonFormConstants.TEXT, "header"); fields.put(field); - Mockito.doReturn(fields).when(formUtils).getFormFields(ArgumentMatchers.anyString(), ArgumentMatchers.any(Context.class)); + Mockito.doReturn(fields).when(formUtils).getFormFields(ArgumentMatchers.anyString(), + ArgumentMatchers.any(Context.class)); ReflectionHelpers.setField(expansionPanelUndoButtonClickListener, "formUtils", formUtils); expansionPanelUndoButtonClickListener.onClick(view); + + Assert.assertNotNull(ShadowAlertDialog.getLatestAlertDialog()); } } \ No newline at end of file