1 package de.j32.jpim.data;
3 import static org.junit.Assert.assertEquals;
5 import org.junit.After;
6 import org.junit.Before;
9 import de.j32.jpim.data.Addressbook;
10 import de.j32.jpim.data.Attribute;
11 import de.j32.jpim.data.Entry;
12 import de.j32.jpim.data.EntryConsumer;
13 import de.j32.util.Util;
15 public class AddressbookTest
20 public void setUp() throws Exception
22 ab = new Addressbook();
26 public void tearDown() throws Exception
30 public final void testAdd()
32 Entry in = new Entry();
35 in.attribute("phone", "work", "+12 345 67890");
39 Entry out = Util.first(ab);
40 assertEquals(in.name(), out.name());
41 assertEquals(in.id(), out.id());
42 Attribute inattr = Util.first(in.attributes());
43 Attribute outattr = Util.first(out.attributes());
44 assertEquals(inattr.type, outattr.type);
45 assertEquals(inattr.rel, outattr.rel);
46 assertEquals(inattr.value, outattr.value);
47 assertEquals(inattr.index, outattr.index);
51 public final void testConsume()
53 Entry in = new Entry();
56 in.attribute("phone", "work", "+12 345 67890");
60 Entry out = Util.first(ab);
61 assertEquals(in.name(), out.name());
62 assertEquals(in.id(), out.id());
63 Attribute inattr = Util.first(in.attributes());
64 Attribute outattr = Util.first(out.attributes());
65 assertEquals(inattr.type, outattr.type);
66 assertEquals(inattr.rel, outattr.rel);
67 assertEquals(inattr.value, outattr.value);
68 assertEquals(inattr.index, outattr.index);
72 public final void testSendTo()
74 Entry in = new Entry();
77 in.attribute("phone", "work", "+12 345 67890");
80 final Entry[] out = { new Entry() };
81 ab.sendTo(new EntryConsumer() {
82 public void consume(Entry entry)
88 assertEquals(in.name(), out[0].name());
89 assertEquals(in.id(), out[0].id());
90 Attribute inattr = Util.first(in.attributes());
91 Attribute outattr = Util.first(out[0].attributes());
92 assertEquals(inattr.type, outattr.type);
93 assertEquals(inattr.rel, outattr.rel);
94 assertEquals(inattr.value, outattr.value);
95 assertEquals(inattr.index, outattr.index);
99 public final void testIterator()
101 Entry in = new Entry();
104 in.attribute("phone", "work", "+12 345 67890");
107 for (Entry out : ab) {
108 assertEquals(in.name(), out.name());
109 assertEquals(in.id(), out.id());
110 Attribute inattr = Util.first(in.attributes());
111 Attribute outattr = Util.first(out.attributes());
112 assertEquals(inattr.type, outattr.type);
113 assertEquals(inattr.rel, outattr.rel);
114 assertEquals(inattr.value, outattr.value);
115 assertEquals(inattr.index, outattr.index);