package com.netflix.governator;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;

import org.junit.Before;
import org.junit.Test;

import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.netflix.governator.event.guava.GuavaApplicationEventModule;

public class NullableBindingTest {

    private Injector injector;

    @Before
    public void setup() {
        injector = InjectorBuilder.fromModules(new GuavaApplicationEventModule(), new AbstractModule() {
            @Override
            protected void configure() {
                bind(InnerDependency.class).toProvider(new Provider<InnerDependency>() {
                    @Override
                    public InnerDependency get() {
                        return null;
                    }
                });               
            }
        }).createInjector();
    }
    
    @Test
    public void test() {
        OuterDependency instance = injector.getInstance(OuterDependency.class);
        assertNotNull(instance);
        assertNull(instance.innerDependency);
    }


    private static class OuterDependency {

        InnerDependency innerDependency;
        
        @Inject
        public OuterDependency(@Nullable InnerDependency innerDependency) {
            this.innerDependency = innerDependency;
        }
    }

    @Singleton
    private static class InnerDependency {

    }
}



@@ -360,24 +360,29 @@
 .inject.
+util.
 Provider
 ;%0Aimport
@@ -373,16 +373,17 @@
 Provider
+s
 ;%0Aimport
@@ -515,17 +515,21 @@
 jector;%0A
+    
 %0A
-
     @Bef
@@ -785,20 +785,16 @@
 der(
-new 
 Provider
 %3CInn
@@ -789,16 +789,18 @@
 Provider
+s.
 %3CInnerDe
@@ -812,170 +812,16 @@
 ncy%3E
-() %7B%0A                    @Override%0A                    public InnerDependency get() %7B%0A                        return null;%0A                    %7D%0A                %7D
+of(null)
 );  

use providers util for null provider