diff --git a/core/src/main/java/io/tracee/contextlogger/AbstractToStringBuilder.java b/core/src/main/java/io/tracee/contextlogger/AbstractToStringBuilder.java index 4cc4c82..286eb02 100644 --- a/core/src/main/java/io/tracee/contextlogger/AbstractToStringBuilder.java +++ b/core/src/main/java/io/tracee/contextlogger/AbstractToStringBuilder.java @@ -11,10 +11,10 @@ */ public abstract class AbstractToStringBuilder implements ContextLoggerBuilderAccessable { - protected final ContextLoggerConfiguration contextLoggerConfiguration; - protected TraceeContextStringRepresentationBuilder traceeContextLogBuilder; + private final ContextLoggerConfiguration contextLoggerConfiguration; + private TraceeContextStringRepresentationBuilder traceeContextLogBuilder; - protected Object[] objectsToProcess; + private Object[] objectsToProcess; protected AbstractToStringBuilder(ContextLoggerConfiguration contextLoggerConfiguration) { this.contextLoggerConfiguration = contextLoggerConfiguration; @@ -49,8 +49,20 @@ public void setStringRepresentationBuilder(TraceeContextStringRepresentationBuil this.traceeContextLogBuilder = stringRepresentationBuilder; } + protected TraceeContextStringRepresentationBuilder getStringRepresentationBuilder() { + return this.traceeContextLogBuilder; + } + @Override public ContextLoggerConfiguration getContextLoggerConfiguration() { return this.contextLoggerConfiguration; } + + protected Object[] getObjectsToProcess() { + return objectsToProcess; + } + + protected void setObjectsToProcess(final Object[] objectsToProcess) { + this.objectsToProcess = objectsToProcess; + } } diff --git a/core/src/main/java/io/tracee/contextlogger/TraceeContextLogger.java b/core/src/main/java/io/tracee/contextlogger/TraceeContextLogger.java index 34ba3e5..3a75f31 100644 --- a/core/src/main/java/io/tracee/contextlogger/TraceeContextLogger.java +++ b/core/src/main/java/io/tracee/contextlogger/TraceeContextLogger.java @@ -20,7 +20,6 @@ public final class TraceeContextLogger extends AbstractToStringBuilder getCustomImplicitDataProviders() { /** * Generic function to get a implicit data provider classes from resource files. * - * @param type the type of implicit context data provider to look for + * @param type the type of implicit context data provider to look for * @param resourceUrl the resource file url process - * @param The generic type of implicit data provider either {@link io.tracee.contextlogger.contextprovider.api.CustomImplicitContextData} or - * {@link io.tracee.contextlogger.api.ImplicitContextData} + * @param The generic type of implicit data provider either {@link io.tracee.contextlogger.contextprovider.api.CustomImplicitContextData} or + * {@link io.tracee.contextlogger.api.ImplicitContextData} * @return a set that contains all context provider type the were found */ static Set getImplicitWrappers(final Class type, final String resourceUrl) { @@ -133,19 +138,21 @@ static Set getImplicitWrappers(final Class type, final String resource T instance = type.cast(clazz.newInstance()); result.add(instance); } - } catch (Exception e) { - // to be ignored - } catch (NoClassDefFoundError error) { + } + catch (Throwable e) { // to be ignored } } - } catch (Exception e) { + } + catch (Exception e) { logError("Context logger - An error occurred while loading implicit type wrappers.", e); - } finally { + } + finally { if (bufferedReader != null) { try { bufferedReader.close(); - } catch (IOException ignored) { + } + catch (IOException ignored) { // ignore } } @@ -194,25 +201,27 @@ static List getAvailableWrappers(final String resourceUrl) { if (WrappedContextData.class.isAssignableFrom(clazz)) { // try to create instance to get the wrapped type - final WrappedContextData instance = (WrappedContextData) clazz.newInstance(); + final WrappedContextData instance = (WrappedContextData)clazz.newInstance(); result.add(new TypeToWrapper(instance.getWrappedType(), clazz)); } - } catch (Exception e) { - // to be ignored - } catch (NoClassDefFoundError error) { + } + catch (Throwable e) { // to be ignored } } - } catch (Exception e) { + } + catch (Throwable e) { logError("Context logger - An error occurred while loading explicit type wrappers.", e); - } finally { + } + finally { if (bufferedReader != null) { try { bufferedReader.close(); - } catch (IOException e1) { + } + catch (IOException e1) { // ignore } } diff --git a/core/src/main/java/io/tracee/contextlogger/outputgenerator/AbstractContextStringRepresentationBuilder.java b/core/src/main/java/io/tracee/contextlogger/outputgenerator/AbstractContextStringRepresentationBuilder.java index 8c28b15..54e04a2 100644 --- a/core/src/main/java/io/tracee/contextlogger/outputgenerator/AbstractContextStringRepresentationBuilder.java +++ b/core/src/main/java/io/tracee/contextlogger/outputgenerator/AbstractContextStringRepresentationBuilder.java @@ -68,7 +68,7 @@ protected void cloneTo(AbstractContextStringRepresentationBuilder cloneTo) { cloneTo.setWrapperClasses(new HashSet(wrapperClasses)); cloneTo.setProfile(profile); - cloneTo.setManualContextOverrides(manualContextOverrides); + cloneTo.setManualContextOverrides(new HashMap(manualContextOverrides)); cloneTo.setEnforceOrder(keepOrder); cloneTo.setOutputWriterConfiguration(outputWriterConfiguration); diff --git a/core/src/main/java/io/tracee/contextlogger/outputgenerator/functions/TraceeContextProviderWrapperFunction.java b/core/src/main/java/io/tracee/contextlogger/outputgenerator/functions/TraceeContextProviderWrapperFunction.java index 1f8c071..97772c5 100644 --- a/core/src/main/java/io/tracee/contextlogger/outputgenerator/functions/TraceeContextProviderWrapperFunction.java +++ b/core/src/main/java/io/tracee/contextlogger/outputgenerator/functions/TraceeContextProviderWrapperFunction.java @@ -75,7 +75,7 @@ public Object apply(ContextLoggerConfiguration contextLoggerConfiguration, Objec * @param type the type of the new instance * @return a new instance of the passed type or null if an exception occurred during the creation of the instance of if the passed type is null. */ - private Object createInstance(final Class type) { + protected Object createInstance(final Class type) { if (type != null) { try { return type.newInstance(); diff --git a/core/src/test/java/io/tracee/contextlogger/AbstractToStringBuilderTest.java b/core/src/test/java/io/tracee/contextlogger/AbstractToStringBuilderTest.java new file mode 100644 index 0000000..1740e82 --- /dev/null +++ b/core/src/test/java/io/tracee/contextlogger/AbstractToStringBuilderTest.java @@ -0,0 +1,132 @@ +package io.tracee.contextlogger; + +import java.util.Map; +import java.util.Set; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; +import org.mockito.Mockito; + +import io.tracee.contextlogger.api.TraceeContextStringRepresentationBuilder; +import io.tracee.contextlogger.impl.ContextLoggerConfiguration; +import io.tracee.contextlogger.outputgenerator.writer.OutputWriterConfiguration; +import io.tracee.contextlogger.profile.Profile; + +/** + * Unit test for {@link AbstractToStringBuilder}. + */ +public class AbstractToStringBuilderTest { + + public static class TestToStringBuilder extends AbstractToStringBuilder { + + protected TestToStringBuilder() { + super((ContextLoggerConfiguration)null); + } + + protected TestToStringBuilder(final AbstractToStringBuilder instanceToClone) { + super(instanceToClone); + } + + @Override + public void log(final Object... instancesToLog) { + + } + + @Override + public void logWithPrefixedMessage(final String prefixedMessage, final Object... instancesToLog) { + + } + } + + public TraceeContextStringRepresentationBuilder traceeContextLogBuilder = new TraceeContextStringRepresentationBuilder() { + + @Override + public Set getWrapperClasses() { + return null; + } + + @Override + public void setWrapperClasses(final Set wrapperClasses) { + + } + + @Override + public boolean getEnforceOrder() { + return false; + } + + @Override + public void setEnforceOrder(final boolean keepOrder) { + + } + + @Override + public String createStringRepresentation(final Object... instancesToLog) { + return null; + } + + @Override + public void setOutputWriterConfiguration(final OutputWriterConfiguration outputWriterConfiguration) { + + } + + @Override + public void setManualContextOverrides(final Map manualContextOverrides) { + + } + + @Override + public Map getManualContextOverrides() { + return null; + } + + @Override + public TraceeContextStringRepresentationBuilder cloneStringRepresentationBuilder() { + return null; + } + + @Override + public void setProfile(final Profile profile) { + + } + + @Override + public Profile getProfile() { + return null; + } + }; + + @Test + public void should_use_constructor_correctly() { + + TestToStringBuilder source = new TestToStringBuilder(); + source.setStringRepresentationBuilder(traceeContextLogBuilder); + + final Object[] objArray = { "ABC", "DEF" }; + source.setObjectsToProcess(objArray); + + TestToStringBuilder unit = new TestToStringBuilder(source); + + MatcherAssert.assertThat(unit.getStringRepresentationBuilder(), Matchers.equalTo(source.getStringRepresentationBuilder())); + MatcherAssert.assertThat(unit.getObjectsToProcess(), Matchers.equalTo(objArray)); + MatcherAssert.assertThat(unit.getContextLoggerConfiguration(), Matchers.nullValue()); + + } + + @Test + public void toString_should_be_forwarded_to_tracee_context_log_builder_correctly() { + + TestToStringBuilder unit = new TestToStringBuilder(); + + TraceeContextStringRepresentationBuilder spy = Mockito.spy(traceeContextLogBuilder); + + unit.setStringRepresentationBuilder(spy); + + unit.toString("ABC", "DEF"); + Mockito.verify(spy).createStringRepresentation("ABC", "DEF"); + + unit.create("DEF", "GHI"); + Mockito.verify(spy).createStringRepresentation("DEF", "GHI"); + } +} diff --git a/core/src/test/java/io/tracee/contextlogger/TraceeContextLoggerTest.java b/core/src/test/java/io/tracee/contextlogger/TraceeContextLoggerTest.java new file mode 100644 index 0000000..bc8a5fd --- /dev/null +++ b/core/src/test/java/io/tracee/contextlogger/TraceeContextLoggerTest.java @@ -0,0 +1,60 @@ +package io.tracee.contextlogger; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +import io.tracee.contextlogger.contextprovider.java.JavaThrowableContextProvider; +import io.tracee.contextlogger.outputgenerator.writer.BasicOutputWriterConfiguration; + +/** + * Unit test for {@link TraceeContextLogger}. + */ +public class TraceeContextLoggerTest { + + @Test + public void should_detect_suppress_passed_instance_to_be_excluded() { + + TraceeContextLogger unit = (TraceeContextLogger)TraceeContextLogger.create() + .enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE).disableTypes(String.class).apply(); + + String result = unit.toString("ABC", 1L); + + MatcherAssert.assertThat(result, Matchers.equalTo("[\"TYPE:Object[]\",\"Long['1']\"]")); + + } + + @Test + public void should_create_string_representation() { + + TraceeContextLogger unit = (TraceeContextLogger)TraceeContextLogger.create() + .enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE).apply(); + + String result = unit.toString("ABC", 1L); + MatcherAssert.assertThat(result, Matchers.equalTo("[\"TYPE:Object[]\",\"String['ABC']\",\"Long['1']\"]")); + + Object[] objectsToBeProcessed = { "DEF", 2L }; + unit.setObjectsToProcess(objectsToBeProcessed); + result = unit.provideOutput(); + MatcherAssert.assertThat(result, Matchers.equalTo("[\"TYPE:Object[]\",\"String['DEF']\",\"Long['2']\"]")); + + } + + @Test + public void excludeContextProviders_should_exclude_contextProviders_correctly() { + + TraceeContextLogger unit = (TraceeContextLogger)((TraceeContextLogger)TraceeContextLogger.create() + .enforceOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE).apply()) + .excludeContextProviders(JavaThrowableContextProvider.class); + + String result = unit.toString(new NullPointerException()); + + MatcherAssert.assertThat(result, Matchers.is("null")); + + result = unit.toString(new NullPointerException(), "ABC"); + + MatcherAssert.assertThat(result, Matchers.equalTo("[\"TYPE:Object[]\",\"String['ABC']\"]")); + + } + +} diff --git a/core/src/test/java/io/tracee/contextlogger/contextprovider/TypeToWrapperTest.java b/core/src/test/java/io/tracee/contextlogger/contextprovider/TypeToWrapperTest.java index b152c1e..b6c516f 100644 --- a/core/src/test/java/io/tracee/contextlogger/contextprovider/TypeToWrapperTest.java +++ b/core/src/test/java/io/tracee/contextlogger/contextprovider/TypeToWrapperTest.java @@ -1,13 +1,17 @@ package io.tracee.contextlogger.contextprovider; -import org.junit.Test; - -import java.util.List; - +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; +import java.util.List; +import java.util.Set; + +import org.junit.Test; + +import io.tracee.contextlogger.contextprovider.tracee.TraceeMessage; + /** * Test class for {@link TypeToWrapper}. * Created by Tobias Gindler, holisticon AG on 20.03.14. @@ -15,11 +19,22 @@ public class TypeToWrapperTest { @Test - public void getAvailableWrappers_should_load_all_available_wrappers () { + public void getAvailableWrappers_should_load_all_available_wrappers() { List result = TypeToWrapper.getAvailableWrappers(); assertThat(result, notNullValue()); assertThat(result.size(), greaterThan(0)); } + + @Test + public void getAllWrappedClasses_should_get_all_wrapped_classes() { + + Set wrappedClassesSet = TypeToWrapper.getAllWrappedClasses(); + + assertThat(wrappedClassesSet, notNullValue()); + assertThat(wrappedClassesSet.size(), greaterThan(0)); + assertThat(wrappedClassesSet, containsInAnyOrder((Class)TraceeMessage.class, (Class)Throwable.class)); + } + } diff --git a/core/src/test/java/io/tracee/contextlogger/contextprovider/tracee/TraceeMessageTest.java b/core/src/test/java/io/tracee/contextlogger/contextprovider/tracee/TraceeMessageTest.java new file mode 100644 index 0000000..9ae01cf --- /dev/null +++ b/core/src/test/java/io/tracee/contextlogger/contextprovider/tracee/TraceeMessageTest.java @@ -0,0 +1,20 @@ +package io.tracee.contextlogger.contextprovider.tracee; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Unit test for {@link TraceeMessage}. + */ +public class TraceeMessageTest { + + @Test + public void should_wrap_instance_correctly() { + + MatcherAssert.assertThat(TraceeMessage.wrap(null).getMessage(), Matchers.nullValue()); + + MatcherAssert.assertThat(TraceeMessage.wrap(this).getMessage(), Matchers.is((Object)this)); + + } +} diff --git a/core/src/test/java/io/tracee/contextlogger/outputgenerator/AbstractContextStringRepresentationBuilderTest.java b/core/src/test/java/io/tracee/contextlogger/outputgenerator/AbstractContextStringRepresentationBuilderTest.java new file mode 100644 index 0000000..805e5df --- /dev/null +++ b/core/src/test/java/io/tracee/contextlogger/outputgenerator/AbstractContextStringRepresentationBuilderTest.java @@ -0,0 +1,103 @@ +package io.tracee.contextlogger.outputgenerator; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +import io.tracee.contextlogger.api.TraceeContextStringRepresentationBuilder; +import io.tracee.contextlogger.outputgenerator.writer.BasicOutputWriterConfiguration; +import io.tracee.contextlogger.outputgenerator.writer.OutputWriterConfiguration; +import io.tracee.contextlogger.profile.Profile; + +/** + * Unit test for {@link AbstractContextStringRepresentationBuilder}. + */ +public class AbstractContextStringRepresentationBuilderTest { + + public static class TestContextStringRepresentationBuilder extends AbstractContextStringRepresentationBuilder { + + @Override + public String createStringRepresentation(final Object... instancesToLog) { + return null; + } + + @Override + public TraceeContextStringRepresentationBuilder cloneStringRepresentationBuilder() { + return null; + } + } + + TestContextStringRepresentationBuilder unit = new TestContextStringRepresentationBuilder(); + + @Test + public void getManualContextOverrides_should_handle_manual_override_map_correctly() { + + // test 1 : null valued contextual overrides + unit.setManualContextOverrides(null); + MatcherAssert.assertThat(unit.getManualContextOverrides(), Matchers.notNullValue()); + MatcherAssert.assertThat(unit.getManualContextOverrides().size(), Matchers.is(0)); + + // test 2: non null valued contextual overrrides + Map manualOverrideMap = new HashMap(); + + unit.setManualContextOverrides(manualOverrideMap); + MatcherAssert.assertThat(unit.getManualContextOverrides(), Matchers.notNullValue()); + MatcherAssert.assertThat(unit.getManualContextOverrides(), Matchers.is(manualOverrideMap)); + + } + + @Test + public void getOutputWriterConfiguration_should_handle_output_writer_configuration_correctly() { + + // test 1 : null valued output writer configuration + unit.setOutputWriterConfiguration(null); + MatcherAssert.assertThat(unit.getOutputWriterConfiguration(), Matchers.notNullValue()); + MatcherAssert.assertThat(unit.getOutputWriterConfiguration(), Matchers.is((OutputWriterConfiguration)BasicOutputWriterConfiguration.JSON_INTENDED)); + + // test 2: non null valued output writer configuration + unit.setOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE); + MatcherAssert.assertThat(unit.getOutputWriterConfiguration(), Matchers.notNullValue()); + MatcherAssert.assertThat(unit.getOutputWriterConfiguration(), Matchers.is((OutputWriterConfiguration)BasicOutputWriterConfiguration.JSON_INLINE)); + + } + + @Test + public void cloneTo_should_clone_all_fields_correctly() { + + Map manualOverrideMap = new HashMap(); + manualOverrideMap.put("ABC", true); + + Set wrapperClasses = new HashSet(); + wrapperClasses.add(TestContextStringRepresentationBuilder.class); + + TestContextStringRepresentationBuilder source = new TestContextStringRepresentationBuilder(); + source.setOutputWriterConfiguration(BasicOutputWriterConfiguration.JSON_INLINE); + source.setProfile(Profile.FULL); + source.setManualContextOverrides(manualOverrideMap); + source.setWrapperClasses(wrapperClasses); + source.setEnforceOrder(true); + + TestContextStringRepresentationBuilder cloneTarget = new TestContextStringRepresentationBuilder(); + + source.cloneTo(cloneTarget); + + MatcherAssert.assertThat(cloneTarget.getProfile(), Matchers.is(source.getProfile())); + MatcherAssert.assertThat(cloneTarget.getEnforceOrder(), Matchers.is(source.getEnforceOrder())); + MatcherAssert.assertThat(cloneTarget.getOutputWriterConfiguration(), Matchers.is(source.getOutputWriterConfiguration())); + + MatcherAssert.assertThat(System.identityHashCode(cloneTarget.getManualContextOverrides()), + Matchers.not(System.identityHashCode(source.getManualContextOverrides()))); + MatcherAssert.assertThat(cloneTarget.getManualContextOverrides().get("ABC"), Matchers.is(true)); + + MatcherAssert.assertThat(System.identityHashCode(cloneTarget.getWrapperClasses()), + Matchers.not(System.identityHashCode(source.getWrapperClasses()))); + MatcherAssert.assertThat(cloneTarget.getWrapperClasses().iterator().next(), + Matchers.typeCompatibleWith((Class)TestContextStringRepresentationBuilder.class)); + + } +} diff --git a/core/src/test/java/io/tracee/contextlogger/outputgenerator/functions/TraceeContextProviderWrapperFunctionTest.java b/core/src/test/java/io/tracee/contextlogger/outputgenerator/functions/TraceeContextProviderWrapperFunctionTest.java new file mode 100644 index 0000000..0ccec70 --- /dev/null +++ b/core/src/test/java/io/tracee/contextlogger/outputgenerator/functions/TraceeContextProviderWrapperFunctionTest.java @@ -0,0 +1,192 @@ +package io.tracee.contextlogger.outputgenerator.functions; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import io.tracee.contextlogger.api.ImplicitContext; +import io.tracee.contextlogger.contextprovider.TypeToWrapper; +import io.tracee.contextlogger.contextprovider.api.WrappedContextData; +import io.tracee.contextlogger.impl.ContextLoggerConfiguration; + +/** + * Unit test for {@link TraceeContextProviderWrapperFunction}. + */ +public class TraceeContextProviderWrapperFunctionTest { + + private ContextLoggerConfiguration contextLoggerConfiguration = Mockito.mock(ContextLoggerConfiguration.class); + + private TraceeContextProviderWrapperFunction unit = TraceeContextProviderWrapperFunction.getInstance(); + + public static class ClassWithNoNoargConstructor { + + public ClassWithNoNoargConstructor(String xyz) { + + } + + } + + public static class UnmappedClass { + + } + + public static class MappedClass { + + } + + public static class MappedClassWrapper implements WrappedContextData { + + private MappedClass instance; + + @Override + public void setContextData(final Object instance) throws ClassCastException { + this.instance = (MappedClass)instance; + } + + @Override + public MappedClass getContextData() { + return this.instance; + } + + @Override + public Class getWrappedType() { + return MappedClass.class; + } + } + + public static class IncorrectMappedClass { + + } + + public static class IncorrectMappedClassWrapper { + + } + + public static class WrappedTypeListType { + + } + + public static class WrappedTypeListTypeWrapper implements WrappedContextData { + + private WrappedTypeListType instance; + + @Override + public void setContextData(final Object instance) throws ClassCastException { + this.instance = (WrappedTypeListType)instance; + } + + @Override + public WrappedTypeListType getContextData() { + return this.instance; + } + + @Override + public Class getWrappedType() { + return WrappedTypeListType.class; + } + } + + @Before + public void init() { + + Map implicitContextClassMap = new HashMap(); + implicitContextClassMap.put(ImplicitContext.COMMON, TraceeContextProviderWrapperFunctionTest.class); + + when(contextLoggerConfiguration.getImplicitContextClassMap()).thenReturn(implicitContextClassMap); + + Map classToWrapperMap = new HashMap(); + classToWrapperMap.put(MappedClass.class, MappedClassWrapper.class); + classToWrapperMap.put(IncorrectMappedClass.class, IncorrectMappedClassWrapper.class); + + when(contextLoggerConfiguration.getClassToWrapperMap()).thenReturn(classToWrapperMap); + + List typeToWrapperList = new ArrayList(); + typeToWrapperList.add(new TypeToWrapper(WrappedTypeListType.class, WrappedTypeListTypeWrapper.class)); + + when(contextLoggerConfiguration.getWrapperList()).thenReturn(typeToWrapperList); + + } + + @Test + public void apply_should_handle_implicit_context_correctly() { + + Object result = unit.apply(contextLoggerConfiguration, ImplicitContext.COMMON); + assertThat(result, Matchers.notNullValue()); + assertThat(result.getClass(), Matchers.typeCompatibleWith(this.getClass())); + + } + + @Test + public void apply_should_handle_known_mapped_context_class_correctly() { + + Object instance = new MappedClass(); + + Object result = unit.apply(contextLoggerConfiguration, instance); + + assertThat(result, Matchers.notNullValue()); + assertThat(result.getClass(), Matchers.typeCompatibleWith(MappedClassWrapper.class)); + + } + + @Test + public void apply_should_handle_type_to_wrapper_type_correctly() { + + Object instance = new WrappedTypeListType(); + + Object result = unit.apply(contextLoggerConfiguration, instance); + + assertThat(result, Matchers.notNullValue()); + assertThat(result.getClass(), Matchers.typeCompatibleWith(WrappedTypeListTypeWrapper.class)); + + } + + @Test + public void apply_should_handle_broken_known_mapped_context_class_correctly() { + + Object instance = new IncorrectMappedClass(); + + Object result = unit.apply(contextLoggerConfiguration, instance); + + // should return passed instance if mapping is broken + assertThat(result, Matchers.notNullValue()); + assertThat(result, Matchers.is(instance)); + + } + + @Test + public void apply_should_return_passed_instance_if_no_wrapper_can_be_found() { + + Object instance = new UnmappedClass(); + + Object result = unit.apply(contextLoggerConfiguration, instance); + assertThat(result, Matchers.notNullValue()); + assertThat(result, Matchers.is(instance)); + + } + + @Test + public void createInstance_should_create_instance_correctly() { + Object result = unit.createInstance(this.getClass()); + + assertThat(result, Matchers.notNullValue()); + assertThat(result.getClass(), Matchers.typeCompatibleWith(this.getClass())); + } + + @Test + public void createInstance_should_create_null_for_type_with_no_noarg_constructor() { + + Object result = unit.createInstance(ClassWithNoNoargConstructor.class); + + assertThat(result, Matchers.nullValue()); + + } +}