+package net.pterodactylus.sone.template;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.Matchers.sameInstance;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import net.pterodactylus.util.template.Accessor;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link ListAccessorTest}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ListAccessorTest {
+
+ private final Accessor accessor = new ListAccessor();
+
+ @Test
+ public void gettingARandomElementFromAnEmptyListReturnsNull() {
+ assertThat(accessor.get(null, Collections.emptyList(), "random"), nullValue());
+ }
+
+ @Test
+ public void gettingARandomElementFromAListOfOneWillReturnTheOneElement() {
+ Object object = new Object();
+ assertThat(accessor.get(null, Arrays.asList(object), "random"), sameInstance(object));
+ }
+
+ @Test
+ public void gettingRandomElementsFromAListTwoElementsWillReturnBothWithSomeProportion() {
+ Object first = new Object();
+ Object second = new Object();
+ List<?> objects = Arrays.asList(first, second);
+ int gotFirst = 0;
+ for (int i = 0; i < 10000; i++) {
+ if (accessor.get(null, objects, "random") == first) {
+ gotFirst++;
+ }
+ }
+ assertThat(gotFirst, greaterThanOrEqualTo(4000));
+ }
+
+}