1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
19   */
20  
21  package org.onemind.commons.java.datastructure;
22  
23  import java.util.List;
24  import junit.framework.TestCase;
25  import org.onemind.commons.java.datastructure.CounterQueue;
26  /***
27   * The test for counter queue
28   * @author TiongHiang Lee (thlee@onemindsoft.org)
29   * @version $Id: CounterQueueTest.java,v 1.2 2004/08/26 12:33:09 thlee Exp $ $Name:  $
30   */
31  public class CounterQueueTest extends TestCase
32  {
33  
34      public void testCounterQueue()
35      {
36          CounterQueue cq = new CounterQueue();
37          Object counter = new Object();
38          Object queuer1 = new Object();
39          Object queuer2 = new Object();
40          //just check for random counter object
41          assertEquals(cq.getQueue(new Object()).size(), 0);
42          //adding
43          cq.addToQueue(counter, queuer1);
44          cq.addToQueue(counter, queuer2);
45          //just check for random counter object
46          assertEquals(cq.getQueue(new Object()).size(), 0);
47          //test added result
48          List l = cq.getQueue(counter);
49          assertEquals(l.size(), 2);
50          assertEquals(l.get(0), queuer1);
51          assertEquals(l.get(1), queuer2);
52          //test remove next from queue
53          assertEquals(cq.removeNextFromQueue(counter), queuer1);
54          assertEquals(l.size(), 1);
55          //test remove from queuer
56          cq.removeFromQueue(counter, queuer2);
57          assertEquals(l.size(), 0);
58      }
59  }