1 package net.pterodactylus.sone.template;
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
5 import static org.hamcrest.Matchers.nullValue;
6 import static org.hamcrest.Matchers.sameInstance;
8 import java.util.Arrays;
9 import java.util.Collections;
10 import java.util.List;
12 import net.pterodactylus.util.template.Accessor;
14 import org.junit.Test;
17 * Unit test for {@link ListAccessorTest}.
19 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
21 public class ListAccessorTest {
23 private final Accessor accessor = new ListAccessor();
26 public void gettingARandomElementFromAnEmptyListReturnsNull() {
27 assertThat(accessor.get(null, Collections.emptyList(), "random"), nullValue());
31 public void gettingARandomElementFromAListOfOneWillReturnTheOneElement() {
32 Object object = new Object();
33 assertThat(accessor.get(null, Arrays.asList(object), "random"), sameInstance(object));
37 public void gettingRandomElementsFromAListTwoElementsWillReturnBothWithSomeProportion() {
38 Object first = new Object();
39 Object second = new Object();
40 List<?> objects = Arrays.asList(first, second);
42 for (int i = 0; i < 10000; i++) {
43 if (accessor.get(null, objects, "random") == first) {
47 assertThat(gotFirst, greaterThanOrEqualTo(4000));