• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.widget.cts;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertNull;
23 import static org.junit.Assert.assertSame;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.any;
27 import static org.mockito.Mockito.eq;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.reset;
30 import static org.mockito.Mockito.times;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.verifyZeroInteractions;
33 
34 import android.app.Instrumentation;
35 import android.content.Context;
36 import android.database.DataSetObserver;
37 import android.graphics.Canvas;
38 import android.graphics.drawable.BitmapDrawable;
39 import android.graphics.drawable.Drawable;
40 import android.os.Parcelable;
41 import android.util.AttributeSet;
42 import android.util.Xml;
43 import android.view.LayoutInflater;
44 import android.view.View;
45 import android.view.ViewGroup;
46 import android.view.accessibility.AccessibilityNodeInfo;
47 import android.widget.AbsListView;
48 import android.widget.ExpandableListAdapter;
49 import android.widget.ExpandableListView;
50 import android.widget.ListAdapter;
51 import android.widget.TextView;
52 import android.widget.cts.util.ExpandableListScenario;
53 
54 import androidx.test.InstrumentationRegistry;
55 import androidx.test.annotation.UiThreadTest;
56 import androidx.test.filters.MediumTest;
57 import androidx.test.rule.ActivityTestRule;
58 import androidx.test.runner.AndroidJUnit4;
59 
60 import com.android.compatibility.common.util.ApiTest;
61 import com.android.compatibility.common.util.WidgetTestUtils;
62 import com.android.compatibility.common.util.WindowUtil;
63 
64 import org.junit.Before;
65 import org.junit.Rule;
66 import org.junit.Test;
67 import org.junit.runner.RunWith;
68 import org.xmlpull.v1.XmlPullParser;
69 
70 @MediumTest
71 @RunWith(AndroidJUnit4.class)
72 public class ExpandableListViewTest {
73     private Instrumentation mInstrumentation;
74     private ExpandableListScenario mActivity;
75     private ExpandableListView mExpandableListView;
76 
77     @Rule
78     public ActivityTestRule<ExpandableList> mActivityRule =
79             new ActivityTestRule<>(ExpandableList.class);
80 
81     @Before
setup()82     public void setup() {
83         mInstrumentation = InstrumentationRegistry.getInstrumentation();
84         mActivity = mActivityRule.getActivity();
85         WindowUtil.waitForFocus(mActivity);
86         mExpandableListView = mActivity.getExpandableListView();
87     }
88 
89     @Test
testConstructor()90     public void testConstructor() {
91         new ExpandableListView(mActivity);
92 
93         new ExpandableListView(mActivity, null);
94 
95         new ExpandableListView(mActivity, null, android.R.attr.expandableListViewStyle);
96 
97         new ExpandableListView(mActivity, null, 0,
98                 android.R.style.Widget_DeviceDefault_ExpandableListView);
99 
100         new ExpandableListView(mActivity, null, 0,
101                 android.R.style.Widget_DeviceDefault_Light_ExpandableListView);
102 
103         new ExpandableListView(mActivity, null, 0,
104                 android.R.style.Widget_Material_ExpandableListView);
105 
106         new ExpandableListView(mActivity, null, 0,
107                 android.R.style.Widget_Material_Light_ExpandableListView);
108 
109         XmlPullParser parser =
110                 mActivity.getResources().getXml(R.layout.expandablelistview_layout);
111         AttributeSet attrs = Xml.asAttributeSet(parser);
112         new ExpandableListView(mActivity, attrs);
113         new ExpandableListView(mActivity, attrs, 0);
114     }
115 
116     @Test(expected=NullPointerException.class)
testConstructorWithNullContext1()117     public void testConstructorWithNullContext1() {
118         new ExpandableListView(null);
119     }
120 
121     @Test(expected=NullPointerException.class)
testConstructorWithNullContext2()122     public void testConstructorWithNullContext2() {
123         new ExpandableListView(null, null);
124     }
125 
126     @Test(expected=NullPointerException.class)
testConstructorWithNullContext3()127     public void testConstructorWithNullContext3() {
128         new ExpandableListView(null, null, 0);
129     }
130 
131     @Test
testSetChildDivider()132     public void testSetChildDivider() {
133         Drawable drawable = mActivity.getResources().getDrawable(R.drawable.scenery);
134         mExpandableListView.setChildDivider(drawable);
135     }
136 
137     @Test(expected=RuntimeException.class)
testSetAdapterOfWrongType()138     public void testSetAdapterOfWrongType() {
139         mExpandableListView.setAdapter((ListAdapter) null);
140     }
141 
142     @UiThreadTest
143     @Test
testGetAdapter()144     public void testGetAdapter() {
145         assertNull(mExpandableListView.getAdapter());
146 
147         ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter();
148         mExpandableListView.setAdapter(expandableAdapter);
149         assertNotNull(mExpandableListView.getAdapter());
150     }
151 
152     @UiThreadTest
153     @Test
testAccessExpandableListAdapter()154     public void testAccessExpandableListAdapter() {
155         ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter();
156 
157         assertNull(mExpandableListView.getExpandableListAdapter());
158         mExpandableListView.setAdapter(expandableAdapter);
159         assertSame(expandableAdapter, mExpandableListView.getExpandableListAdapter());
160     }
161 
162     @UiThreadTest
163     @Test
testPerformItemClick()164     public void testPerformItemClick() {
165         assertFalse(mExpandableListView.performItemClick(null, 100, 99));
166 
167         ExpandableListView.OnItemClickListener mockOnItemClickListener =
168                 mock(ExpandableListView.OnItemClickListener.class);
169         mExpandableListView.setOnItemClickListener(mockOnItemClickListener);
170         assertTrue(mExpandableListView.performItemClick(null, 100, 99));
171         verify(mockOnItemClickListener, times(1)).onItemClick(eq(mExpandableListView),
172                 any(), eq(100), eq(99L));
173     }
174 
175     @Test
testSetOnItemClickListener()176     public void testSetOnItemClickListener() {
177         ExpandableListView.OnItemClickListener mockOnItemClickListener =
178                 mock(ExpandableListView.OnItemClickListener.class);
179 
180         assertNull(mExpandableListView.getOnItemClickListener());
181         mExpandableListView.setOnItemClickListener(mockOnItemClickListener);
182         assertSame(mockOnItemClickListener, mExpandableListView.getOnItemClickListener());
183     }
184 
185     @UiThreadTest
186     @ApiTest(apis = {"android.widget.ExpandableListView#onInitializeAccessibilityNodeInfoForItem"})
187     @Test
testOnInitializeAccessibilityNodeInfoForItem()188     public void testOnInitializeAccessibilityNodeInfoForItem() {
189         ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter();
190         mExpandableListView.setAdapter(expandableAdapter);
191 
192         // Need a real view to be used in super.onInitializeAccessibilityNodeInfoForItem method.
193         TextView group = new TextView(mActivity);
194         final AbsListView.LayoutParams layoutParams =
195                 new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
196                         ViewGroup.LayoutParams.WRAP_CONTENT);
197         group.setLayoutParams(layoutParams);
198 
199         assertTrue(mExpandableListView.expandGroup(0));
200         AccessibilityNodeInfo expandedGroupInfo = new AccessibilityNodeInfo();
201         mExpandableListView.onInitializeAccessibilityNodeInfoForItem(group, 0, expandedGroupInfo);
202         assertTrue(expandedGroupInfo.getActionList().contains(
203                 AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE));
204 
205         assertTrue(mExpandableListView.collapseGroup(0));
206         AccessibilityNodeInfo collapseGroupInfo = new AccessibilityNodeInfo();
207         mExpandableListView.onInitializeAccessibilityNodeInfoForItem(group, 0, collapseGroupInfo);
208         assertTrue(collapseGroupInfo.getActionList().contains(
209                 AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND));
210     }
211 
212     @UiThreadTest
213     @Test
testExpandGroup()214     public void testExpandGroup() {
215         ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter();
216         mExpandableListView.setAdapter(expandableAdapter);
217 
218         ExpandableListView.OnGroupExpandListener mockOnGroupExpandListener =
219                 mock(ExpandableListView.OnGroupExpandListener.class);
220         mExpandableListView.setOnGroupExpandListener(mockOnGroupExpandListener);
221 
222         verifyZeroInteractions(mockOnGroupExpandListener);
223 
224         assertTrue(mExpandableListView.expandGroup(0));
225         verify(mockOnGroupExpandListener, times(1)).onGroupExpand(0);
226         assertTrue(mExpandableListView.isGroupExpanded(0));
227 
228         reset(mockOnGroupExpandListener);
229         assertFalse(mExpandableListView.expandGroup(0));
230         verify(mockOnGroupExpandListener, times(1)).onGroupExpand(0);
231         assertTrue(mExpandableListView.isGroupExpanded(0));
232 
233         reset(mockOnGroupExpandListener);
234         assertTrue(mExpandableListView.expandGroup(1));
235         verify(mockOnGroupExpandListener, times(1)).onGroupExpand(1);
236         assertTrue(mExpandableListView.isGroupExpanded(1));
237 
238         reset(mockOnGroupExpandListener);
239         assertFalse(mExpandableListView.expandGroup(1));
240         verify(mockOnGroupExpandListener, times(1)).onGroupExpand(1);
241         assertTrue(mExpandableListView.isGroupExpanded(1));
242 
243         reset(mockOnGroupExpandListener);
244         mExpandableListView.setAdapter((ExpandableListAdapter) null);
245         try {
246             mExpandableListView.expandGroup(0);
247             fail("should throw NullPointerException");
248         } catch (NullPointerException e) {
249         }
250     }
251 
252     @Test
testExpandGroupSmooth()253     public void testExpandGroupSmooth() throws Throwable {
254         mActivityRule.runOnUiThread(
255                 () -> mExpandableListView.setAdapter(new MockExpandableListAdapter()));
256 
257         ExpandableListView.OnGroupExpandListener mockOnGroupExpandListener =
258                 mock(ExpandableListView.OnGroupExpandListener.class);
259         mExpandableListView.setOnGroupExpandListener(mockOnGroupExpandListener);
260 
261         verifyZeroInteractions(mockOnGroupExpandListener);
262         WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mExpandableListView,
263                 () -> assertTrue(mExpandableListView.expandGroup(0, true)));
264         verify(mockOnGroupExpandListener, times(1)).onGroupExpand(0);
265         assertTrue(mExpandableListView.isGroupExpanded(0));
266 
267         reset(mockOnGroupExpandListener);
268         WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mExpandableListView,
269                 () -> assertFalse(mExpandableListView.expandGroup(0, true)));
270         verify(mockOnGroupExpandListener, times(1)).onGroupExpand(0);
271         assertTrue(mExpandableListView.isGroupExpanded(0));
272 
273         reset(mockOnGroupExpandListener);
274         WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mExpandableListView,
275                 () -> assertTrue(mExpandableListView.expandGroup(1, true)));
276         verify(mockOnGroupExpandListener, times(1)).onGroupExpand(1);
277         assertTrue(mExpandableListView.isGroupExpanded(1));
278 
279         reset(mockOnGroupExpandListener);
280         WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mExpandableListView,
281                 () -> assertFalse(mExpandableListView.expandGroup(1, true)));
282         verify(mockOnGroupExpandListener, times(1)).onGroupExpand(1);
283         assertTrue(mExpandableListView.isGroupExpanded(1));
284 
285         reset(mockOnGroupExpandListener);
286         mActivityRule.runOnUiThread(() -> {
287             mExpandableListView.setAdapter((ExpandableListAdapter) null);
288             try {
289                 mExpandableListView.expandGroup(0);
290                 fail("should throw NullPointerException");
291             } catch (NullPointerException e) {
292             }
293         });
294     }
295 
296     @UiThreadTest
297     @Test
testCollapseGroup()298     public void testCollapseGroup() {
299         ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter();
300         mExpandableListView.setAdapter(expandableAdapter);
301 
302         ExpandableListView.OnGroupCollapseListener mockOnGroupCollapseListener =
303                 mock(ExpandableListView.OnGroupCollapseListener.class);
304         mExpandableListView.setOnGroupCollapseListener(mockOnGroupCollapseListener);
305 
306         verifyZeroInteractions(mockOnGroupCollapseListener);
307         assertFalse(mExpandableListView.collapseGroup(0));
308         verify(mockOnGroupCollapseListener, times(1)).onGroupCollapse(0);
309         assertFalse(mExpandableListView.isGroupExpanded(0));
310 
311         reset(mockOnGroupCollapseListener);
312         mExpandableListView.expandGroup(0);
313         assertTrue(mExpandableListView.collapseGroup(0));
314         verify(mockOnGroupCollapseListener, times(1)).onGroupCollapse(0);
315         assertFalse(mExpandableListView.isGroupExpanded(0));
316 
317         reset(mockOnGroupCollapseListener);
318         assertFalse(mExpandableListView.collapseGroup(1));
319         verify(mockOnGroupCollapseListener, times(1)).onGroupCollapse(1);
320         assertFalse(mExpandableListView.isGroupExpanded(1));
321 
322         reset(mockOnGroupCollapseListener);
323         mExpandableListView.setAdapter((ExpandableListAdapter) null);
324         try {
325             mExpandableListView.collapseGroup(0);
326             fail("should throw NullPointerException");
327         } catch (NullPointerException e) {
328         }
329     }
330 
331     @UiThreadTest
332     @Test
testSetOnGroupClickListener()333     public void testSetOnGroupClickListener() {
334         mExpandableListView.setAdapter(new MockExpandableListAdapter());
335 
336         ExpandableListView.OnGroupClickListener mockOnGroupClickListener =
337                 mock(ExpandableListView.OnGroupClickListener.class);
338 
339         mExpandableListView.setOnGroupClickListener(mockOnGroupClickListener);
340         verifyZeroInteractions(mockOnGroupClickListener);
341 
342         mExpandableListView.performItemClick(null, 0, 0);
343         verify(mockOnGroupClickListener, times(1)).onGroupClick(eq(mExpandableListView),
344                 any(), eq(0), eq(0L));
345     }
346 
347     @UiThreadTest
348     @Test
testSetOnChildClickListener()349     public void testSetOnChildClickListener() {
350         mExpandableListView.setAdapter(new MockExpandableListAdapter());
351 
352         ExpandableListView.OnChildClickListener mockOnChildClickListener =
353                 mock(ExpandableListView.OnChildClickListener.class);
354 
355         mExpandableListView.setOnChildClickListener(mockOnChildClickListener);
356         verifyZeroInteractions(mockOnChildClickListener);
357 
358         // first let the list expand
359         mExpandableListView.expandGroup(0);
360         // click on the child list of the first group
361         mExpandableListView.performItemClick(null, 1, 0);
362         verify(mockOnChildClickListener, times(1)).onChildClick(eq(mExpandableListView),
363                 any(), eq(0), eq(0), eq(0L));
364     }
365 
366     @UiThreadTest
367     @Test
testGetExpandableListPosition()368     public void testGetExpandableListPosition() {
369         mExpandableListView.setAdapter(new MockExpandableListAdapter());
370 
371         assertEquals(0, mExpandableListView.getExpandableListPosition(0));
372 
373         // Group 0 is not expanded, position 1 is invalid
374         assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL,
375                 mExpandableListView.getExpandableListPosition(1));
376 
377         // Position 1 becomes valid when group 0 is expanded
378         mExpandableListView.expandGroup(0);
379         assertEquals(ExpandableListView.getPackedPositionForChild(0, 0),
380                 mExpandableListView.getExpandableListPosition(1));
381 
382         // Position 2 is still invalid (only one child).
383         assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL,
384                 mExpandableListView.getExpandableListPosition(2));
385     }
386 
387     @UiThreadTest
388     @Test
testGetFlatListPosition()389     public void testGetFlatListPosition() {
390         mExpandableListView.setAdapter(new MockExpandableListAdapter());
391 
392         try {
393             mExpandableListView.getFlatListPosition(ExpandableListView.PACKED_POSITION_VALUE_NULL);
394         } catch (NullPointerException e) {
395         }
396         assertEquals(1, mExpandableListView.getFlatListPosition(
397                 ((long) ExpandableListView.PACKED_POSITION_TYPE_CHILD)<<32L));
398         // 0x8000000100000000L means this is a child and group position is 1.
399         assertEquals(1, mExpandableListView.getFlatListPosition(0x8000000100000000L));
400     }
401 
402     @UiThreadTest
403     @Test
testGetSelectedPosition()404     public void testGetSelectedPosition() {
405         assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL,
406                 mExpandableListView.getSelectedPosition());
407 
408         mExpandableListView.setAdapter(new MockExpandableListAdapter());
409 
410         mExpandableListView.setSelectedGroup(0);
411         assertEquals(0, mExpandableListView.getSelectedPosition());
412 
413         mExpandableListView.setSelectedGroup(1);
414         assertEquals(0, mExpandableListView.getSelectedPosition());
415     }
416 
417     @UiThreadTest
418     @Test
testGetSelectedId()419     public void testGetSelectedId() {
420         assertEquals(-1, mExpandableListView.getSelectedId());
421         mExpandableListView.setAdapter(new MockExpandableListAdapter());
422 
423         mExpandableListView.setSelectedGroup(0);
424         assertEquals(0, mExpandableListView.getSelectedId());
425 
426         mExpandableListView.setSelectedGroup(1);
427         assertEquals(0, mExpandableListView.getSelectedId());
428     }
429 
430     @UiThreadTest
431     @Test
testSetSelectedGroup()432     public void testSetSelectedGroup() {
433         mExpandableListView.setAdapter(new MockExpandableListAdapter());
434 
435         mExpandableListView.setSelectedGroup(0);
436         assertEquals(0, mExpandableListView.getSelectedPosition());
437 
438         mExpandableListView.setSelectedGroup(1);
439         assertEquals(0, mExpandableListView.getSelectedPosition());
440     }
441 
442     @UiThreadTest
443     @Test
testSetSelectedChild()444     public void testSetSelectedChild() {
445         mExpandableListView.setAdapter(new MockExpandableListAdapter());
446 
447         assertTrue(mExpandableListView.setSelectedChild(0, 0, false));
448         assertTrue(mExpandableListView.setSelectedChild(0, 1, true));
449     }
450 
451     @UiThreadTest
452     @Test
testIsGroupExpanded()453     public void testIsGroupExpanded() {
454         mExpandableListView.setAdapter(new MockExpandableListAdapter());
455 
456         mExpandableListView.expandGroup(1);
457         assertFalse(mExpandableListView.isGroupExpanded(0));
458         assertTrue(mExpandableListView.isGroupExpanded(1));
459     }
460 
461     @Test
testGetPackedPositionType()462     public void testGetPackedPositionType() {
463         assertEquals(ExpandableListView.PACKED_POSITION_TYPE_NULL,
464                 ExpandableListView.getPackedPositionType(
465                         ExpandableListView.PACKED_POSITION_VALUE_NULL));
466 
467         assertEquals(ExpandableListView.PACKED_POSITION_TYPE_GROUP,
468                 ExpandableListView.getPackedPositionType(0));
469 
470         // 0x8000000000000000L is PACKED_POSITION_MASK_TYPE, but it is private,
471         // so we just use its value.
472         assertEquals(ExpandableListView.PACKED_POSITION_TYPE_CHILD,
473                 ExpandableListView.getPackedPositionType(0x8000000000000000L));
474     }
475 
476     @Test
testGetPackedPositionGroup()477     public void testGetPackedPositionGroup() {
478         assertEquals(-1, ExpandableListView.getPackedPositionGroup(
479                 ExpandableListView.PACKED_POSITION_VALUE_NULL));
480 
481         assertEquals(0, ExpandableListView.getPackedPositionGroup(0));
482 
483         // 0x123400000000L means its group position is 0x1234
484         assertEquals(0x1234, ExpandableListView.getPackedPositionGroup(0x123400000000L));
485 
486         // 0x7FFFFFFF00000000L means its group position is 0x7FFFFFFF
487         assertEquals(0x7FFFFFFF, ExpandableListView.getPackedPositionGroup(0x7FFFFFFF00000000L));
488     }
489 
490     @Test
testGetPackedPositionChild()491     public void testGetPackedPositionChild() {
492         assertEquals(-1, ExpandableListView.getPackedPositionChild(
493                 ExpandableListView.PACKED_POSITION_VALUE_NULL));
494 
495         assertEquals(-1, ExpandableListView.getPackedPositionChild(1));
496 
497         // 0x8000000000000000L means its child position is 0
498         assertEquals(0, ExpandableListView.getPackedPositionChild(0x8000000000000000L));
499 
500         // 0x80000000ffffffffL means its child position is 0xffffffff
501         assertEquals(0xffffffff, ExpandableListView.getPackedPositionChild(0x80000000ffffffffL));
502     }
503 
504     @Test
testGetPackedPositionForChild()505     public void testGetPackedPositionForChild() {
506         assertEquals(0x8000000000000000L,
507                 ExpandableListView.getPackedPositionForChild(0, 0));
508 
509         assertEquals(0xffffffffffffffffL,
510                 ExpandableListView.getPackedPositionForChild(Integer.MAX_VALUE, 0xffffffff));
511     }
512 
513     @Test
testGetPackedPositionForGroup()514     public void testGetPackedPositionForGroup() {
515         assertEquals(0, ExpandableListView.getPackedPositionForGroup(0));
516 
517         assertEquals(0x7fffffff00000000L,
518                 ExpandableListView.getPackedPositionForGroup(Integer.MAX_VALUE));
519     }
520 
521     @Test
testSetChildIndicator()522     public void testSetChildIndicator() {
523         mExpandableListView.setChildIndicator(null);
524     }
525 
526     @Test
testSetChildIndicatorBounds()527     public void testSetChildIndicatorBounds() {
528         mExpandableListView.setChildIndicatorBounds(10, 20);
529     }
530 
531     @Test
testSetChildIndicatorBoundsRelative()532     public void testSetChildIndicatorBoundsRelative() {
533         mExpandableListView.setChildIndicatorBoundsRelative(10, 20);
534     }
535 
536     @Test
testSetGroupIndicator()537     public void testSetGroupIndicator() {
538         Drawable drawable = new BitmapDrawable();
539         mExpandableListView.setGroupIndicator(drawable);
540     }
541 
542     @Test
testSetIndicatorBounds()543     public void testSetIndicatorBounds() {
544         mExpandableListView.setIndicatorBounds(10, 30);
545     }
546 
547     @Test
testSetIndicatorBoundsRelative()548     public void testSetIndicatorBoundsRelative() {
549         mExpandableListView.setIndicatorBoundsRelative(10, 30);
550     }
551 
552     @Test
testOnSaveInstanceState()553     public void testOnSaveInstanceState() {
554         ExpandableListView src = new ExpandableListView(mActivity);
555         Parcelable p1 = src.onSaveInstanceState();
556 
557         ExpandableListView dest = new ExpandableListView(mActivity);
558         dest.onRestoreInstanceState(p1);
559         Parcelable p2 = dest.onSaveInstanceState();
560 
561         assertNotNull(p1);
562         assertNotNull(p2);
563     }
564 
565     @Test
testDispatchDraw()566     public void testDispatchDraw() {
567         MockExpandableListView expandableListView = new MockExpandableListView(mActivity);
568         expandableListView.dispatchDraw(new Canvas());
569     }
570 
571     private class MockExpandableListAdapter implements ExpandableListAdapter {
572         private final LayoutInflater mLayoutInflater;
573 
MockExpandableListAdapter()574         public MockExpandableListAdapter() {
575             mLayoutInflater = LayoutInflater.from(mActivity);
576         }
577 
registerDataSetObserver(DataSetObserver observer)578         public void registerDataSetObserver(DataSetObserver observer) {
579         }
580 
unregisterDataSetObserver(DataSetObserver observer)581         public void unregisterDataSetObserver(DataSetObserver observer) {
582         }
583 
getGroupCount()584         public int getGroupCount() {
585             return 1;
586         }
587 
getChildrenCount(int groupPosition)588         public int getChildrenCount(int groupPosition) {
589             switch (groupPosition) {
590             case 0:
591                 return 1;
592             default:
593                 return 0;
594             }
595         }
596 
getGroup(int groupPosition)597         public Object getGroup(int groupPosition) {
598             switch (groupPosition) {
599             case 0:
600                 return "Data";
601             default:
602                 return null;
603             }
604         }
605 
getChild(int groupPosition, int childPosition)606         public Object getChild(int groupPosition, int childPosition) {
607             if (groupPosition == 0 && childPosition == 0)
608                 return "child data";
609             else
610                 return null;
611         }
612 
getGroupId(int groupPosition)613         public long getGroupId(int groupPosition) {
614             return 0;
615         }
616 
getChildId(int groupPosition, int childPosition)617         public long getChildId(int groupPosition, int childPosition) {
618             return 0;
619         }
620 
hasStableIds()621         public boolean hasStableIds() {
622             return true;
623         }
624 
getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)625         public View getGroupView(int groupPosition, boolean isExpanded,
626                 View convertView, ViewGroup parent) {
627             TextView result = (TextView) convertView;
628             if (result == null) {
629                 result = (TextView) mLayoutInflater.inflate(
630                         R.layout.expandablelistview_group, parent, false);
631             }
632             result.setText("Group " + groupPosition);
633             return result;
634         }
635 
getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)636         public View getChildView(int groupPosition, int childPosition,
637                 boolean isLastChild, View convertView, ViewGroup parent) {
638             TextView result = (TextView) convertView;
639             if (result == null) {
640                 result = (TextView) mLayoutInflater.inflate(
641                         R.layout.expandablelistview_child, parent, false);
642             }
643             result.setText("Child " + childPosition);
644             return result;
645         }
646 
isChildSelectable(int groupPosition, int childPosition)647         public boolean isChildSelectable(int groupPosition, int childPosition) {
648             return true;
649         }
650 
areAllItemsEnabled()651         public boolean areAllItemsEnabled() {
652             return true;
653         }
654 
isEmpty()655         public boolean isEmpty() {
656             return true;
657         }
658 
onGroupExpanded(int groupPosition)659         public void onGroupExpanded(int groupPosition) {
660         }
661 
onGroupCollapsed(int groupPosition)662         public void onGroupCollapsed(int groupPosition) {
663         }
664 
getCombinedChildId(long groupId, long childId)665         public long getCombinedChildId(long groupId, long childId) {
666             return 0;
667         }
668 
getCombinedGroupId(long groupId)669         public long getCombinedGroupId(long groupId) {
670             return 0;
671         }
672     }
673 
674     private class MockExpandableListView extends ExpandableListView {
MockExpandableListView(Context context)675         public MockExpandableListView(Context context) {
676             super(context);
677         }
678 
MockExpandableListView(Context context, AttributeSet attrs)679         public MockExpandableListView(Context context, AttributeSet attrs) {
680             super(context, attrs);
681         }
682 
MockExpandableListView(Context context, AttributeSet attrs, int defStyle)683         public MockExpandableListView(Context context, AttributeSet attrs, int defStyle) {
684             super(context, attrs, defStyle);
685         }
686 
687         @Override
dispatchDraw(Canvas canvas)688         protected void dispatchDraw(Canvas canvas) {
689             super.dispatchDraw(canvas);
690         }
691     }
692 }
693