001 package fr.isae.tags;
002
003 import org.junit.*;
004 import static org.junit.Assert.*;
005 import java.util.ArrayList;
006 import java.util.Date;
007
008 /**
009 * Unit Test for class Etiquette. It uses the data provided by
010 * <code>DataGenerator</code> class.
011 *
012 * <p>Created: Tue Nov 9 08:40:37 2010</p>
013 *
014 * @author <a href="mailto:garion@isae.fr">Christophe Garion</a>
015 * @version 1.0
016 */
017 public class EtiquetteTest {
018
019 private ArrayList<MarquePage> mps;
020 private ArrayList<Etiquette> tags;
021
022 /**
023 * Setup for the tests.
024 */
025 @Before public void setUp() {
026 this.mps = DataGenerator.generateMarquePages();
027 this.tags = DataGenerator.generateEtiquettes();
028 }
029
030 /**
031 * Test method for constructor if tag is root.
032 */
033 @Test public void testConstructeurRacine() {
034 assertNull(this.tags.get(0).getMere());
035 }
036
037 /**
038 * Test method for constructor if tag is not root. The tag must be
039 * added to the root's children list.
040 */
041 @Test public void testConstructeurNonRacine() {
042 assertSame(this.tags.get(0), this.tags.get(1).getMere());
043 assertSame(this.tags.get(0), this.tags.get(2).getMere());
044 assertSame(this.tags.get(2), this.tags.get(3).getMere());
045 assertSame(this.tags.get(2), this.tags.get(4).getMere());
046 assertSame(this.tags.get(3), this.tags.get(5).getMere());
047 assertSame(this.tags.get(3), this.tags.get(5).getMere());
048 }
049
050 /**
051 * Test method for getFilles when tag has children.
052 */
053 @Test public void testGetFillesWithChildren() {
054 ArrayList<Etiquette> filles = this.tags.get(3).getFilles();
055 assertEquals(2, filles.size());
056 assertSame(this.tags.get(5), filles.get(0));
057 assertSame(this.tags.get(6), filles.get(1));
058 }
059
060 /**
061 * Test method for getFilles when tag does not have children.
062 */
063 @Test public void testGetFillesWithoutChildren() {
064 ArrayList<Etiquette> filles = this.tags.get(5).getFilles();
065 assertEquals(0, filles.size());
066 }
067
068 /**
069 * Test method for getMarquePages when tag has bookmarks.
070 */
071 @Test public void testGetMarquePagesWithMP() {
072 ArrayList<MarquePage> mp = this.tags.get(5).getMarquePages();
073 assertEquals(3, mp.size());
074 assertSame(this.mps.get(3), mp.get(0));
075 assertSame(this.mps.get(4), mp.get(1));
076 assertSame(this.mps.get(5), mp.get(2));
077 }
078
079 /**
080 * Test method for getMarquePages when tag has no bookmark.
081 */
082 @Test public void testGetMarquePagesWithoutMP() {
083 ArrayList<MarquePage> mp = this.tags.get(1).getMarquePages();
084 assertEquals(0, mp.size());
085 }
086
087 /**
088 * Test method for ajouter.
089 */
090 @Test public void testAjouter() {
091 ArrayList<MarquePage> mpsAux = this.tags.get(0).getMarquePages();
092 int oldSize = mpsAux.size();
093 MarquePage mp = new MarquePage("SUPAERO", "http://www.supaero.fr", new Date());
094
095 this.tags.get(0).ajouter(mp);
096
097 assertEquals(oldSize + 1, mpsAux.size());
098 assertTrue(mpsAux.contains(mp));
099 assertSame(mp, mpsAux.get(0));
100 }
101
102 /**
103 * Test method for retirer when tags has bookmarks.
104 */
105 @Test public void testAjouterWithMP() {
106 ArrayList<MarquePage> mpsAux = this.tags.get(5).getMarquePages();
107 int oldSize = mpsAux.size();
108 MarquePage mpToRemove = this.mps.get(5);
109 ArrayList<MarquePage> oldMps = new ArrayList<MarquePage>();
110 for (MarquePage mp : mpsAux) {
111 if (mp != mpToRemove) {
112 oldMps.add(mp);
113 }
114 }
115
116 this.tags.get(5).retirer(mpToRemove);
117
118 assertEquals(oldSize - 1, mpsAux.size());
119 assertFalse(mpsAux.contains(mpToRemove));
120
121 for (MarquePage mp : oldMps) {
122 assertTrue(mpsAux.contains(mp));
123 }
124 }
125
126 /**
127 * Test method for retirer when tags has no bookmark.
128 */
129 @Test public void testAjouterWithoutMP() {
130 ArrayList<MarquePage> mpsAux = this.tags.get(0).getMarquePages();
131 MarquePage mpToRemove = this.mps.get(5);
132
133 this.tags.get(0).retirer(mpToRemove);
134
135 assertEquals(0, mpsAux.size());
136 assertFalse(mpsAux.contains(mpToRemove));
137 }
138 }
|