X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FAlbumAccessorTest.java;h=28f6fd16d5770df56114485dca11bcfaa9b51cc8;hb=03cec6a6772c2d836d94864adddaf544cbe9d72f;hp=afc2a544bb1459e491cd7d28b5ad5b5b7337eb88;hpb=f229fe41f708d2b275c20ceb9aba5993761218a3;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java b/src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java
index afc2a54..28f6fd1 100644
--- a/src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java
+++ b/src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java
@@ -1,17 +1,24 @@
package net.pterodactylus.sone.template;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
-import net.pterodactylus.sone.TestUtil;
import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.test.TestUtil;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@@ -21,8 +28,6 @@ import org.junit.Test;
/**
* Unit test for {@link AlbumAccessor}.
- *
- * @author David âBombeâ Roden
*/
public class AlbumAccessorTest {
@@ -90,4 +95,25 @@ public class AlbumAccessorTest {
};
}
+ @Test
+ public void albumImageIsGeneratedRandomly() {
+ Image image = mock(Image.class);
+ List albumImages = Arrays.asList(mock(Image.class), image);
+ when(album.getImages()).thenReturn(albumImages);
+ int matchedImage = 0;
+ for (int i = 0; i < 1000; i++) {
+ Image randomImage = (Image) albumAccessor.get(null, album, "albumImage");
+ if (randomImage == image) {
+ matchedImage++;
+ }
+ }
+ assertThat(matchedImage, allOf(greaterThanOrEqualTo(250), lessThanOrEqualTo(750)));
+ }
+
+ @Test
+ public void albumImageIsNullIfThereAreNoImagesInAnAlbum() {
+ when(album.getImages()).thenReturn(Collections.emptyList());
+ assertThat(albumAccessor.get(null, album, "albumImage"), nullValue());
+ }
+
}