From: David ‘Bombe’ Roden Date: Thu, 14 Nov 2013 21:42:02 +0000 (+0100) Subject: Add unit test for IdentityEvent and OwnIdentityEvent. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9f23092d7f3820e31ff34f38bcf11fcc594ae645;p=Sone.git Add unit test for IdentityEvent and OwnIdentityEvent. --- 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..a11d233 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/freenet/wot/event/IdentityEventTest.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +public class IdentityEventTest { + + private final OwnIdentity ownIdentity = createOwnIdentity("O1", Collections.emptyList(), Collections.emptyMap()); + private final Identity identity = createIdentity("I1", Collections.emptyList(), Collections.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 index 0000000..49f16be --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEventTest.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +public class OwnIdentityEventTest { + + private final OwnIdentity ownIdentity = Identities.createOwnIdentity("O1", Collections.emptyList(), Collections.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); + } + + } + +}