1 package net.pterodactylus.sone.template;
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;
8 import java.util.ArrayList;
9 import java.util.Collection;
11 import net.pterodactylus.sone.data.Profile;
12 import net.pterodactylus.sone.data.Sone;
14 import org.junit.Before;
15 import org.junit.Test;
18 * Unit test for {@link CollectionAccessor}.
20 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
22 public class CollectionAccessorTest {
24 private final CollectionAccessor accessor = new CollectionAccessor();
25 private final Collection<Object> collection = new ArrayList<Object>();
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"));
35 private Sone createSone(String firstName, String middleName,
37 Sone sone = mock(Sone.class);
38 Profile profile = new Profile(sone);
39 profile.setFirstName(firstName).setMiddleName(middleName).setLastName(
41 when(sone.getProfile()).thenReturn(profile);
46 public void soneNamesAreConcatenatedCorrectly() {
47 assertThat(accessor.get(null, collection, "soneNames"),
48 is((Object) "One 1. First, Two 2. Second"));
52 public void sizeIsReportedCorrectly() {
53 assertThat(accessor.get(null, collection, "size"),
54 is((Object) Integer.valueOf(4)));