Exemplo n.º 1
0
    @Test
    public void shouldCorrectlyInstantiateClassWithMultipleConstructorParameters() {
        injectionContext.addProvider(Key.forClass(Integer.class), new InstanceProvider<Integer>(1));
        injectionContext.addProvider(Key.forClass(String.class), new InstanceProvider<String>("s"));

        Constructor<ConstructorWithMultipleParameters> constructor = findConstructor(ConstructorWithMultipleParameters.class);
        injector(ConstructorWithMultipleParameters.class).newInstance(constructor);
    }
Exemplo n.º 2
0
    @Test
    public void shouldCorrectlyInstantiateClassWithQualifier() {
        injectionContext.addProvider(Key.forClassAndQualifier(Integer.class, TestQualifier.class), new InstanceProvider<Integer>(1));

        Constructor<ParametrizedConstructorWithQualifier> constructor = findConstructor(ParametrizedConstructorWithQualifier.class);
        ParametrizedConstructorWithQualifier instance = injector(ParametrizedConstructorWithQualifier.class).newInstance(constructor);

        assertThat(1, is(instance.i));
    }
Exemplo n.º 3
0
    @Test
    public void shouldCorrectlyInstantiateClassWithPrimitiveTypeArgument() {
        injectionContext.addProvider(Key.forClass(Integer.class), new InstanceProvider<Integer>(1));

        Constructor<ParametrizedConstructorWithAnnotation> constructor = findConstructor(ParametrizedConstructorWithAnnotation.class);
        ParametrizedConstructorWithAnnotation instance = injector(ParametrizedConstructorWithAnnotation.class).newInstance(constructor);

        assertThat(1, is(instance.i));
    }
Exemplo n.º 4
0
    @Test
    public void shouldCorrectlyInstantiateClassWithUserTypeArgument() {
        DefaultConstructor defaultConstructor = new DefaultConstructor();
        injectionContext.addProvider(Key.forClass(DefaultConstructor.class), new InstanceProvider<DefaultConstructor>(defaultConstructor));

        Constructor<UserTypeInjection> constructor = findConstructor(UserTypeInjection.class);
        UserTypeInjection instance = injector(UserTypeInjection.class).newInstance(constructor);

        assertThat(defaultConstructor, is(instance.i));
    }