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
17package com.android.documentsui.selection;
18
19import static junit.framework.Assert.fail;
20
21import android.support.test.filters.SmallTest;
22import android.support.test.runner.AndroidJUnit4;
23
24import com.android.documentsui.dirlist.TestData;
25import com.android.documentsui.dirlist.TestDocumentsAdapter;
26import com.android.documentsui.selection.SelectionManager;
27import com.android.documentsui.testing.SelectionManagers;
28
29import org.junit.Before;
30import org.junit.Test;
31import org.junit.runner.RunWith;
32
33import java.util.List;
34
35@RunWith(AndroidJUnit4.class)
36@SmallTest
37public class SelectionManager_SingleSelectTest {
38
39    private static final List<String> ITEMS = TestData.create(100);
40
41    private SelectionManager mManager;
42    private TestSelectionListener mCallback;
43    private TestDocumentsAdapter mAdapter;
44    private SelectionProbe mSelection;
45
46    @Before
47    public void setUp() throws Exception {
48        mCallback = new TestSelectionListener();
49        mManager = SelectionManagers.createTestInstance(ITEMS, SelectionManager.MODE_SINGLE);
50        mManager.addCallback(mCallback);
51
52        mSelection = new SelectionProbe(mManager);
53    }
54
55    @Test
56    public void testSimpleSelect() {
57        mManager.toggleSelection(ITEMS.get(3));
58        mManager.toggleSelection(ITEMS.get(4));
59        mCallback.assertSelectionChanged();
60        mSelection.assertSelection(4);
61    }
62
63    @Test
64    public void testRangeSelectionNotEstablished() {
65        mManager.toggleSelection(ITEMS.get(3));
66        mCallback.reset();
67
68        try {
69            mManager.snapRangeSelection(10);
70            fail("Should have thrown.");
71        } catch (Exception expected) {}
72
73        mCallback.assertSelectionUnchanged();
74        mSelection.assertSelection(3);
75    }
76}
77