Add tests for identity events.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jul 2014 12:00:30 +0000 (14:00 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jul 2014 12:00:30 +0000 (14:00 +0200)
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..461e303
--- /dev/null
@@ -0,0 +1,54 @@
+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 static org.mockito.Mockito.mock;
+
+import net.pterodactylus.sone.freenet.wot.Identity;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link IdentityEvent}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class IdentityEventTest {
+
+       private final OwnIdentity ownIdentity = mock(OwnIdentity.class);
+       private final Identity identity = mock(Identity.class);
+       private final IdentityEvent identityEvent = createIdentityEvent(ownIdentity, identity);
+
+       private IdentityEvent createIdentityEvent(final OwnIdentity ownIdentity, final Identity identity) {
+               return new IdentityEvent(ownIdentity, identity) {
+               };
+       }
+
+       @Test
+       public void identityEventRetainsIdentities() {
+               assertThat(identityEvent.ownIdentity(), is(ownIdentity));
+               assertThat(identityEvent.identity(), is(identity));
+       }
+
+       @Test
+       public void eventsWithTheSameIdentityHaveTheSameHashCode() {
+               IdentityEvent secondIdentityEvent = createIdentityEvent(ownIdentity, identity);
+               assertThat(identityEvent.hashCode(), is(secondIdentityEvent.hashCode()));
+       }
+
+       @Test
+       public void eventsWithTheSameIdentitiesAreEqual() {
+               IdentityEvent secondIdentityEvent = createIdentityEvent(ownIdentity, identity);
+               assertThat(identityEvent, is(secondIdentityEvent));
+               assertThat(secondIdentityEvent, is(identityEvent));
+       }
+
+       @Test
+       public void nullDoesNotEqualIdentityEvent() {
+               assertThat(identityEvent, not(is((Object) null)));
+       }
+
+
+}
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..c4ec43b
--- /dev/null
@@ -0,0 +1,48 @@
+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 static org.mockito.Mockito.mock;
+
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link OwnIdentityEvent}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class OwnIdentityEventTest {
+
+       private final OwnIdentity ownIdentity = mock(OwnIdentity.class);
+       private final OwnIdentityEvent ownIdentityEvent = createOwnIdentityEvent(ownIdentity);
+
+       @Test
+       public void eventRetainsOwnIdentity() {
+               assertThat(ownIdentityEvent.ownIdentity(), is(ownIdentity));
+       }
+
+       protected OwnIdentityEvent createOwnIdentityEvent(final OwnIdentity ownIdentity) {
+               return new OwnIdentityEvent(ownIdentity) {
+               };
+       }
+
+       @Test
+       public void twoOwnIdentityEventsWithTheSameIdentityHaveTheSameHashCode() {
+               OwnIdentityEvent secondOwnIdentityEvent = createOwnIdentityEvent(ownIdentity);
+               assertThat(secondOwnIdentityEvent.hashCode(), is(ownIdentityEvent.hashCode()));
+       }
+
+       @Test
+       public void ownIdentityEventDoesNotMatchNull() {
+               assertThat(ownIdentityEvent, not(is((Object) null)));
+       }
+
+       @Test
+       public void ownIdentityEventDoesNotMatchObjectWithADifferentClass() {
+               assertThat(ownIdentityEvent, not(is(new Object())));
+       }
+
+}