ListeIteratorTest.java
01 package fr.isae.lists;
02 
03 import org.junit.*;
04 import static org.junit.Assert.*;
05 
06 /**
07  *  Unit Test for class ListeIterator. Use the following lists
08  *  for tests: <code>[]</code><code>[1]</code> and
09  *  <code>[1, 2, 3, 4, 5, 6, 7]</code><code>ListeChaineeIterable</code>
10  *  is used to provide lists.
11  *
12  *
13  * Created: Wed Nov  2 16:37:09 2011
14  *
15  @author <a href="mailto:garion@isae.fr">Christophe Garion</a>
16  @version 1.0
17  */
18 public class ListeIteratorTest {
19 
20     private ListeChaineeIterable el;
21     private ListeChaineeIterable ol;
22     private ListeChaineeIterable l;
23     private ListeIterator ei;
24     private ListeIterator oi;
25     private ListeIterator li;
26 
27     /**
28      * Setup for the tests.
29      */
30     @Before public void setUp() {
31         this.el = new ListeChaineeIterable();
32 
33         this.ol = new ListeChaineeIterable();
34         this.ol.ajouter(01);
35 
36         this.l = new ListeChaineeIterable();
37         for (int i = 0;  i < 7; i++) {
38             this.l.ajouter(i, i + 1);
39         }
40 
41         this.ei = new ListeIterator(this.el);
42         this.oi = new ListeIterator(this.ol);
43         this.li = new ListeIterator(this.l);
44     }
45 
46     /**
47      * Test method for constructor.
48      */
49     @Test public void testConstructor() {
50         assertEquals(1this.oi.next()0.0);
51         assertEquals(1this.li.next()0.0);
52     }
53 
54     /**
55      * Test method for hasNext with empty list.
56      */
57     @Test public void thasNextEmpty() {
58         assertFalse(this.ei.hasNext());
59     }
60 
61     /**
62      * Test method for hasNext with non-empty list.
63      */
64     @Test public void thasNextNonEmpty() {
65         assertTrue(this.oi.hasNext());
66         assertTrue(this.li.hasNext());
67     }
68 
69     /**
70      * Test method for next with one element list.
71      */
72     @Test public void testNextOne() {
73         this.oi.next();
74         assertFalse(this.oi.hasNext());
75     }
76 
77     /**
78      * Test method for next with list.
79      */
80     @Test public void testNext() {
81         for (int i = 0; i < 7; i++) {
82             assertTrue(this.li.hasNext());
83             this.li.next();
84         }
85         assertFalse(this.li.hasNext());
86     }
87 
88     /**
89      * Test method for next with list to verify if
90      * the element returned by method is correct.
91      */
92     @Test public void testNextReturn() {
93         for (int i = 0; i < 7; i++) {
94             assertEquals(i + 1this.li.next()0.0);
95         }
96     }
97 }