/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.logging;

import org.junit.Assert;

import org.junit.Test;
import org.xwiki.logging.event.LogEvent;

/**
 * Test {@link LogQueue}.
 * 
 * @version $Id$
 */
public class LogQueueTest
{
    @Test
    public void testError()
    {
        LogQueue queue = new LogQueue();
        LogEvent logEvent;

        queue.error("message");
        Assert.assertEquals("message", queue.poll().getFormattedMessage());

        queue.error("message {}", "param");
        Assert.assertEquals("message param", queue.poll().getFormattedMessage());

        queue.error("message {} {}", "param1", "param2");
        Assert.assertEquals("message param1 param2", queue.poll().getFormattedMessage());

        queue.error("message {}", "param1", new Exception());
        logEvent = queue.poll();
        Assert.assertEquals("message param1", logEvent.getFormattedMessage());
        Assert.assertNotNull(logEvent.getThrowable());
        Assert.assertNull(logEvent.getTranslationKey());

        queue.error("message {}", new Object[] {"param1", new Exception()});
        logEvent = queue.poll();
        Assert.assertEquals("message param1", logEvent.getFormattedMessage());
        Assert.assertNotNull(logEvent.getThrowable());
        Assert.assertNull(logEvent.getTranslationKey());

        queue.error(new TranslationMarker("translation.key"), "message");
        logEvent = queue.poll();
        Assert.assertEquals("translation.key", logEvent.getTranslationKey());
    }
}

@@ -915,16 +915,42 @@
 gging;%0A%0A
+import java.util.Arrays;%0A%0A
 import o
@@ -966,17 +966,16 @@
 Assert;%0A
-%0A
 import o
@@ -1227,16 +1227,219 @@
 Event;%0A%0A
+        queue.error(%22%22);%0A        logEvent = queue.poll();%0A        Assert.assertEquals(Arrays.asList(%22%22), logEvent.getMessageElements());%0A        Assert.assertEquals(%22%22, logEvent.getFormattedMessage());%0A%0A
         
@@ -1720,24 +1720,57 @@
  %22param2%22);%0A
+        logEvent = queue.poll();%0A
         Asse
@@ -1810,28 +1810,24 @@
 aram2%22, 
-queue.poll()
+logEvent
 .getForm
@@ -1847,179 +1847,572 @@
 ));%0A
-%0A        queue.error(%22message %7B%7D%22, %22param1%22, new Exception());%0A        logEvent = queue.poll();%0A        Assert.assertEquals(%22message param1%22, logEvent.getFormattedMessage(
+        Assert.assertEquals(Arrays.asList(%22message %22, %22 %22, %22%22), logEvent.getMessageElements());%0A        Assert.assertEquals(Arrays.asList(%22param1%22, %22param2%22), Arrays.asList(logEvent.getArgumentArray()));%0A%0A        queue.error(%22message %7B%7D%22, %22param1%22, new Exception());%0A        logEvent = queue.poll();%0A        Assert.assertEquals(%22message param1%22, logEvent.getFormattedMessage());%0A        Assert.assertEquals(Arrays.asList(%22message %22, %22%22), logEvent.getMessageElements());%0A        Assert.assertEquals(Arrays.asList(%22param1%22), Arrays.asList(logEvent.getArgumentArray()
 ));%0A
@@ -2705,32 +2705,221 @@
 ttedMessage());%0A
+        Assert.assertEquals(Arrays.asList(%22message %22, %22%22), logEvent.getMessageElements());%0A        Assert.assertEquals(Arrays.asList(%22param1%22), Arrays.asList(logEvent.getArgumentArray()));%0A
         Assert.a
@@ -3196,20 +3196,196 @@
 tionKey());%0A
+        Assert.assertEquals(Arrays.asList(%22message%22), logEvent.getMessageElements());%0A        Assert.assertEquals(Arrays.asList(), Arrays.asList(logEvent.getArgumentArray()));%0A
     %7D%0A%7D%0A

Add unit tests