From 17c2b314e99eaa31c9f6e6e3bcc5035b3ff41a2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 2 Nov 2014 11:33:27 +0100 Subject: [PATCH] Add unit test for collection accessor. --- .../sone/template/CollectionAccessorTest.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/java/net/pterodactylus/sone/template/CollectionAccessorTest.java 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 index 0000000..d0e5057 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/template/CollectionAccessorTest.java @@ -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 David ‘Bombe’ Roden + */ +public class CollectionAccessorTest { + + private final CollectionAccessor accessor = new CollectionAccessor(); + private final Collection collection = new ArrayList(); + + @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))); + } + +} -- 2.7.4