Setup core and web interface separately
[Sone.git] / src / test / java / net / pterodactylus / sone / template / CollectionAccessorTest.java
1 package net.pterodactylus.sone.template;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.is;
5 import static org.mockito.Mockito.mock;
6 import static org.mockito.Mockito.when;
7
8 import java.util.ArrayList;
9 import java.util.Collection;
10
11 import net.pterodactylus.sone.data.Profile;
12 import net.pterodactylus.sone.data.Sone;
13
14 import org.junit.Before;
15 import org.junit.Test;
16
17 /**
18  * Unit test for {@link CollectionAccessor}.
19  *
20  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
21  */
22 public class CollectionAccessorTest {
23
24         private final CollectionAccessor accessor = new CollectionAccessor();
25         private final Collection<Object> collection = new ArrayList<Object>();
26
27         @Before
28         public void setupCollection() {
29                 collection.add(new Object());
30                 collection.add(createSone("One", "1.", "First"));
31                 collection.add(new Object());
32                 collection.add(createSone("Two", "2.", "Second"));
33         }
34
35         private Sone createSone(String firstName, String middleName,
36                         String lastName) {
37                 Sone sone = mock(Sone.class);
38                 Profile profile = new Profile(sone);
39                 profile.setFirstName(firstName).setMiddleName(middleName).setLastName(
40                                 lastName);
41                 when(sone.getProfile()).thenReturn(profile);
42                 return sone;
43         }
44
45         @Test
46         public void soneNamesAreConcatenatedCorrectly() {
47                 assertThat(accessor.get(null, collection, "soneNames"),
48                                 is((Object) "One 1. First, Two 2. Second"));
49         }
50
51         @Test
52         public void sizeIsReportedCorrectly() {
53                 assertThat(accessor.get(null, collection, "size"),
54                                 is((Object) Integer.valueOf(4)));
55         }
56
57 }