package com.xamoom.android.xamoomsdk.xamoomcontentblocks.Adapters;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.xamoom.android.xamoomcontentblocks.Adapters.ContentBlock1Adapter;
import com.xamoom.android.xamoomcontentblocks.ViewHolders.ContentBlock1ViewHolder;
import com.xamoom.android.xamoomsdk.BuildConfig;
import com.xamoom.android.xamoomsdk.R;
import com.xamoom.android.xamoomsdk.Resource.ContentBlock;
import com.xamoom.android.xamoomsdk.Resource.Style;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

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

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Matchers.eq;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, manifest = "AndroidManifest.xml")
public class ContentBlock1AdapterTest {

  Activity activity;

  @Before
  public void setup() {
    activity = Robolectric.buildActivity(Activity.class).create().get();
  }


  @Test
  public void testConstructor() {
    assertNotNull(new ContentBlock1Adapter());
  }

  @Test
  public void testIsForViewType() {
    List<ContentBlock> contentBlocks = new ArrayList();
    ContentBlock contentBlock = new ContentBlock();
    contentBlock.setBlockType(1);
    contentBlocks.add(contentBlock);

    ContentBlock1Adapter contentBlock1Adapter = new ContentBlock1Adapter();

    assertTrue(contentBlock1Adapter.isForViewType(contentBlocks, 0));
  }

  @Test
  public void testOnCreateViewHolder() {
    List<ContentBlock> contentBlocks = new ArrayList();
    ContentBlock contentBlock = new ContentBlock();
    contentBlock.setBlockType(1);
    contentBlocks.add(contentBlock);

    ContentBlock1Adapter adapter = new ContentBlock1Adapter();
    ViewGroup recycleView = (ViewGroup) View.inflate(activity, R.layout.content_block_1_layout, null);

    RecyclerView.ViewHolder vh = adapter.onCreateViewHolder(recycleView, null, null, null, null, null, false, null, null);

    assertNotNull(vh);
    assertEquals(vh.getClass(), ContentBlock1ViewHolder.class);
  }

  @Test
  public void testOnBindViewHolder() {
    List<ContentBlock> contentBlocks = new ArrayList();
    ContentBlock contentBlock = new ContentBlock();
    contentBlock.setBlockType(0);
    contentBlocks.add(contentBlock);
    Style style = new Style();
    style.setForegroundFontColor("#000000");
    ContentBlock1ViewHolder mockViewholder = Mockito.mock(ContentBlock1ViewHolder.class);
    ContentBlock1Adapter adapter = new ContentBlock1Adapter();

    adapter.onBindViewHolder(contentBlocks, 0, mockViewholder, style, false);

    Mockito.verify(mockViewholder).setupContentBlock(eq(contentBlock), eq(false));
  }
}

@@ -90,16 +90,56 @@
 tivity;%0A
+import android.support.v4.app.Fragment;%0A
 import a
@@ -431,23 +431,160 @@
 moom
-sdk.BuildConfig
+contentblocks.XamoomContentFragment;%0Aimport com.xamoom.android.xamoomsdk.BuildConfig;%0Aimport com.xamoom.android.xamoomsdk.Helper.ContentFragmentActivity
 ;%0Aim
@@ -954,24 +954,67 @@
 TestRunner;%0A
+import org.robolectric.RuntimeEnvironment;%0A
 import org.r
@@ -1458,16 +1458,24 @@
 st %7B%0A%0A  
+private 
 Activity
@@ -1479,17 +1479,18 @@
 ity 
-a
+mA
 ctivity;
 %0A%0A  
@@ -1485,16 +1485,72 @@
 ctivity;
+%0A  private XamoomContentFragment mXamoomContentFragment;
 %0A%0A  @Bef
@@ -1581,17 +1581,18 @@
 ) %7B%0A    
-a
+mA
 ctivity 
@@ -1623,37 +1623,176 @@
 ity(
-Activity.class).create().get(
+ ContentFragmentActivity.class )%0A        .create()%0A        .start()%0A        .resume()%0A        .get();%0A%0A    mXamoomContentFragment = XamoomContentFragment.newInstance(%22%22
 );%0A 
@@ -2611,17 +2611,18 @@
 inflate(
-a
+mA
 ctivity,
@@ -2735,21 +2735,47 @@
 cleView,
- null
+%0A        mXamoomContentFragment
 , null, 
@@ -2781,24 +2781,32 @@
  null, null,
+%0A       
  null, false

Add fragment to test with