From: David ‘Bombe’ Roden Date: Tue, 22 Jul 2014 12:00:30 +0000 (+0200) Subject: Add tests for identity events. X-Git-Tag: 0.9-rc1^2~3^2~210 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6132cd528d8b8a6e2a89a7520194a7ca46b0a4ce;p=Sone.git Add tests for identity events. --- 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 index 0000000..461e303 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/freenet/wot/event/IdentityEventTest.java @@ -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 David ‘Bombe’ Roden + */ +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 index 0000000..c4ec43b --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEventTest.java @@ -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 David ‘Bombe’ Roden + */ +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()))); + } + +}