<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="tests"/>
<classpathentry kind="lib" path="libs/commons-logging/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="libs/commons-logging/commons-logging-adapters-1.1.1.jar"/>
<classpathentry kind="lib" path="libs/commons-logging/commons-logging-api-1.1.1.jar"/>
<classpathentry kind="lib" path="libs/spring/dist/org.springframework.web.portlet-3.0.4.RELEASE.jar"/>
<classpathentry kind="lib" path="libs/spring/dist/org.springframework.web.servlet-3.0.4.RELEASE.jar"/>
<classpathentry kind="lib" path="libs/spring/dist/org.springframework.web.struts-3.0.4.RELEASE.jar"/>
+ <classpathentry kind="lib" path="libs/junit/junit-4.8.2.jar"/>
+ <classpathentry kind="lib" path="libs/junit/junit-dep-4.8.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<property name="build" location="bin" />
<property name="main" value="de.j32.pimstuff.Main" />
<property name="lib" value="libs" />
-
+ <property name="test" value="tests" />
+
<target name="makedirs">
<mkdir dir="${build}" />
</target>
- <path id="classpath.lib">
+ <path id="classpath">
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</path>
-
+
+ <fileset id="tests" dir="${test}">
+ <include name="**/*.java" />
+ </fileset>
+
<target name="build" depends="makedirs" description="Compile project to ${build} directory">
- <javac srcdir="${src}" destdir="${build}" />
+ <javac srcdir="${src}" destdir="${build}" classpathref="classpath" />
</target>
<target name="clean" description="Clean up ${build} directory">
</target>
<target name="run" depends="build" description="Start main class">
- <java fork="true" classpath="${build}" classpathref="classpath.lib" classname="${main}" />
+ <java fork="true" classpath="${build}" classpathref="classpath" classname="${main}" />
+ </target>
+
+ <target name="build-tests" depends="build" description="Compile tests">
+ <javac srcdir="${test}" destdir="${build}" classpath="${build}" classpathref="classpath" />
+ </target>
+
+ <target name="test" depends="build-tests" description="Run JUnit tests">
+ <junit fork="true" printsummary="withOutAndErr" haltonerror="true">
+ <classpath>
+ <path refid="classpath" />
+ <pathelement path="${build}" />
+ <pathelement path="${test}" />
+ </classpath>
+ <batchtest>
+ <fileset refid="tests" />
+ </batchtest>
+ </junit>
</target>
</project>
--- /dev/null
+package de.j32.pimstuff.data;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+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);
+ }
+ }
+
+}