Add test for reply sorter
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 31 Jul 2015 14:50:37 +0000 (16:50 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 31 Jul 2015 14:50:37 +0000 (16:50 +0200)
src/test/java/net/pterodactylus/sone/data/ReplyTest.java [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/data/ReplyTest.java b/src/test/java/net/pterodactylus/sone/data/ReplyTest.java
new file mode 100644 (file)
index 0000000..0410ac6
--- /dev/null
@@ -0,0 +1,35 @@
+package net.pterodactylus.sone.data;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+/**
+ * Unit test for the static elements in {@link Reply}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ReplyTest {
+
+       @Test
+       public void comparatorSortsRepliesCorrectly() {
+               Reply<?> reply1 = mock(Reply.class);
+               when(reply1.getTime()).thenReturn(3000L);
+               Reply<?> reply2 = mock(Reply.class);
+               when(reply2.getTime()).thenReturn(2000L);
+               Reply<?> reply3 = mock(Reply.class);
+               when(reply3.getTime()).thenReturn(1000L);
+               List<Reply<?>> replies = new ArrayList<Reply<?>>(Arrays.<Reply<?>>asList(reply1, reply2, reply3));
+               Collections.sort(replies, Reply.TIME_COMPARATOR);
+               assertThat(replies, Matchers.<Reply<?>>contains(reply3, reply2, reply1));
+       }
+
+}