8c9e1a9e7b5b652fb9b23d0dfadd7cc5ecc56dde
[Sone.git] / src / test / java / net / pterodactylus / sone / data / impl / AbstractSoneBuilderTest.java
1 package net.pterodactylus.sone.data.impl;
2
3 import static org.mockito.Mockito.mock;
4
5 import net.pterodactylus.sone.data.Client;
6 import net.pterodactylus.sone.data.Sone;
7 import net.pterodactylus.sone.freenet.wot.Identity;
8 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
9
10 import org.junit.Test;
11
12 /**
13  * Unit test for {@link AbstractSoneBuilder}.
14  *
15  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
16  */
17 public class AbstractSoneBuilderTest {
18
19         private final AbstractSoneBuilder soneBuilder = new AbstractSoneBuilder() {
20                 @Override
21                 public Sone build() throws IllegalStateException {
22                         validate();
23                         return null;
24                 }
25         };
26         private final Client client = new Client("Test Client", "1.0");
27
28         @Test
29         public void localSoneIsValidated() {
30                 Identity ownIdentity = mock(OwnIdentity.class);
31                 soneBuilder.local().from(ownIdentity).lastUpdated(1).using(client).build();
32         }
33
34         @Test(expected = IllegalStateException.class)
35         public void localSoneIsNotValidatedIfIdentityIsNotAnOwnIdentity() {
36                 Identity identity = mock(Identity.class);
37                 soneBuilder.local().from(identity).lastUpdated(1).using(client).build();
38         }
39
40         @Test(expected = IllegalStateException.class)
41         public void localSoneIsNotValidatedIfIdentityIsNull() {
42                 soneBuilder.local().lastUpdated(1).using(client).build();
43         }
44
45         @Test
46         public void remoteSoneIsValidated() {
47                 Identity identity = mock(Identity.class);
48                 soneBuilder.from(identity).lastUpdated(1).using(client).build();
49         }
50
51         @Test(expected = IllegalStateException.class)
52         public void remoteSoneIsNotValidatedIfIdentityIsNull() {
53                 soneBuilder.lastUpdated(1).using(client).build();
54         }
55
56         @Test(expected = IllegalStateException.class)
57         public void localSoneIsNotValidatedWithoutUpdateTime() {
58                 Identity identity = mock(OwnIdentity.class);
59                 soneBuilder.from(identity).local().using(client).build();
60         }
61
62         @Test(expected = IllegalStateException.class)
63         public void remoteSoneIsNotValidatedWithoutUpdateTime() {
64                 Identity identity = mock(Identity.class);
65                 soneBuilder.from(identity).using(client).build();
66         }
67
68         @Test(expected = IllegalStateException.class)
69         public void localSoneIsNotValidatedWithoutClient() {
70                 Identity identity = mock(OwnIdentity.class);
71                 soneBuilder.from(identity).local().lastUpdated(1L).build();
72         }
73
74         @Test(expected = IllegalStateException.class)
75         public void remoteSoneIsNotValidatedWithoutClient() {
76                 Identity identity = mock(Identity.class);
77                 soneBuilder.from(identity).lastUpdated(1L).build();
78         }
79
80 }