ListUtilTest.java revision 2637d96c202372854a7c71466ddcc6e90fc4fc53
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5
6package org.mockito.internal.util.collections;
7
8import org.assertj.core.api.Assertions;
9import org.junit.Test;
10import org.mockito.internal.util.collections.ListUtil.Filter;
11import org.mockitoutil.TestBase;
12
13import java.util.LinkedList;
14import java.util.List;
15
16import static java.util.Arrays.asList;
17import static junit.framework.TestCase.assertTrue;
18
19public class ListUtilTest extends TestBase {
20
21    @Test
22    public void shouldFilterList() throws Exception {
23        List<String> list = asList("one", "x", "two", "x", "three");
24        List<String> filtered = ListUtil.filter(list, new Filter<String>() {
25            public boolean isOut(String object) {
26                return object == "x";
27            }
28        });
29
30        Assertions.assertThat(filtered).containsSequence("one", "two", "three");
31    }
32
33    @Test
34    public void shouldReturnEmptyIfEmptyListGiven() throws Exception {
35        List<Object> list = new LinkedList<Object>();
36        List<Object> filtered = ListUtil.filter(list, null);
37        assertTrue(filtered.isEmpty());
38    }
39}
40