• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 com.android.documentsui.selection;
18 
19 import static org.junit.Assert.fail;
20 
21 import android.support.test.filters.SmallTest;
22 import android.support.test.runner.AndroidJUnit4;
23 
24 import com.android.documentsui.selection.testing.SelectionPredicates;
25 import com.android.documentsui.selection.testing.SelectionProbe;
26 import com.android.documentsui.selection.testing.TestAdapter;
27 import com.android.documentsui.selection.testing.TestSelectionObserver;
28 import com.android.documentsui.selection.testing.TestStableIdProvider;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 
34 import java.util.List;
35 
36 @RunWith(AndroidJUnit4.class)
37 @SmallTest
38 public class DefaultSelectionHelper_SingleSelectTest {
39 
40     private List<String> mItems;
41     private SelectionHelper mHelper;
42     private TestSelectionObserver mListener;
43     private SelectionProbe mSelection;
44 
45     @Before
setUp()46     public void setUp() throws Exception {
47         mItems = TestAdapter.createItemList(100);
48         mListener = new TestSelectionObserver();
49         TestAdapter adapter = new TestAdapter();
50         adapter.updateTestModelIds(mItems);
51 
52         mHelper = new DefaultSelectionHelper(
53                 DefaultSelectionHelper.MODE_SINGLE,
54                 adapter,
55                 new TestStableIdProvider(adapter),
56                 SelectionPredicates.CAN_SET_ANYTHING);
57 
58         mHelper.addObserver(mListener);
59 
60         mSelection = new SelectionProbe(mHelper);
61     }
62 
63     @Test
testSimpleSelect()64     public void testSimpleSelect() {
65         mHelper.select(mItems.get(3));
66         mHelper.select(mItems.get(4));
67         mListener.assertSelectionChanged();
68         mSelection.assertSelection(4);
69     }
70 
71     @Test
testRangeSelectionNotEstablished()72     public void testRangeSelectionNotEstablished() {
73         mHelper.select(mItems.get(3));
74         mListener.reset();
75 
76         try {
77             mHelper.extendRange(10);
78             fail("Should have thrown.");
79         } catch (Exception expected) {}
80 
81         mListener.assertSelectionUnchanged();
82         mSelection.assertSelection(3);
83     }
84 }
85