// Path: iterableapi/src/test/java/com/iterable/iterableapi/unit/TestRunner.java
// public class TestRunner extends RobolectricTestRunner {
//     /**
//      * Creates a runner to run {@code testClass}. Looks in your working directory for your AndroidManifest.xml file
//      * and res directory by default. Use the {@link Config} annotation to configure.
//      *
//      * @param testClass the test class to be run
//      * @throws InitializationError if junit says so
//      */
//     public TestRunner(Class<?> testClass) throws InitializationError {
//         super(testClass);
//     }
// 
// }


import com.iterable.iterableapi.unit.TestRunner;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
        verify(mockChangeListener).onInAppMessageChanged(testInAppMessage);
    }

    @Test
    public void testStorageNotInvoked() throws Exception {
        JSONObject payload = new JSONObject(IterableTestUtils.getResourceString("inapp_payload_multiple.json"));
        JSONArray jsonArray = payload.optJSONArray(IterableConstants.ITERABLE_IN_APP_MESSAGE);
        String storageInterfaceHTML = "HTML from storage interface";
        if (jsonArray != null) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject messageJson = jsonArray.optJSONObject(i);

                IterableInAppStorage storageInterface = mock(IterableInAppStorage.class);
                IterableInAppMessage message = IterableInAppMessage.fromJSONObject(messageJson, storageInterface);
                assertNotNull(message.getContent().html);
                assertNotEquals(message.getContent().html, storageInterfaceHTML);

                //Asserting if the storage was accessed even once
                verify(storageInterface, times(0)).getHTML(message.getMessageId());
            }
        }
    }

    @Test
    public void testInAppStorageAccess() throws Exception {
        JSONObject payload = new JSONObject(IterableTestUtils.getResourceString("inapp_payload_multiple.json"));
        JSONArray jsonArray = payload.optJSONArray(IterableConstants.ITERABLE_IN_APP_MESSAGE);
        String storageInterfaceHTML = "HTML from storage interface";
        if (jsonArray != null) {
            for (int i = 0; i < jsonArray.length(); i++) {
// Path: iterableapi/src/test/java/com/iterable/iterableapi/unit/TestRunner.java
// public class TestRunner extends RobolectricTestRunner {
//     /**
//      * Creates a runner to run {@code testClass}. Looks in your working directory for your AndroidManifest.xml file
//      * and res directory by default. Use the {@link Config} annotation to configure.
//      *
//      * @param testClass the test class to be run
//      * @throws InitializationError if junit says so
//      */
//     public TestRunner(Class<?> testClass) throws InitializationError {
//         super(testClass);
//     }
// 
// }


// Path: iterableapi/src/test/java/com/iterable/iterableapi/IterableInAppMessageTest.java
import com.iterable.iterableapi.unit.TestRunner;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

        verify(mockChangeListener).onInAppMessageChanged(testInAppMessage);
    }

    @Test
    public void testStorageNotInvoked() throws Exception {
        JSONObject payload = new JSONObject(IterableTestUtils.getResourceString("inapp_payload_multiple.json"));
        JSONArray jsonArray = payload.optJSONArray(IterableConstants.ITERABLE_IN_APP_MESSAGE);
        String storageInterfaceHTML = "HTML from storage interface";
        if (jsonArray != null) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject messageJson = jsonArray.optJSONObject(i);

                IterableInAppStorage storageInterface = mock(IterableInAppStorage.class);
                IterableInAppMessage message = IterableInAppMessage.fromJSONObject(messageJson, storageInterface);
                assertNotNull(message.getContent().html);
                assertNotEquals(message.getContent().html, storageInterfaceHTML);

                //Asserting if the storage was accessed even once
                verify(storageInterface, times(0)).getHTML(message.getMessageId());
            }
        }
    }

    @Test
    public void testInAppStorageAccess() throws Exception {
        JSONObject payload = new JSONObject(IterableTestUtils.getResourceString("inapp_payload_multiple.json"));
        JSONArray jsonArray = payload.optJSONArray(IterableConstants.ITERABLE_IN_APP_MESSAGE);
        String storageInterfaceHTML = "HTML from storage interface";
        if (jsonArray != null) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject messageJson = jsonArray.optJSONObject(i);