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