001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.spi;
015
016import ch.qos.logback.classic.Level;
017import ch.qos.logback.classic.Logger;
018import ch.qos.logback.classic.LoggerContext;
019import org.junit.Before;
020import org.junit.Test;
021
022import static org.junit.Assert.assertNull;
023import static org.junit.Assert.assertEquals;
024
025public class LoggingEventTest {
026
027    LoggerContext loggerContext = new LoggerContext();
028    Logger logger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
029
030    @Before
031    public void setUp() {
032    }
033
034    @Test
035    public void testFormattingOneArg() {
036        String message = "x={}";
037        Throwable throwable = null;
038        Object[] argArray = new Object[] { 12 };
039
040        LoggingEvent event = new LoggingEvent("", logger, Level.INFO, message, throwable, argArray);
041        assertNull(event.formattedMessage);
042        assertEquals("x=12", event.getFormattedMessage());
043    }
044
045    @Test
046    public void testFormattingTwoArg() {
047        String message = "{}-{}";
048        Throwable throwable = null;
049        Object[] argArray = new Object[] { 12, 13 };
050        LoggingEvent event = new LoggingEvent("", logger, Level.INFO, message, throwable, argArray);
051
052        assertNull(event.formattedMessage);
053        assertEquals("12-13", event.getFormattedMessage());
054    }
055
056    @Test
057    public void testNoFormattingWithArgs() {
058        String message = "testNoFormatting";
059        Throwable throwable = null;
060        Object[] argArray = new Object[] { 12, 13 };
061        LoggingEvent event = new LoggingEvent("", logger, Level.INFO, message, throwable, argArray);
062        assertNull(event.formattedMessage);
063        assertEquals(message, event.getFormattedMessage());
064    }
065
066    @Test
067    public void testNoFormattingWithoutArgs() {
068        String message = "testNoFormatting";
069        Throwable throwable = null;
070        Object[] argArray = null;
071        LoggingEvent event = new LoggingEvent("", logger, Level.INFO, message, throwable, argArray);
072        assertNull(event.formattedMessage);
073        assertEquals(message, event.getFormattedMessage());
074    }
075}