1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 6 package org.mockito.internal.util.collections; 7 8 import org.assertj.core.api.Assertions; 9 import org.junit.Test; 10 import org.mockito.internal.util.collections.ListUtil.Filter; 11 import org.mockitoutil.TestBase; 12 13 import java.util.LinkedList; 14 import java.util.List; 15 16 import static java.util.Arrays.asList; 17 import static junit.framework.TestCase.assertTrue; 18 19 public class ListUtilTest extends TestBase { 20 21 @Test shouldFilterList()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 shouldReturnEmptyIfEmptyListGiven()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