package com.iterable.iterableapi;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mock;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

import android.graphics.Rect;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class IterableInboxSessionTest {
    @Mock
    IterableInAppManager mockInAppManager = mock(IterableInAppManager.class);

    @Before
    public void setUp() {
        IterableApi.sharedInstance = new IterableApi(mockInAppManager);

//        IterableApi.sharedInstance = new IterableApi();

//        IterableTestUtils.createIterableApi();
    }

    @Test
    public void testInitializer() {
        IterableInboxSession inboxSession = new IterableInboxSession();
        assertNull(inboxSession.sessionEndTime);
        assertNull(inboxSession.sessionStartTime);
        assertNull(inboxSession.impressions);
        assertEquals(0, inboxSession.endTotalMessageCount);
        assertEquals(0, inboxSession.endUnreadMessageCount);
        assertEquals(0, inboxSession.startTotalMessageCount);
        assertEquals(0, inboxSession.endTotalMessageCount);
    }

    @Ignore("incomplete test")
    @Test
    public void testUpdateVisibleRows() {
        IterableInAppMessage msg1 = InAppTestUtils.getTestInboxInAppWithId("1");
        IterableInAppMessage msg2 = InAppTestUtils.getTestInboxInAppWithId("2");

        // load messages into inAppManager


        InboxSessionManager sessionManager = new InboxSessionManager();

        // create new session here

        IterableInboxSession inboxSession = new IterableInboxSession();

        IterableInboxSession.Impression imp1 = new IterableInboxSession.Impression(msg1.getMessageId(), true, 1, 1.0f);
        IterableInboxSession.Impression imp2 = new IterableInboxSession.Impression(msg2.getMessageId(), true, 2, 2.0f);
        IterableInboxSession.Impression elapsedImp1 = new IterableInboxSession.Impression(msg1.getMessageId(), true, 1, 3.0f);

        sessionManager.updateVisibleRows(Arrays.asList(imp1));

        assertTrue(sessionManager.impressions.containsValue(imp1));
        assertFalse(sessionManager.impressions.containsValue(imp2));

        sessionManager.updateVisibleRows(Arrays.asList(imp1, imp2));

        assertTrue(sessionManager.impressions.containsValue(imp1));
        assertTrue(sessionManager.impressions.containsValue(imp2));

        sessionManager.updateVisibleRows(Arrays.asList(elapsedImp1, imp2));

        assertFalse(sessionManager.impressions.containsValue(imp1));
        assertTrue(sessionManager.impressions.containsValue(imp2));
        assertTrue(sessionManager.impressions.containsValue(elapsedImp1));

        //get and assert data integrity of impressions at each step?
    }
}
@@ -74,62 +74,12 @@
 nit.
-Ignore;%0Aimport org.junit.Test;%0Aimport org.mockito.Mock
+Test
 ;%0A%0Ai
@@ -163,2727 +163,624 @@
 sert
-False;%0Aimport static org.junit.Assert.assertNull;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.mockito.Mockito.mock;%0A%0Aimport android.graphics.Rect;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Apublic class IterableInboxSessionTest %7B%0A    @Mock%0A    IterableInAppManager mockInAppManager = mock(IterableInAppManager.class);%0A%0A    @Before%0A    public void setUp() %7B%0A        IterableApi.sharedInstance = new IterableApi(mockInAppManager);%0A%0A//        IterableApi.sharedInstance = new IterableApi();%0A%0A//        IterableTestUtils.createIterableApi();%0A    %7D%0A%0A    @Test%0A    public void testInitializer() %7B%0A        IterableInboxSession inboxSession = new IterableInboxSession();%0A        assertNull(inboxSession.sessionEndTime);%0A        assertNull(inboxSession.sessionStartTime);%0A        assertNull(inboxSession.impressions);%0A        assertEquals(0, inboxSession.endTotalMessageCount);%0A        assertEquals(0, inboxSession.endUnreadMessageCount);%0A        assertEquals(0, inboxSession.startTotalMessageCount);%0A        assertEquals(0, inboxSession.endTotalMessageCount);%0A    %7D%0A%0A    @Ignore(%22incomplete test%22)%0A    @Test%0A    public void testUpdateVisibleRows() %7B%0A        IterableInAppMessage msg1 = InAppTestUtils.getTestInboxInAppWithId(%221%22);%0A        IterableInAppMessage msg2 = InAppTestUtils.getTestInboxInAppWithId(%222%22);%0A%0A        // load messages into inAppManager%0A%0A%0A        InboxSessionManager sessionManager = new InboxSessionManager();%0A%0A        // create new session here%0A%0A        IterableInboxSession inboxSession = new IterableInboxSession();%0A%0A        IterableInboxSession.Impression imp1 = new IterableInboxSession.Impression(msg1.getMessageId(), true, 1, 1.0f);%0A        IterableInboxSession.Impression imp2 = new IterableInboxSession.Impression(msg2.getMessageId(), true, 2, 2.0f);%0A        IterableInboxSession.Impression elapsedImp1 = new IterableInboxSession.Impression(msg1.getMessageId(), true, 1, 3.0f);%0A%0A        sessionManager.updateVisibleRows(Arrays.asList(imp1));%0A%0A        assertTrue(sessionManager.impressions.containsValue(imp1));%0A        assertFalse(sessionManager.impressions.containsValue(imp2));%0A%0A        sessionManager.updateVisibleRows(Arrays.asList(imp1, imp2));%0A%0A        assertTrue(sessionManager.impressions.containsValue(imp1));%0A        assertTrue(sessionManager.impressions.containsValue(imp2));%0A%0A        sessionManager.updateVisibleRows(Arrays.asList(elapsedImp1, imp2));%0A%0A        assertFalse(sessionManager.impressions.containsValue(imp1));%0A        assertTrue(sessionManager.impressions.containsValue(imp2));%0A        assertTrue(sessionManager.impressions.containsValue(elapsedImp1));%0A%0A        //get and assert data integrity of impressions at each step?
+Null;%0A%0Apublic class IterableInboxSessionTest extends BaseTest %7B%0A    @Before%0A    public void setUp() %7B%0A%0A    %7D%0A%0A    @Test%0A    public void testInitializer() %7B%0A        IterableInboxSession inboxSession = new IterableInboxSession();%0A        assertNull(inboxSession.sessionEndTime);%0A        assertNull(inboxSession.sessionStartTime);%0A        assertNull(inboxSession.impressions);%0A        assertEquals(0, inboxSession.endTotalMessageCount);%0A        assertEquals(0, inboxSession.endUnreadMessageCount);%0A        assertEquals(0, inboxSession.startTotalMessageCount);%0A        assertEquals(0, inboxSession.endTotalMessageCount);
 %0A   

remove test for now