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