/*
 * Copyright (c) 2006-2014 DMDirc Developers
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.dmdirc.logger;


import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class DMDircExceptionHandlerTest {

    @Mock private ErrorManager errorManager;
    private DMDircExceptionHandler eh;

    @Before
    public void setup() {
        Logger.setErrorManager(errorManager);
        eh = new DMDircExceptionHandler();
    }

    @Test
    public void testUncaughtException() {
        final Exception exception = new UnsupportedOperationException();
        eh.uncaughtException(null, exception);
        verify(errorManager).addError(eq(ErrorLevel.HIGH), anyString(), same(exception), eq(true));
    }

    @Test
    public void testUncaughtError() {
        final Error error = new OutOfMemoryError();
        eh.uncaughtException(null, error);
        verify(errorManager).addError(eq(ErrorLevel.FATAL), anyString(), same(error), eq(true));
    }

}

@@ -1149,16 +1149,92 @@
 gger;%0A%0A%0A
+import com.dmdirc.DMDircMBassador;%0Aimport com.dmdirc.events.AppErrorEvent;%0A%0A
 import o
@@ -1306,16 +1306,78 @@
 unWith;%0A
+import org.mockito.ArgumentCaptor;%0Aimport org.mockito.Captor;%0A
 import o
@@ -1441,16 +1441,69 @@
 unner;%0A%0A
+import static junit.framework.TestCase.assertEquals;%0A
 import s
@@ -1528,17 +1528,22 @@
 Mockito.
-*
+verify
 ;%0A%0A@RunW
@@ -1637,33 +1637,89 @@
 ate 
-ErrorManager errorManager
+DMDircMBassador eventBus;%0A    @Captor private ArgumentCaptor%3CAppErrorEvent%3E event
 ;%0A  
@@ -1798,54 +1798,8 @@
 ) %7B%0A
-        Logger.setErrorManager(errorManager);%0A
     
@@ -1834,16 +1834,24 @@
 Handler(
+eventBus
 );%0A    %7D
@@ -2044,32 +2044,63 @@
 fy(e
-rrorManager).addError(eq
+ventBus).publish(event.capture());%0A        assertEquals
 (Err
@@ -2115,48 +2115,234 @@
 HIGH
-)
 , 
-anyString(), same(exception), eq(true
+event.getValue().getLevel());%0A        assertEquals(exception, event.getValue().getThrowable());%0A        assertEquals(exception.toString(), event.getValue().getMessage());%0A        assertEquals(%22%22, event.getValue().getDetails(
 ));%0A
@@ -2511,32 +2511,63 @@
 fy(e
-rrorManager).addError(eq
+ventBus).publish(event.capture());%0A        assertEquals
 (Err
@@ -2583,44 +2583,226 @@
 ATAL
-)
 , 
-anyString(), same(error), eq(true
+event.getValue().getLevel());%0A        assertEquals(error, event.getValue().getThrowable());%0A        assertEquals(error.toString(), event.getValue().getMessage());%0A        assertEquals(%22%22, event.getValue().getDetails(
 ));%0A

Fix unit test.