Add unit test for IdentityEvent and OwnIdentityEvent.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Nov 2013 21:42:02 +0000 (22:42 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:26:08 +0000 (22:26 +0100)
src/test/java/net/pterodactylus/sone/freenet/wot/event/IdentityEventTest.java [new file with mode: 0644]
src/test/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEventTest.java [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/freenet/wot/event/IdentityEventTest.java b/src/test/java/net/pterodactylus/sone/freenet/wot/event/IdentityEventTest.java
new file mode 100644 (file)
index 0000000..a11d233
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Sone - IdentityEventTest.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.freenet.wot.event;
+
+import static net.pterodactylus.sone.freenet.wot.Identities.createIdentity;
+import static net.pterodactylus.sone.freenet.wot.Identities.createOwnIdentity;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+
+import java.util.Collections;
+
+import net.pterodactylus.sone.freenet.wot.Identity;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class IdentityEventTest {
+
+       private final OwnIdentity ownIdentity = createOwnIdentity("O1", Collections.<String>emptyList(), Collections.<String, String>emptyMap());
+       private final Identity identity = createIdentity("I1", Collections.<String>emptyList(), Collections.<String, String>emptyMap());
+       private final IdentityEvent identityEvent = new TestIdentityEvent(ownIdentity, identity);
+
+       @Test
+       public void identityEventStoresAndReturnsIdentities() {
+               assertThat(identityEvent.ownIdentity(), is(ownIdentity));
+               assertThat(identityEvent.identity(), is(identity));
+       }
+
+       @Test
+       public void equalIdentityEventsHaveTheSameHashCode() {
+               IdentityEvent identityEvent = new TestIdentityEvent(ownIdentity, identity);
+               assertThat(identityEvent, is(this.identityEvent));
+               assertThat(identityEvent.hashCode(), is(this.identityEvent.hashCode()));
+       }
+
+       @Test
+       public void differentEventClassDoesNotMatch() {
+               IdentityEvent identityEvent = new IdentityEvent(ownIdentity, identity) {
+               };
+               assertThat(identityEvent, not(is(this.identityEvent)));
+       }
+
+       private static class TestIdentityEvent extends IdentityEvent {
+
+               protected TestIdentityEvent(OwnIdentity ownIdentity, Identity identity) {
+                       super(ownIdentity, identity);
+               }
+
+       }
+
+}
diff --git a/src/test/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEventTest.java b/src/test/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEventTest.java
new file mode 100644 (file)
index 0000000..49f16be
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Sone - OwnIdentityEventTest.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.freenet.wot.event;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+
+import java.util.Collections;
+
+import net.pterodactylus.sone.freenet.wot.Identities;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class OwnIdentityEventTest {
+
+       private final OwnIdentity ownIdentity = Identities.createOwnIdentity("O1", Collections.<String>emptyList(), Collections.<String, String>emptyMap());
+       private final OwnIdentityEvent ownIdentityEvent = new TestOwnIdentityEvent(ownIdentity);
+
+       @Test
+       public void ownIdentityEventStoresAndReturnsOwnIdentity() {
+               assertThat(ownIdentityEvent.ownIdentity(), is(ownIdentity));
+       }
+
+       @Test
+       public void equalIdentityEventsHashTheSameHashCode() {
+               OwnIdentityEvent ownIdentityEvent = new TestOwnIdentityEvent(ownIdentity);
+               assertThat(ownIdentityEvent, is(this.ownIdentityEvent));
+               assertThat(ownIdentityEvent.hashCode(), is(this.ownIdentityEvent.hashCode()));
+       }
+
+       @Test
+       public void differentEventClassDoesNotMatch() {
+               OwnIdentityEvent ownIdentityEvent = new OwnIdentityEvent(ownIdentity) {
+               };
+               assertThat(ownIdentityEvent, not(is(this.ownIdentityEvent)));
+       }
+
+       private static class TestOwnIdentityEvent extends OwnIdentityEvent {
+
+               protected TestOwnIdentityEvent(OwnIdentity ownIdentity) {
+                       super(ownIdentity);
+               }
+
+       }
+
+}