package com.codahale.dropwizard.logging;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.net.SyslogAppender;
import com.codahale.dropwizard.jackson.DiscoverableSubtypeResolver;
import org.junit.Test;

import static org.fest.assertions.api.Assertions.assertThat;

public class SyslogAppenderFactoryTest {
    @Test
    public void isDiscoverable() throws Exception {
        assertThat(new DiscoverableSubtypeResolver().getDiscoveredSubtypes())
                .contains(SyslogAppenderFactory.class);
    }

    @Test
    public void defaultIncludesAppName() throws Exception {
        assertThat(new SyslogAppenderFactory().getLogFormat())
                .contains("%app");
    }

    @Test
    public void defaultIncludesPid() throws Exception {
        assertThat(new SyslogAppenderFactory().getLogFormat())
                .contains("%pid");
    }

    @Test
    public void patternIncludesAppNameAndPid() throws Exception {
        SyslogAppender appender = (SyslogAppender) new SyslogAppenderFactory()
                .build(new LoggerContext(), "MyApplication", null);
        assertThat(appender.getSuffixPattern())
                .matches("^MyApplication\\[\\d+\\].+");
    }
}

@@ -126,24 +126,110 @@
 ogAppender;%0A
+import ch.qos.logback.classic.spi.ILoggingEvent;%0Aimport ch.qos.logback.core.Appender;%0A
 import com.c
@@ -308,16 +308,49 @@
 .Test;%0A%0A
+import java.lang.reflect.Field;%0A%0A
 import s
@@ -1077,30 +1077,24 @@
         
-Syslog
 Appender
  appende
@@ -1089,36 +1089,33 @@
 nder
- appender = (SyslogAppender)
+%3CILoggingEvent%3E wrapper =
  new
@@ -1207,16 +1207,325 @@
  null);%0A
+%0A        // hack to get at the SyslogAppender beneath the AsyncAppender%0A        // todo: find a nicer way to do all this%0A        Field delegate = AsyncAppender.class.getDeclaredField(%22delegate%22);%0A        delegate.setAccessible(true);%0A        SyslogAppender appender = (SyslogAppender) delegate.get(wrapper);%0A%0A
         

Fix test to work with new AsyncAppender