1package com.xtremelabs.robolectric.shadows; 2 3import android.view.View; 4import android.view.ViewGroup; 5import android.widget.BaseAdapter; 6import com.xtremelabs.robolectric.WithTestDefaultsRunner; 7import org.junit.Test; 8import org.junit.runner.RunWith; 9 10import static com.xtremelabs.robolectric.Robolectric.shadowOf; 11import static junit.framework.Assert.assertFalse; 12import static junit.framework.Assert.assertTrue; 13 14@RunWith(WithTestDefaultsRunner.class) 15public class BaseAdapterTest { 16 @Test 17 public void shouldRecordNotifyDataSetChanged() throws Exception { 18 BaseAdapter adapter = new TestBaseAdapter(); 19 adapter.notifyDataSetChanged(); 20 assertTrue(shadowOf(adapter).wasNotifyDataSetChangedCalled()); 21 } 22 23 @Test 24 public void canResetNotifyDataSetChangedFlag() throws Exception { 25 BaseAdapter adapter = new TestBaseAdapter(); 26 adapter.notifyDataSetChanged(); 27 shadowOf(adapter).clearWasDataSetChangedCalledFlag(); 28 assertFalse(shadowOf(adapter).wasNotifyDataSetChangedCalled()); 29 } 30 31 private static class TestBaseAdapter extends BaseAdapter { 32 @Override 33 public int getCount() { 34 return 0; 35 } 36 37 @Override 38 public Object getItem(int position) { 39 return null; 40 } 41 42 @Override 43 public long getItemId(int position) { 44 return 0; 45 } 46 47 @Override 48 public View getView(int position, View convertView, ViewGroup parent) { 49 return null; 50 } 51 } 52} 53