Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.view.View;
      4 import android.widget.ExpandableListView;
      5 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
      6 import com.xtremelabs.robolectric.util.Transcript;
      7 import org.junit.Before;
      8 import org.junit.Test;
      9 import org.junit.runner.RunWith;
     10 
     11 import static org.hamcrest.CoreMatchers.sameInstance;
     12 import static org.junit.Assert.assertThat;
     13 
     14 @RunWith(WithTestDefaultsRunner.class)
     15 public class ExpandableListViewTest {
     16 
     17     private Transcript transcript;
     18     private ExpandableListView expandableListView;
     19     private MyOnChildClickListener myOnChildClickListener;
     20 
     21     @Before
     22     public void setUp() {
     23         expandableListView = new ExpandableListView(null);
     24         transcript = new Transcript();
     25         myOnChildClickListener = new MyOnChildClickListener();
     26     }
     27 
     28     @Test
     29     public void testPerformItemClick_ShouldFireOnItemClickListener() throws Exception {
     30         expandableListView.setOnChildClickListener(myOnChildClickListener);
     31         expandableListView.performItemClick(null, 6, -1);
     32         transcript.assertEventsSoFar("item was clicked: 6");
     33     }
     34 
     35     @Test
     36     public void shouldTolerateNullChildClickListener() throws Exception {
     37         expandableListView.performItemClick(null, 6, -1);
     38     }
     39 
     40     @Test
     41     public void shouldPassTheViewToTheClickListener() throws Exception {
     42         expandableListView.setOnChildClickListener(myOnChildClickListener);
     43         expandableListView.performItemClick(null, 6, -1);
     44         assertThat(myOnChildClickListener.expandableListView, sameInstance(expandableListView));
     45     }
     46 
     47     private class MyOnChildClickListener implements ExpandableListView.OnChildClickListener {
     48         ExpandableListView expandableListView;
     49 
     50         @Override
     51         public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int position, long l) {
     52             this.expandableListView = expandableListView;
     53             transcript.add("item was clicked: " + position);
     54             return true;
     55         }
     56     }
     57 }
     58