KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > co > jezuk > mango > RemoveIfTest


1 package uk.co.jezuk.mango;
2
3 import junit.framework.*;
4
5 import java.util.Collection JavaDoc;
6 import java.util.ArrayList JavaDoc;
7
8 public class RemoveIfTest extends TestCase
9 {
10   java.util.List JavaDoc list;
11
12   public RemoveIfTest(String JavaDoc name) { super(name); }
13   public static Test suite() { return new TestSuite(RemoveIfTest.class); }
14
15   protected void setUp()
16   {
17     list = new java.util.ArrayList JavaDoc();
18     for(int i = 0; i < 10; ++i)
19       list.add(new Integer JavaDoc(i));
20   } // setUp
21

22   public void test1()
23   {
24     Algorithms.removeIf(list, Bind.First(Predicates.LessThanEquals(), new Integer JavaDoc(7)));
25
26     assertEquals(7, list.size());
27     assertEquals(null, Algorithms.find(list, new Integer JavaDoc(7)));
28     assertEquals(null, Algorithms.find(list, new Integer JavaDoc(8)));
29     assertEquals(null, Algorithms.find(list, new Integer JavaDoc(9)));
30   } // test1
31

32   public void test2()
33   {
34     Algorithms.removeIf(list, 1, 5, Bind.First(Predicates.LessThanEquals(), new Integer JavaDoc(7)));
35
36     assertEquals(10, list.size());
37     assertEquals(list.get(7), Algorithms.find(list, new Integer JavaDoc(7)));
38   } // test2
39

40 } // RemoveIfTest
41
Popular Tags