1 package net.pterodactylus.sone.data.impl;
3 import static org.mockito.Mockito.mock;
5 import net.pterodactylus.sone.data.Client;
6 import net.pterodactylus.sone.data.LocalSone;
7 import net.pterodactylus.sone.data.Sone;
8 import net.pterodactylus.sone.freenet.wot.Identity;
9 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
11 import org.junit.Test;
14 * Unit test for {@link AbstractSoneBuilder}.
16 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
18 public class AbstractSoneBuilderTest {
20 private final AbstractSoneBuilder soneBuilder = new AbstractSoneBuilder() {
22 public Sone build() throws IllegalStateException {
28 public LocalSone buildLocal() throws IllegalStateException {
33 private final Client client = new Client("Test Client", "1.0");
36 public void localSoneIsValidated() {
37 Identity ownIdentity = mock(OwnIdentity.class);
38 soneBuilder.from(ownIdentity).lastUpdated(1).using(client).buildLocal();
41 @Test(expected = IllegalStateException.class)
42 public void localSoneIsNotValidatedIfIdentityIsNotAnOwnIdentity() {
43 Identity identity = mock(Identity.class);
44 soneBuilder.from(identity).lastUpdated(1).using(client).buildLocal();
47 @Test(expected = IllegalStateException.class)
48 public void localSoneIsNotValidatedIfIdentityIsNull() {
49 soneBuilder.lastUpdated(1).using(client).buildLocal();
53 public void remoteSoneIsValidated() {
54 Identity identity = mock(Identity.class);
55 soneBuilder.from(identity).lastUpdated(1).using(client).build();
58 @Test(expected = IllegalStateException.class)
59 public void remoteSoneIsNotValidatedIfIdentityIsNull() {
60 soneBuilder.lastUpdated(1).using(client).build();
63 @Test(expected = IllegalStateException.class)
64 public void localSoneIsNotValidatedWithoutUpdateTime() {
65 Identity identity = mock(OwnIdentity.class);
66 soneBuilder.from(identity).using(client).buildLocal();
69 @Test(expected = IllegalStateException.class)
70 public void remoteSoneIsNotValidatedWithoutUpdateTime() {
71 Identity identity = mock(Identity.class);
72 soneBuilder.from(identity).using(client).build();
75 @Test(expected = IllegalStateException.class)
76 public void localSoneIsNotValidatedWithoutClient() {
77 Identity identity = mock(OwnIdentity.class);
78 soneBuilder.from(identity).lastUpdated(1L).buildLocal();
81 @Test(expected = IllegalStateException.class)
82 public void remoteSoneIsNotValidatedWithoutClient() {
83 Identity identity = mock(Identity.class);
84 soneBuilder.from(identity).lastUpdated(1L).build();