Search in sources :

Example 1 with ItemTypeAdapter

use of email.schaal.ocreader.api.json.ItemTypeAdapter in project ocreader by schaal.

the class JsonTest method TestItemToJson.

@Test
public void TestItemToJson() throws IOException {
    Moshi moshi = new Moshi.Builder().add(Item.class, new ItemTypeAdapter()).build();
    Item item = new Item.Builder().setId(1).setContentHash("oijoijo").setUnreadChanged(true).setUnread(false).build();
    String itemJson = moshi.adapter(Item.class).toJson(item);
    ReducedItem reducedItem = moshi.adapter(ReducedItem.class).fromJson(itemJson);
    ReducedItem expectedReducedItem = new ReducedItem();
    expectedReducedItem.id = 1;
    expectedReducedItem.contentHash = "oijoijo";
    expectedReducedItem.isUnread = false;
    expectedReducedItem.isStarred = null;
    assertEquals(expectedReducedItem, reducedItem);
}
Also used : Item(email.schaal.ocreader.database.model.Item) ItemTypeAdapter(email.schaal.ocreader.api.json.ItemTypeAdapter) Moshi(com.squareup.moshi.Moshi) Test(org.junit.Test)

Aggregations

Moshi (com.squareup.moshi.Moshi)1 ItemTypeAdapter (email.schaal.ocreader.api.json.ItemTypeAdapter)1 Item (email.schaal.ocreader.database.model.Item)1 Test (org.junit.Test)1