diff options
3 files changed, 15 insertions, 2 deletions
diff --git a/sangria-log4j/pom.xml b/sangria-log4j/pom.xml index 224081d..06e892a 100644 --- a/sangria-log4j/pom.xml +++ b/sangria-log4j/pom.xml @@ -39,6 +39,12 @@ </dependency> <dependency> + <groupId>com.tavianator.sangria</groupId> + <artifactId>sangria-test</artifactId> + <scope>test</scope> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff --git a/sangria-log4j/src/main/java/com/tavianator/sangria/log4j/Log4jLoggerProvider.java b/sangria-log4j/src/main/java/com/tavianator/sangria/log4j/Log4jLoggerProvider.java index dae2323..34262d7 100644 --- a/sangria-log4j/src/main/java/com/tavianator/sangria/log4j/Log4jLoggerProvider.java +++ b/sangria-log4j/src/main/java/com/tavianator/sangria/log4j/Log4jLoggerProvider.java @@ -19,6 +19,7 @@ package com.tavianator.sangria.log4j; import javax.inject.Singleton; +import com.google.inject.Inject; import com.google.inject.spi.InjectionPoint; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -34,6 +35,10 @@ import com.tavianator.sangria.contextual.ContextSensitiveProvider; */ @Singleton class Log4jLoggerProvider implements ContextSensitiveProvider<Logger> { + @Inject + Log4jLoggerProvider() { + } + @Override public Logger getInContext(InjectionPoint injectionPoint) { return LogManager.getLogger(injectionPoint.getDeclaringType().getRawType()); diff --git a/sangria-log4j/src/test/java/com/tavianator/sangria/log4j/SangriaLog4jModuleTest.java b/sangria-log4j/src/test/java/com/tavianator/sangria/log4j/SangriaLog4jModuleTest.java index d91cf90..a3ecd66 100644 --- a/sangria-log4j/src/test/java/com/tavianator/sangria/log4j/SangriaLog4jModuleTest.java +++ b/sangria-log4j/src/test/java/com/tavianator/sangria/log4j/SangriaLog4jModuleTest.java @@ -29,6 +29,7 @@ import org.apache.logging.log4j.Logger; import org.junit.Before; import org.junit.Test; +import static com.tavianator.sangria.test.SangriaMatchers.*; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @@ -74,7 +75,8 @@ public class SangriaLog4jModuleTest { } @Test - public void testDeDuplication() { - Guice.createInjector(new SangriaLog4jModule(), new SangriaLog4jModule()); + public void testBestPractices() { + assertThat(new SangriaLog4jModule(), is(atomic())); + assertThat(new SangriaLog4jModule(), followsBestPractices()); } } |