package com.bugsnag.android;

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

import com.bugsnag.android.Configuration;
import com.bugsnag.android.Error;

public class ErrorTest extends BugsnagTestCase {
    public void testShouldIgnore() {
        Configuration config = new Configuration("api-key");
        config.ignoreClasses = new String[] {"java.io.IOException"};

        // Shouldn't ignore classes not in ignoreClasses
        Error error = new Error(config, new RuntimeException("Test"));
        assertFalse(error.shouldIgnoreClass());

        // Should ignore errors in ignoreClasses
        error = new Error(config, new java.io.IOException("Test"));
        assertTrue(error.shouldIgnoreClass());
    }

    public void testGetExceptionName() {
        Configuration config = new Configuration("api-key");

        Error error = new Error(config, new RuntimeException("Test"));
        assertEquals("java.lang.RuntimeException", error.getExceptionName());
    }

    public void testGetExceptionMessage() {
        Configuration config = new Configuration("api-key");

        Error error = new Error(config, new RuntimeException("Example message"));
        assertEquals("Example message", error.getExceptionMessage());
    }

    public void testToStream() throws JSONException {
        Configuration config = new Configuration("api-key");
        Error error = new Error(config, new RuntimeException("Example message"));

        JSONObject errorJson = streamableToJson(error);
        assertEquals("warning", errorJson.get("severity"));
        // TODO: Test all other fields are correct
    }
}

@@ -87,85 +87,8 @@
 t;%0A%0A
-import com.bugsnag.android.Configuration;%0Aimport com.bugsnag.android.Error;%0A%0A
 publ
@@ -164,16 +164,21 @@
 ldIgnore
+Class
 () %7B%0A   
@@ -1201,16 +1201,26 @@
 test
-ToStream
+BasicSerialization
 () t
@@ -1513,50 +1513,1320 @@
     
-// TODO: Test all other fields are correct
+assertEquals(%222%22, errorJson.get(%22payloadVersion%22));%0A        assertNotNull(errorJson.get(%22severity%22));%0A        assertNotNull(errorJson.get(%22metaData%22));%0A        assertNotNull(errorJson.get(%22threads%22));%0A    %7D%0A%0A    public void testSetContext() throws JSONException %7B%0A        Configuration config = new Configuration(%22api-key%22);%0A        Error error = new Error(config, new RuntimeException(%22Example message%22));%0A        error.setContext(%22ExampleContext%22);%0A%0A        JSONObject errorJson = streamableToJson(error);%0A        assertEquals(%22ExampleContext%22, errorJson.get(%22context%22));%0A    %7D%0A%0A    public void testSetGroupingHash() throws JSONException %7B%0A        Configuration config = new Configuration(%22api-key%22);%0A        Error error = new Error(config, new RuntimeException(%22Example message%22));%0A        error.setGroupingHash(%22herpderp%22);%0A%0A        JSONObject errorJson = streamableToJson(error);%0A        assertEquals(%22herpderp%22, errorJson.get(%22groupingHash%22));%0A    %7D%0A%0A    public void testSetSeverity() throws JSONException %7B%0A        Configuration config = new Configuration(%22api-key%22);%0A        Error error = new Error(config, new RuntimeException(%22Example message%22));%0A        error.setSeverity(Severity.INFO);%0A%0A        JSONObject errorJson = streamableToJson(error);%0A        assertEquals(%22info%22, errorJson.get(%22severity%22));
 %0A   

Add more Error tests