From 86c15ac320f9757524fffd99d88dbfcae8a84217 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Nov 2015 13:40:17 +0300 Subject: add unit tests --- src/test/java/com/juick/tests/MessageTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/java/com/juick/tests/MessageTests.java (limited to 'src/test/java/com') diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java new file mode 100644 index 00000000..47b2d13c --- /dev/null +++ b/src/test/java/com/juick/tests/MessageTests.java @@ -0,0 +1,16 @@ +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.juick.Message; + +public class MessageTests { + @Test + public void messageTagsParser() { + Message msg = new Message(); + msg.parseTags("test test" + (char)0xA0 + "2 test3"); + assertEquals("First tag must be", "test", msg.Tags.get(0)); + assertEquals("Third tag must be", "test3", msg.Tags.get(2)); + assertEquals("Count of tags must be", 3, msg.Tags.size()); + } +} \ No newline at end of file -- cgit v1.2.3 From 7668b411895053aebb1e6b122a9ba54301a257ba Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Nov 2015 14:19:11 +0300 Subject: refactoring --- src/main/java/com/juick/Message.java | 66 +++++++++++++++++++------ src/main/java/com/juick/User.java | 62 ++++++++++++++++++----- src/test/java/com/juick/tests/MessageTests.java | 2 + 3 files changed, 103 insertions(+), 27 deletions(-) (limited to 'src/test/java/com') diff --git a/src/main/java/com/juick/Message.java b/src/main/java/com/juick/Message.java index 4db2620e..03573aed 100644 --- a/src/main/java/com/juick/Message.java +++ b/src/main/java/com/juick/Message.java @@ -27,11 +27,13 @@ import java.util.Date; */ public class Message { - public int MID = 0; - public int RID = 0; + private int MID = 0; + + private int RID = 0; + public int ReplyTo = 0; - public String Text = null; - public User User = null; + private String Text = null; + private User User = null; public ArrayList Tags = new ArrayList(); public Date Timestamp = null; public String TimestampString = null; @@ -55,11 +57,11 @@ public class Message { } public Message(Message msg) { - MID = msg.MID; - RID = msg.RID; + setMID(msg.getMID()); + setRID(msg.getRID()); ReplyTo = msg.ReplyTo; - Text = msg.Text; - User = msg.User; + setText(msg.getText()); + setUser(msg.getUser()); Tags = msg.Tags; Timestamp = msg.Timestamp; TimestampString = msg.TimestampString; @@ -88,7 +90,7 @@ public class Message { return false; } Message jmsg = (Message) obj; - return (this.MID == jmsg.MID && this.RID == jmsg.RID); + return (this.getMID() == jmsg.getMID() && this.getRID() == jmsg.getRID()); } public int compareTo(Object obj) throws ClassCastException { @@ -97,16 +99,16 @@ public class Message { } Message jmsg = (Message) obj; - if (this.MID != jmsg.MID) { - if (this.MID > jmsg.MID) { + if (this.getMID() != jmsg.getMID()) { + if (this.getMID() > jmsg.getMID()) { return -1; } else { return 1; } } - if (this.RID != jmsg.RID) { - if (this.RID < jmsg.RID) { + if (this.getRID() != jmsg.getRID()) { + if (this.getRID() < jmsg.getRID()) { return -1; } else { return 1; @@ -137,9 +139,9 @@ public class Message { if (AttachmentType != null) { String url = "http://i.juick.com/"; url += AttachmentType.equals("mp4") ? "video" : "photos-1024"; - url += "/" + MID; - if (RID > 0) { - url += "-" + RID; + url += "/" + getMID(); + if (getRID() > 0) { + url += "-" + getRID(); } url += "." + AttachmentType; return url; @@ -172,4 +174,36 @@ public class Message { } return ret; } + + public int getMID() { + return MID; + } + + public void setMID(int MID) { + this.MID = MID; + } + + public int getRID() { + return RID; + } + + public void setRID(int RID) { + this.RID = RID; + } + + public com.juick.User getUser() { + return User; + } + + public void setUser(com.juick.User user) { + User = user; + } + + public String getText() { + return Text; + } + + public void setText(String text) { + Text = text; + } } diff --git a/src/main/java/com/juick/User.java b/src/main/java/com/juick/User.java index e3fc0ae7..40a3df96 100644 --- a/src/main/java/com/juick/User.java +++ b/src/main/java/com/juick/User.java @@ -23,31 +23,71 @@ package com.juick; */ public class User { - public int UID = 0; - public String UName = null; + private int UID = 0; + private String UName = null; public Object Avatar = null; - public String FullName = null; - public String JID = null; + private String FullName = null; + private String JID = null; public int MessagesCount = 0; - public String AuthHash = null; + private String AuthHash = null; public boolean Banned = false; public User() { } public User(User u) { - UID = u.UID; - UName = u.UName; + setUID(u.getUID()); + setUName(u.getUName()); Avatar = u.Avatar; - FullName = u.FullName; - JID = u.JID; + setFullName(u.getFullName()); + setJID(u.getJID()); MessagesCount = u.MessagesCount; - AuthHash = u.AuthHash; + setAuthHash(u.getAuthHash()); Banned = u.Banned; } @Override public boolean equals(Object obj) { - return (obj instanceof User && ((User) obj).UID == this.UID); + return (obj instanceof User && ((User) obj).getUID() == this.getUID()); + } + + public int getUID() { + return UID; + } + + public void setUID(int UID) { + this.UID = UID; + } + + public String getUName() { + return UName; + } + + public void setUName(String UName) { + this.UName = UName; + } + + public String getFullName() { + return FullName; + } + + public void setFullName(String fullName) { + FullName = fullName; + } + + public String getJID() { + return JID; + } + + public void setJID(String JID) { + this.JID = JID; + } + + public String getAuthHash() { + return AuthHash; + } + + public void setAuthHash(String authHash) { + AuthHash = authHash; } } diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java index 47b2d13c..0392c7b3 100644 --- a/src/test/java/com/juick/tests/MessageTests.java +++ b/src/test/java/com/juick/tests/MessageTests.java @@ -1,3 +1,5 @@ +package com.juick.tests; + import static org.junit.Assert.assertEquals; import org.junit.Test; -- cgit v1.2.3