1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Expanded Message model by getId(); added tests for both supported api layers.

This commit is contained in:
Fabian Schlenz 2017-02-25 11:46:00 +01:00
parent 3d2b07eae9
commit b26df3639e
3 changed files with 56 additions and 5 deletions

View File

@ -8,6 +8,7 @@ public class Message {
protected static String tableName = "messages";
private JsonObject json;
private String message = null;
private Integer id = null;
public Message(String json) {
this.json = new JsonParser().parse(json).getAsJsonObject();
@ -19,7 +20,12 @@ public class Message {
}
public String getMessage() {
if (message != null) return message;
return message = json.getAsJsonPrimitive("message").getAsString();
if (message==null) message=json.getAsJsonPrimitive("message").getAsString();
return message;
}
public int getId() {
if (id==null) id=json.getAsJsonPrimitive("id").getAsInt();
return id;
}
}

View File

@ -0,0 +1,22 @@
import static org.junit.Assert.*;
import org.junit.Test;
import de.fabianonline.telegram_backup.models.Message;
import de.fabianonline.telegram_backup.test.models.TestJSON;
public class MessageParsingTest {
@Test
public void testGetMessage() {
assertEquals(
"Hey cool, i will test it at weekend",
new Message(TestJSON.layer53message).getMessage());
assertEquals(
"Nur mal so als Info, was wir bisher haben.",
new Message(TestJSON.layer51message).getMessage());
}
@Test
public void testGetId() {
assertEquals(15200, new Message(TestJSON.layer51message).getId());
assertEquals(39402, new Message(TestJSON.layer53message).getId());
}
}

View File

@ -0,0 +1,23 @@
package de.fabianonline.telegram_backup.test.models;
public class TestJSON {
public static String layer53message = "{" +
"\"flags\": 256," +
"\"out\": false," +
"\"mentioned\": false," +
"\"mediaUnread\": false," +
"\"silent\": false," +
"\"post\": false," +
"\"fromId\": 159899813," +
"\"toId\": {" +
"\"chatId\": 128405771," +
"\"_constructor\": \"peerChat#bad0e5bb\"" +
"}," +
"\"date\": 1487145903," +
"\"message\": \"Hey cool, i will test it at weekend\"," +
"\"_constructor\": \"message#c09be45f\"," +
"\"id\": 39402" +
"}";
public static String layer51message = "{\"flags\":256,\"unread\":false,\"out\":false,\"mentioned\":false,\"mediaUnread\":false,\"fromId\":2088876634,\"toId\":{\"chatId\":123851650,\"_constructor\":\"peerChat#bad0e5bb\"},\"date\":1468447000,\"message\":\"Nur mal so als Info, was wir bisher haben.\",\"_constructor\":\"message#c992e15c\",\"id\":15200}";
}