aboutsummaryrefslogtreecommitdiff
path: root/juick-core/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-12-07 18:56:43 +0700
committerGravatar Vitaly Takmazov2016-12-07 22:37:17 +0300
commit69a5bdba32cdf0a48e51baa8c9fb28dca013f515 (patch)
tree678ca66ebd5e3c6e0e46f179542ff35fcf52c767 /juick-core/src/test/java/com
parentbad2718b1b85d806221fce52c76fa1d388993396 (diff)
message improvenments, checking for tag's duplicates
Diffstat (limited to 'juick-core/src/test/java/com')
-rw-r--r--juick-core/src/test/java/com/juick/MessageTest.java166
1 files changed, 166 insertions, 0 deletions
diff --git a/juick-core/src/test/java/com/juick/MessageTest.java b/juick-core/src/test/java/com/juick/MessageTest.java
new file mode 100644
index 00000000..a3d0a45b
--- /dev/null
+++ b/juick-core/src/test/java/com/juick/MessageTest.java
@@ -0,0 +1,166 @@
+package com.juick;
+
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+
+/**
+ * Created by aalexeev on 12/7/16.
+ */
+public class MessageTest {
+
+ @Test
+ public void equalsShouldBeReturnCorrectResult() throws Exception {
+ Message message1 = new Message();
+
+ Message message2 = new Message();
+ message2.setMid(RandomUtils.nextInt());
+
+ Message message3 = message1;
+
+ assertThat(message1, equalTo(message3));
+ assertThat(message3, equalTo(message1));
+
+ assertThat(message1, not(equalTo(message2)));
+ assertThat(message2, not(equalTo(message1)));
+
+ int id = RandomUtils.nextInt();
+ message1.setMid(id);
+ message2.setMid(id);
+
+ id = RandomUtils.nextInt();
+ message1.setRid(id);
+ message2.setRid(id);
+
+ assertThat(message1, equalTo(message2));
+ assertThat(message2, equalTo(message1));
+
+ message1.setMid(RandomUtils.nextInt());
+ message1.setRid(RandomUtils.nextInt());
+
+ message2.setMid(RandomUtils.nextInt());
+ message2.setRid(RandomUtils.nextInt());
+
+ assertThat(message1, not(equalTo(message2)));
+ assertThat(message2, not(equalTo(message1)));
+ }
+
+ @Test
+ public void compareShouldBeReturnCorrectResult() throws Exception {
+ Message message1 = new Message();
+
+ message1.setMid(RandomUtils.nextInt());
+ message1.setRid(RandomUtils.nextInt());
+
+ Message message2 = message1;
+
+ assertThat(message1.compareTo(message2), equalTo(0));
+ assertThat(message2.compareTo(message1), equalTo(0));
+
+ Message message3 = new Message();
+
+ message3.setMid(message1.getMid());
+ message3.setRid(message1.getRid());
+
+ assertThat(message1.compareTo(message3), equalTo(0));
+ assertThat(message3.compareTo(message1), equalTo(0));
+ }
+
+ @Test
+ public void messageWithGreaterMidShouldBeLessThenMesageWithLessMid() throws Exception {
+ Message message1 = new Message();
+
+ message1.setMid(RandomUtils.nextInt());
+ message1.setRid(RandomUtils.nextInt());
+
+ Message message2 = new Message();
+
+ message2.setMid(message1.getMid() + RandomUtils.nextInt(1, 10000));
+ message2.setRid(RandomUtils.nextInt());
+
+ assertThat(message1.compareTo(message2), equalTo(1));
+ assertThat(message2.compareTo(message1), equalTo(-1));
+ }
+
+ @Test
+ public void messageWithGreaterRidAndEqualsMidShouldBeGreaterThenMessageWithLessRid() throws Exception {
+ Message message1 = new Message();
+
+ message1.setMid(RandomUtils.nextInt());
+ message1.setRid(RandomUtils.nextInt());
+
+ Message message2 = new Message();
+
+ message2.setMid(message1.getMid());
+ message2.setRid(message1.getRid() + + RandomUtils.nextInt(1, 10000));
+
+ assertThat(message1.compareTo(message2), equalTo(-1));
+ assertThat(message2.compareTo(message1), equalTo(1));
+ }
+
+ @Test
+ public void attachmentURLShouldBeReturnCorrectResult() throws Exception {
+ Message message1 = new Message();
+
+ assertThat(message1.getAttachmentURL(), nullValue());
+
+ message1.setAttachmentType("jpeg");
+
+ assertThat(message1.getAttachmentURL(), equalTo("http://i.juick.com/photos-1024/0.jpeg"));
+
+ message1.setRid(1);
+
+ assertThat(message1.getAttachmentURL(), equalTo("http://i.juick.com/photos-1024/0-1.jpeg"));
+
+ Message message2 = new Message();
+
+ message2.setAttachmentType("mp4");
+
+ assertThat(message2.getAttachmentURL(), equalTo("http://i.juick.com/video/0.mp4"));
+
+ message2.setRid(1);
+
+ assertThat(message2.getAttachmentURL(), equalTo("http://i.juick.com/video/0-1.mp4"));
+ }
+
+ @Test
+ public void tagsStringShouldBeEmptyIfNoTags() throws Exception {
+ Message message = new Message();
+
+ assertThat(message.getTagsString(), isEmptyString());
+
+ message.FriendsOnly = true;
+
+ assertThat(message.getTagsString(), isEmptyString());
+
+ message.Hidden = true;
+ message.ReadOnly = true;
+
+ assertThat(message.getTagsString(), isEmptyString());
+
+ message.parseTags(" ");
+
+ assertThat(message.getTagsString(), isEmptyString());
+ }
+
+ @Test
+ public void tagsStringShouldHasNoTagDuplicates() throws Exception {
+ Message message = new Message();
+
+ message.parseTags("test");
+
+ assertThat(StringUtils.countMatches(message.getTagsString(), "*test"), equalTo(1));
+
+ message.parseTags("test test");
+
+ assertThat(StringUtils.countMatches(message.getTagsString(), "*test"), equalTo(1));
+
+ message.parseTags("test test ab test");
+
+ assertThat(StringUtils.countMatches(message.getTagsString(), "*test"), equalTo(1));
+ assertThat(StringUtils.countMatches(message.getTagsString(), "*ab"), equalTo(1));
+ }
+}