1/*
2 * Copyright (C) 2017 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 android.arch.paging;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertNull;
21import static org.junit.Assert.assertSame;
22
23import org.junit.Test;
24import org.junit.runner.RunWith;
25import org.junit.runners.JUnit4;
26
27import java.util.ArrayList;
28import java.util.Arrays;
29import java.util.List;
30
31@RunWith(JUnit4.class)
32public class NullPaddedListTest {
33    @Test
34    public void simple() {
35        List<String> data = Arrays.asList("A", "B", "C", "D", "E", "F");
36        NullPaddedList<String> list = new NullPaddedList<>(
37                2, data.subList(2, 4), 2);
38
39        assertNull(list.get(0));
40        assertNull(list.get(1));
41        assertSame(data.get(2), list.get(2));
42        assertSame(data.get(3), list.get(3));
43        assertNull(list.get(4));
44        assertNull(list.get(5));
45
46        assertEquals(6, list.size());
47        assertEquals(2, list.getLeadingNullCount());
48        assertEquals(2, list.getTrailingNullCount());
49    }
50
51    @Test(expected = IndexOutOfBoundsException.class)
52    public void getEmpty() {
53        NullPaddedList<String> list = new NullPaddedList<>(0, new ArrayList<String>(), 0);
54        list.get(0);
55    }
56
57    @Test(expected = IndexOutOfBoundsException.class)
58    public void getNegative() {
59        NullPaddedList<String> list = new NullPaddedList<>(0, Arrays.asList("a", "b"), 0);
60        list.get(-1);
61    }
62
63    @Test(expected = IndexOutOfBoundsException.class)
64    public void getPastEnd() {
65        NullPaddedList<String> list = new NullPaddedList<>(0, Arrays.asList("a", "b"), 0);
66        list.get(2);
67    }
68}
69