X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fj32%2Fjpim%2Fdata%2FAddressbookTest.java;fp=src%2Ftest%2Fjava%2Fde%2Fj32%2Fjpim%2Fdata%2FAddressbookTest.java;h=f024bb4bdac53e736292953ab177566df14cf622;hb=4c31953ffe274db62393de67740de5df70b06d33;hp=0000000000000000000000000000000000000000;hpb=5ac05364dc652686046f01849b810da6ffef1192;p=jpim.git diff --git a/src/test/java/de/j32/jpim/data/AddressbookTest.java b/src/test/java/de/j32/jpim/data/AddressbookTest.java new file mode 100644 index 0000000..f024bb4 --- /dev/null +++ b/src/test/java/de/j32/jpim/data/AddressbookTest.java @@ -0,0 +1,119 @@ +package de.j32.jpim.data; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import de.j32.jpim.data.Addressbook; +import de.j32.jpim.data.Attribute; +import de.j32.jpim.data.Entry; +import de.j32.jpim.data.EntryConsumer; +import de.j32.util.Util; + +public class AddressbookTest +{ + Addressbook ab; + + @Before + public void setUp() throws Exception + { + ab = new Addressbook(); + } + + @After + public void tearDown() throws Exception + {} + + @Test + public final void testAdd() + { + Entry in = new Entry(); + in.name("John Doe"); + in.id(123); + in.attribute("phone", "work", "+12 345 67890"); + + ab.add(in); + + Entry out = Util.first(ab); + assertEquals(in.name(), out.name()); + assertEquals(in.id(), out.id()); + Attribute inattr = Util.first(in.attributes()); + Attribute outattr = Util.first(out.attributes()); + assertEquals(inattr.type, outattr.type); + assertEquals(inattr.rel, outattr.rel); + assertEquals(inattr.value, outattr.value); + assertEquals(inattr.index, outattr.index); + } + + @Test + public final void testConsume() + { + Entry in = new Entry(); + in.name("John Doe"); + in.id(124); + in.attribute("phone", "work", "+12 345 67890"); + + ab.consume(in); + + Entry out = Util.first(ab); + assertEquals(in.name(), out.name()); + assertEquals(in.id(), out.id()); + Attribute inattr = Util.first(in.attributes()); + Attribute outattr = Util.first(out.attributes()); + assertEquals(inattr.type, outattr.type); + assertEquals(inattr.rel, outattr.rel); + assertEquals(inattr.value, outattr.value); + assertEquals(inattr.index, outattr.index); + } + + @Test + public final void testSendTo() + { + Entry in = new Entry(); + in.name("John Doe"); + in.id(125); + in.attribute("phone", "work", "+12 345 67890"); + ab.add(in); + + final Entry[] out = { new Entry() }; + ab.sendTo(new EntryConsumer() { + public void consume(Entry entry) + { + out[0] = entry; + } + }); + + assertEquals(in.name(), out[0].name()); + assertEquals(in.id(), out[0].id()); + Attribute inattr = Util.first(in.attributes()); + Attribute outattr = Util.first(out[0].attributes()); + assertEquals(inattr.type, outattr.type); + assertEquals(inattr.rel, outattr.rel); + assertEquals(inattr.value, outattr.value); + assertEquals(inattr.index, outattr.index); + } + + @Test + public final void testIterator() + { + Entry in = new Entry(); + in.name("John Doe"); + in.id(126); + in.attribute("phone", "work", "+12 345 67890"); + ab.add(in); + + for (Entry out : ab) { + assertEquals(in.name(), out.name()); + assertEquals(in.id(), out.id()); + Attribute inattr = Util.first(in.attributes()); + Attribute outattr = Util.first(out.attributes()); + assertEquals(inattr.type, outattr.type); + assertEquals(inattr.rel, outattr.rel); + assertEquals(inattr.value, outattr.value); + assertEquals(inattr.index, outattr.index); + } + } + +}