package examples.basics;

import org.diablitozzz.jin.Jin;
import org.diablitozzz.jin.JinException;
import org.diablitozzz.jin.JinInject;
import org.diablitozzz.jin.impl.JinBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;

public class Injection {
    
    public static class Depend {
    }

    public static class UserService {
        
        @JinInject
        public Depend singleton;

        @JinInject(name = "named")
        public Depend singletonNamed;

        @JinInject(singleton = false)
        public Depend instance;
        
        @JinInject(name = "named", singleton = false)
        public Depend instanceNamed;

    }
    
    @Test
    public void test() throws JinException {

        final Jin jin = JinBuilder.NEW().build();
        final UserService us = jin.singleton(UserService.class);
        
        Assert.assertNotNull(us.singleton);
        Assert.assertNotNull(us.singletonNamed);
        Assert.assertNotNull(us.instance);
        Assert.assertNotNull(us.instanceNamed);
        
        Assert.assertTrue(us.singleton != us.singletonNamed);
        Assert.assertTrue(us.singleton != us.instance);
        Assert.assertTrue(us.singleton != us.instanceNamed);
        Assert.assertTrue(us.singletonNamed != us.instance);
        Assert.assertTrue(us.singletonNamed != us.instanceNamed);
        Assert.assertTrue(us.instance != us.instanceNamed);
        Assert.assertTrue(us.singleton == jin.singleton(Depend.class));
        Assert.assertTrue(us.singletonNamed == jin.singleton(Depend.class, "named"));
    }

}
