Add unit test for collection accessor.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 2 Nov 2014 10:33:27 +0000 (11:33 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 2 Nov 2014 10:33:27 +0000 (11:33 +0100)
src/test/java/net/pterodactylus/sone/template/CollectionAccessorTest.java [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/template/CollectionAccessorTest.java b/src/test/java/net/pterodactylus/sone/template/CollectionAccessorTest.java
new file mode 100644 (file)
index 0000000..d0e5057
--- /dev/null
@@ -0,0 +1,57 @@
+package net.pterodactylus.sone.template;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Sone;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link CollectionAccessor}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class CollectionAccessorTest {
+
+       private final CollectionAccessor accessor = new CollectionAccessor();
+       private final Collection<Object> collection = new ArrayList<Object>();
+
+       @Before
+       public void setupCollection() {
+               collection.add(new Object());
+               collection.add(createSone("One", "1.", "First"));
+               collection.add(new Object());
+               collection.add(createSone("Two", "2.", "Second"));
+       }
+
+       private Sone createSone(String firstName, String middleName,
+                       String lastName) {
+               Sone sone = mock(Sone.class);
+               Profile profile = new Profile(sone);
+               profile.setFirstName(firstName).setMiddleName(middleName).setLastName(
+                               lastName);
+               when(sone.getProfile()).thenReturn(profile);
+               return sone;
+       }
+
+       @Test
+       public void soneNamesAreConcatenatedCorrectly() {
+               assertThat(accessor.get(null, collection, "soneNames"),
+                               is((Object) "One 1. First, Two 2. Second"));
+       }
+
+       @Test
+       public void sizeIsReportedCorrectly() {
+               assertThat(accessor.get(null, collection, "size"),
+                               is((Object) Integer.valueOf(4)));
+       }
+
+}