package com.humbughq.mobile.test;

import org.json.JSONException;
import org.json.JSONObject;

import com.humbughq.mobile.HumbugActivity;
import com.humbughq.mobile.Message;
import com.humbughq.mobile.Person;
import com.humbughq.mobile.ZulipApp;

import android.content.Intent;
import android.test.ActivityUnitTestCase;

public class UnsortedTests extends ActivityUnitTestCase<HumbugActivity> {

    private ZulipApp app;

    public UnsortedTests() {
        super(HumbugActivity.class);
    }

    protected void setUp() throws Exception {
        super.setUp();
        app = new ZulipApp();
    }
    
    public void testMessageCreation() throws JSONException {
        testInit();
        JSONObject jsonObject;
        jsonObject = new JSONObject("{\"recipient_id\": 314, \"sender_email\": \"lfaraone@zulip.com\", \"timestamp\": 1379966441, \"display_recipient\": \"test\", \"sender_id\": 15, \"sender_full_name\": \"Luke Faraone\", \"sender_domain\": \"zulip.com\", \"content\": \"Hello!\", \"gravatar_hash\": \"9cd8e1981dc89f3221c5077dd8a22515\", \"avatar_url\": \"https://secure.gravatar.com/avatar/9cd8e1981dc89f3221c5077dd8a22515?d=identicon\", \"client\": \"website\", \"content_type\": \"text/x-markdown\", \"subject_links\": [], \"sender_short_name\": \"lfaraone\", \"type\": \"stream\", \"id\": 10594623, \"subject\": \"toast\"}");
        Message msg = new Message((ZulipApp) getActivity().getApplication(), jsonObject);
        assertEquals(msg.getID(), 10594623);
        assertEquals(msg.getSender(), new Person("Luke Faraone", "lfaraone@zulip.com"));
    }

    /**
     * Run this before each test to set up the activity.
     */
    private void testInit() {
        setApplication(app);
        this.startActivity(new Intent(getInstrumentation().getTargetContext(), HumbugActivity.class), null, null);
        this.getInstrumentation().waitForIdleSync();
        app.setContext(getInstrumentation().getTargetContext());
        ((ZulipApp) getActivity().getApplication()).setEmail("testuser@example.com");
        
    }

    protected void tearDown() throws Exception {
        super.tearDown();
    }

}

@@ -594,20 +594,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -743,16 +743,33 @@
 NObject(
+%0A                
 %22%7B%5C%22reci
@@ -1430,16 +1430,32 @@
 ation(),
+%0A               
  jsonObj
@@ -1569,16 +1569,32 @@
 araone%22,
+%0A               
  %22lfarao
@@ -1827,16 +1827,32 @@
 ntext(),
+%0A               
  HumbugA
@@ -2049,16 +2049,33 @@
 ation())
+%0A                
 .setEmai
@@ -2101,24 +2101,16 @@
 .com%22);%0A
-        
 %0A    %7D%0A%0A

Apply formatter to testcases