summaryrefslogtreecommitdiffstats
path: root/sangria-lazy/src/test
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2015-07-10 22:01:30 -0400
committerTavian Barnes <tavianator@tavianator.com>2015-07-10 22:01:30 -0400
commit8c7d863828e0bf4b9045075ff3ccd386993dfbb5 (patch)
tree4c8c374d9abb26fea0d9c65a39a8e098c6f260d3 /sangria-lazy/src/test
parent28fbf0859c63b2a30555b3295fe738c263c0db6b (diff)
downloadsangria-8c7d863828e0bf4b9045075ff3ccd386993dfbb5.tar.xz
lazy: Fix Lazy<T> when a provider returns null.
Diffstat (limited to 'sangria-lazy/src/test')
-rw-r--r--sangria-lazy/src/test/java/com/tavianator/sangria/lazy/LazyTest.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/sangria-lazy/src/test/java/com/tavianator/sangria/lazy/LazyTest.java b/sangria-lazy/src/test/java/com/tavianator/sangria/lazy/LazyTest.java
index ee6200a..a451a96 100644
--- a/sangria-lazy/src/test/java/com/tavianator/sangria/lazy/LazyTest.java
+++ b/sangria-lazy/src/test/java/com/tavianator/sangria/lazy/LazyTest.java
@@ -36,6 +36,7 @@ import com.google.inject.Provider;
import com.google.inject.spi.DefaultBindingTargetVisitor;
import com.google.inject.spi.Element;
import com.google.inject.spi.Elements;
+import com.google.inject.util.Providers;
import org.junit.Test;
import static com.tavianator.sangria.test.SangriaMatchers.*;
@@ -62,15 +63,26 @@ public class LazyTest {
@Singleton
private static class CountingProvider implements Provider<Abstract> {
int count = 0;
+ private final Provider<Abstract> impl;
@Inject
CountingProvider() {
+ this.impl = new Provider<Abstract>() {
+ @Override
+ public Abstract get() {
+ return new Abstract() { };
+ }
+ };
+ }
+
+ CountingProvider(Abstract instance) {
+ this.impl = Providers.of(instance);
}
@Override
public Abstract get() {
++count;
- return new Abstract() { };
+ return impl.get();
}
}
@@ -186,6 +198,19 @@ public class LazyTest {
assertThat(module, followsBestPractices());
}
+ @Test
+ public void testNull() {
+ Module module = new AbstractModule() {
+ @Override
+ protected void configure() {
+ bind(CountingProvider.class)
+ .toInstance(new CountingProvider(null));
+ }
+ };
+
+ test(Guice.createInjector(module), HasLazy.class);
+ }
+
@Test(expected = CreationException.class)
public void testMissingBinding() {
Guice.createInjector(new AbstractModule() {