Skip to content

Commit

Permalink
unit test for isHeader(int pos)
Browse files Browse the repository at this point in the history
Signed-off-by: alex <alex.plutta@googlemail.com>
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
  • Loading branch information
AlexNi245 authored and AndyScherzinger committed Aug 20, 2019
1 parent b61f9e0 commit 4ea9667
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.owncloud.android.ui.adapter;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.internal.util.reflection.FieldSetter;

import java.util.ArrayList;

public final class ActivityListAdapterTest {


@Mock
private ActivityListAdapter activityListAdapter;

@Before
public void setUp() throws NoSuchFieldException {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.initMocks(activityListAdapter);
FieldSetter.setField(activityListAdapter, activityListAdapter.getClass().getDeclaredField("values"), new ArrayList<>());
}

@Test
public void isHeader__ObjectIsHeader_ReturnTrue() {
Object header = "Hello";
Object activity = Mockito.mock(com.owncloud.android.lib.resources.activities.model.Activity.class);

Mockito.when(activityListAdapter.isHeader(0)).thenCallRealMethod();
Mockito.when(activityListAdapter.getItemViewType(0)).thenCallRealMethod();

activityListAdapter.values.add(header);
activityListAdapter.values.add(activity);

final boolean result = activityListAdapter.isHeader(0);
Assert.assertTrue(result);
}

@Test
public void isHeader__ObjectIsActivity_ReturnFalse() {
Object header = "Hello";
Object activity = Mockito.mock(com.owncloud.android.lib.resources.activities.model.Activity.class);

Mockito.when(activityListAdapter.isHeader(1)).thenCallRealMethod();
Mockito.when(activityListAdapter.getItemViewType(1)).thenCallRealMethod();

activityListAdapter.values.add(header);
activityListAdapter.values.add(activity);
Assert.assertFalse(activityListAdapter.isHeader(1));
}
}

0 comments on commit 4ea9667

Please sign in to comment.