/*
* Copyright (c) 2017 xamoom GmbH <apps@xamoom.com>
*
* Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at the root of this project.
*/

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

import android.app.Activity;
import android.support.v4.app.Fragment;
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.xamoomcontentblocks.XamoomContentFragment;
import com.xamoom.android.xamoomsdk.BuildConfig;
import com.xamoom.android.xamoomsdk.Helper.ContentFragmentActivity;
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.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
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(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, manifest = "AndroidManifest.xml")
public class ContentBlock1AdapterTest {

  private Activity mActivity;
  private XamoomContentFragment mXamoomContentFragment;

  @Before
  public void setup() {
    mActivity = Robolectric.buildActivity( ContentFragmentActivity.class )
        .create()
        .start()
        .resume()
        .get();

    mXamoomContentFragment = XamoomContentFragment.newInstance("");
  }


  @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(mActivity, R.layout.content_block_1_layout, null);

    RecyclerView.ViewHolder vh = adapter.onCreateViewHolder(recycleView,
        mXamoomContentFragment, null, null, null,
        null, false, null, 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));
  }
}

@@ -1984,16 +1984,29 @@
 gment = 
+Mockito.mock(
 XamoomCo
@@ -2023,22 +2023,226 @@
 ent.
-newInstance(%22%22
+class);%0A    Mockito.when(mXamoomContentFragment.getContext()).thenReturn(RuntimeEnvironment.application);%0A    Mockito.when(mXamoomContentFragment.getResources()).thenReturn(RuntimeEnvironment.application.getResources()
 );%0A 

Fix contentBlock1 test getting resources