package org.hisp.dhis.android.dashboard.api.user;

import static org.junit.Assert.assertTrue;

import org.hisp.dhis.android.dashboard.api.commons.DateTestUtils;
import org.hisp.dhis.android.dashboard.api.commons.FileReader;
import org.hisp.dhis.android.dashboard.api.commons.JsonParser;
import org.hisp.dhis.android.dashboard.api.models.User;
import org.hisp.dhis.android.dashboard.api.models.UserAccount;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.IOException;

public class UserTests {
    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void userAccount_conversion_to_user() throws IOException {
        UserAccount userAccount = getUserAccountFromJson();
        User user = UserAccount.toUser(userAccount);
        assertTrue(user.getUId().equals("xE7jOejl9FI"));
        assertTrue(user.getName().equals("John Traore"));
        assertTrue(user.getDisplayName().equals("John Traore"));
        assertTrue(DateTestUtils.compareParsedDateWithStringDate(user.getCreated(),
                "2013-04-18T17:15:08.407"));
        assertTrue(DateTestUtils.compareParsedDateWithStringDate(user.getLastUpdated(),
                "2017-05-02T17:02:37.817"));
        assertTrue(user.getAccess() == null);
    }

    private UserAccount getUserAccountFromJson() throws IOException {
        return (UserAccount) JsonParser.getModelFromJson(UserAccount.class, new FileReader().getStringFromFile(
                "userAccount.json"));
    }
}
@@ -399,16 +399,47 @@
 ccount;%0A
+import org.joda.time.DateTime;%0A
 import o
@@ -1078,32 +1078,47 @@
 eWithStringDate(
+DateTime.parse(
 user.getCreated(
@@ -1114,24 +1114,25 @@
 getCreated()
+)
 ,%0A          
@@ -1231,16 +1231,31 @@
 ingDate(
+DateTime.parse(
 user.get
@@ -1267,16 +1267,17 @@
 pdated()
+)
 ,%0A      

Fix tests