Package com.log4jviewer.domain

Source Code of com.log4jviewer.domain.SocketLogEventTest

package com.log4jviewer.domain;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import junit.framework.Assert;

import org.apache.log4j.Level;
import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
import org.junit.Before;
import org.junit.Test;

public class SocketLogEventTest {

    private LoggingEvent mockLog;
    private LocationInfo mockLocationInfo;
    private SocketLogEvent socketLogEvent;

    @Before
    public void init() {
        mockLog = mock(LoggingEvent.class);
        mockLocationInfo = mock(LocationInfo.class);
        when(mockLog.getLocationInformation()).thenReturn(mockLocationInfo);
        socketLogEvent = new SocketLogEvent(mockLog);
    }

    @Test
    public void logInfoTest() {
        when(mockLog.getLoggerName()).thenReturn("CategoryName");
        Assert.assertEquals("CategoryName", socketLogEvent.getCategoryName());

        when(mockLocationInfo.getClassName()).thenReturn("ClassName");
        Assert.assertEquals("ClassName", socketLogEvent.getClassName());

        when(mockLocationInfo.getFileName()).thenReturn("FileName");
        Assert.assertEquals("FileName", socketLogEvent.getFileName());

        when(mockLocationInfo.getLineNumber()).thenReturn("7");
        Assert.assertEquals("7", socketLogEvent.getLineNumber());

        when(mockLog.getRenderedMessage()).thenReturn("Message");
        Assert.assertEquals("Message", socketLogEvent.getMessage());

        when(mockLocationInfo.getMethodName()).thenReturn("MethodName");
        Assert.assertEquals("MethodName", socketLogEvent.getMethodName());

        when(mockLog.getNDC()).thenReturn("Ndc");
        Assert.assertEquals("Ndc", socketLogEvent.getNdc());

        when(mockLog.getLevel()).thenReturn(Level.DEBUG);
        Assert.assertEquals("DEBUG", socketLogEvent.getLevel());

        when(mockLog.getThreadName()).thenReturn("ThreadName");
        Assert.assertEquals("ThreadName", socketLogEvent.getThreadName());

        when(mockLog.getThrowableInformation()).thenReturn(new ThrowableInformation(new Throwable("Exception")));
        Assert.assertEquals("Exception", socketLogEvent.getThrowableInfo());
    }

    @Test
    public void emptyLogInfoTest() {
        Assert.assertEquals("", socketLogEvent.getCategoryName());
        Assert.assertEquals("", socketLogEvent.getClassName());
        Assert.assertEquals("", socketLogEvent.getDate());
        Assert.assertEquals("", socketLogEvent.getFileName());
        Assert.assertEquals("", socketLogEvent.getLineNumber());
        Assert.assertEquals("", socketLogEvent.getMdc());
        Assert.assertEquals("", socketLogEvent.getMessage());
        Assert.assertEquals("", socketLogEvent.getMethodName());
        Assert.assertEquals("", socketLogEvent.getNdc());
        Assert.assertEquals("", socketLogEvent.getLevel());
        Assert.assertEquals("", socketLogEvent.getThreadName());
        Assert.assertEquals("", socketLogEvent.getThrowableInfo());
    }
}
TOP

Related Classes of com.log4jviewer.domain.SocketLogEventTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.