1 package org.columba.mail.parser; 2 3 import java.util.Enumeration ; 4 import java.util.List ; 5 import java.util.Vector ; 6 7 import javax.swing.ImageIcon ; 8 import javax.swing.tree.TreeNode ; 9 10 import junit.framework.TestCase; 11 12 import org.columba.addressbook.facade.ContactItem; 13 import org.columba.addressbook.facade.GroupItem; 14 import org.columba.addressbook.facade.HeaderItem; 15 import org.columba.addressbook.facade.IContactFacade; 16 import org.columba.addressbook.facade.IContactItem; 17 import org.columba.addressbook.facade.IFolder; 18 import org.columba.addressbook.facade.IFolderFacade; 19 import org.columba.addressbook.facade.IGroupItem; 20 import org.columba.addressbook.facade.IHeaderItem; 21 import org.columba.api.exception.StoreException; 22 import org.columba.core.facade.ServiceFacadeRegistry; 23 24 public class ListBuilderTest extends TestCase { 25 26 private IContactItem contact1; 27 28 private IContactItem contact2; 29 30 private IGroupItem group1; 31 32 private IGroupItem group2; 33 34 @Override 35 protected void setUp() throws Exception { 36 37 IContactFacade contactFacade = new MyContactFacade(); 38 IFolderFacade folderFacade = new MyFolderFacade(); 39 40 ServiceFacadeRegistry.getInstance().register(IContactFacade.class, 41 contactFacade); 42 ServiceFacadeRegistry.getInstance().register(IFolderFacade.class, 43 folderFacade); 44 45 contact1 = new ContactItem("0", "name1", "firstname1", "lastname1", 46 "name1@mail.org"); 47 contact2 = new ContactItem("1", "name2", "firstname2", "lastname2", 48 "name2@mail.org"); 49 50 group1 = new GroupItem("0", "groupname1", "description1"); 52 group1.addContact(contact1); 53 54 group2 = new GroupItem("1", "groupname2", "description2"); 56 group2.addContact(contact1); 57 group2.addContact(contact2); 58 } 59 60 63 public void testCreateFlatListWithNamesOnly() { 64 List <String > l = new Vector <String >(); 65 l.add("name1"); 66 l.add("name2"); 67 68 List <String > result = ListBuilder.createFlatList(l); 69 assertEquals("name1@mail.org", result.get(0)); 70 assertEquals("name2@mail.org", result.get(1)); 71 72 } 73 74 77 public void testCreateFlatListWithEmailAddressMixedIn() { 78 List <String > l = new Vector <String >(); 79 l.add("name1"); 80 l.add("name2@mail.org"); 81 82 List <String > result = ListBuilder.createFlatList(l); 83 assertEquals("name1@mail.org", result.get(0)); 84 assertEquals("name2@mail.org", result.get(1)); 85 86 } 87 88 92 public void testCreateFlatListWithGroups() { 93 List <String > l = new Vector <String >(); 94 l.add("groupname1"); 95 l.add("name2@mail.org"); 96 97 List <String > result = ListBuilder.createFlatList(l); 98 assertEquals("name1@mail.org", result.get(0)); 100 assertEquals("name2@mail.org", result.get(1)); 101 102 } 103 104 108 public void testCreateFlatListWithGroups2() { 109 List <String > l = new Vector <String >(); 110 l.add("groupname2"); 111 l.add("name2@mail.org"); 112 113 List <String > result = ListBuilder.createFlatList(l); 114 assertEquals("name1@mail.org", result.get(0)); 116 assertEquals("name2@mail.org", result.get(1)); 117 assertEquals("name2@mail.org", result.get(2)); 118 119 } 120 121 122 126 public void testCreateStringListFromItemList() { 127 128 List <IHeaderItem> l = new Vector <IHeaderItem>(); 129 IHeaderItem item1 = new HeaderItem(true); 130 item1.setName("name1"); 131 l.add(item1); 132 IHeaderItem item2 = new HeaderItem(true); 133 item2.setName("name2"); 134 l.add(item2); 135 136 List <String > result = ListBuilder.createStringListFromItemList(l); 137 assertEquals("name1", result.get(0)); 138 assertEquals("name2", result.get(1)); 139 } 140 141 class Folder implements IFolder { 143 Folder() { 144 145 } 146 147 public ImageIcon getIcon() { 148 return null; 149 } 150 151 public String getId() { 152 return "101"; 153 } 154 155 public String getName() { 156 return null; 157 } 158 159 public TreeNode getChildAt(int childIndex) { 160 return null; 161 } 162 163 public int getChildCount() { 164 return 0; 165 } 166 167 public TreeNode getParent() { 168 return null; 169 } 170 171 public int getIndex(TreeNode node) { 172 return 0; 173 } 174 175 public boolean getAllowsChildren() { 176 return false; 177 } 178 179 public boolean isLeaf() { 180 return false; 181 } 182 183 public Enumeration children() { 184 return null; 185 } 186 } 187 188 class MyFolderFacade implements IFolderFacade { 190 MyFolderFacade() { 191 192 } 193 194 public IFolder getFolder(String uid) { 195 return null; 196 } 197 198 public IFolder getCollectedAddresses() { 199 return null; 200 } 201 202 public IFolder getLocalAddressbook() { 203 return null; 204 } 205 206 public IFolder getFolderByName(String name) { 207 return null; 208 } 209 210 public List <IFolder> getAllFolders() { 211 List <IFolder> list = new Vector <IFolder>(); 212 IFolder f = new Folder(); 213 214 list.add(f); 215 216 return list; 217 } 218 219 public IFolder getRootFolder() { 220 return null; 221 } 222 } 223 224 class MyContactFacade implements IContactFacade { 227 MyContactFacade() { 228 229 } 230 231 public void addContact(String id, IContactItem contactItem) 232 throws StoreException, IllegalArgumentException { 233 234 } 235 236 public void addContacts(String id, IContactItem[] contactItem) 237 throws StoreException, IllegalArgumentException { 238 } 239 240 public void addContact(IContactItem contactItem) throws StoreException, 241 IllegalArgumentException { 242 243 } 244 245 public void addContacts(IContactItem[] contactItems) 246 throws StoreException, IllegalArgumentException { 247 248 } 249 250 public IContactItem getContactItem(String folderId, String contactId) 251 throws StoreException, IllegalArgumentException { 252 if (contactId.equals("0")) 253 return contact1; 254 else if (contactId.equals("1")) 255 return contact2; 256 return null; 257 } 258 259 public List <IHeaderItem> getAllHeaderItems(String folderId, 260 boolean flattenGroupItems) throws StoreException, 261 IllegalArgumentException { 262 return null; 263 } 264 265 public List <IContactItem> getAllContacts(String folderId) 266 throws StoreException, IllegalArgumentException { 267 return null; 268 } 269 270 public List <IGroupItem> getAllGroups(String folderId) 271 throws StoreException, IllegalArgumentException { 272 List <IGroupItem> list = new Vector <IGroupItem>(); 273 list.add(group1); 274 list.add(group2); 275 return list; 276 } 277 278 public String findByEmailAddress(String folderId, String emailAddress) 279 throws StoreException, IllegalArgumentException { 280 281 return null; 282 } 283 284 public String findByName(String folderId, String name) 285 throws StoreException, IllegalArgumentException { 286 if (name.equals("name1")) 287 return "0"; 288 else if (name.equals("name2")) 289 return "1"; 290 291 return null; 292 } 293 } 294 } 295 | Popular Tags |