From 6132cd528d8b8a6e2a89a7520194a7ca46b0a4ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 22 Jul 2014 14:00:30 +0200 Subject: [PATCH] Add tests for identity events. --- .../sone/freenet/wot/event/IdentityEventTest.java | 54 ++++++++++++++++++++++ .../freenet/wot/event/OwnIdentityEventTest.java | 48 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 src/test/java/net/pterodactylus/sone/freenet/wot/event/IdentityEventTest.java create mode 100644 src/test/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEventTest.java 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()))); + } + +} -- 2.7.4