New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only the first @Injectable is considered when searching for fullyInitialized constructor arguments #341

Closed
Vampire opened this Issue Sep 22, 2016 · 1 comment

Comments

2 participants
@Vampire

Vampire commented Sep 22, 2016

Having the SUT

public class Foo {
    String foo;
    @Inject
    Bar bar;

    static class Bar {
        public Bar(String bar) {
        }
    }
}

and the test class

public class FooTest {
    @Tested(fullyInitialized = true)
    Foo sut;

    @Injectable
    String foo;

    @Injectable
    String bang;

    @Test
    public void test() {
    }
}

you will get the error java.lang.IllegalArgumentException: No injectable value available for parameter "foo" in constructor Foo$Bar#Bar(String bar), because injectable foo was already consumed for field foo and constructor parameter injection only looks at the first candidate which it sees as already consumed.

If you change the test class to

public class FooTest {
    @Tested(fullyInitialized = true)
    Foo sut;

    @Injectable
    String bang;

    @Injectable
    String foo;

    @Test
    public void test() {
    }
}

it works fine, because for field foo the name-matching injectable foo is used and for the Bar constructor the first found injectable bang is used.

The following of course also works due to the name-matching:

public class FooTest {
    @Tested(fullyInitialized = true)
    Foo sut;

    @Injectable
    String foo;

    @Injectable
    String bar;

    @Test
    public void test() {
    }
}
@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Sep 22, 2016

Member

Seems like a bug. Thanks for reporting it!

Member

rliesenfeld commented Sep 22, 2016

Seems like a bug. Thanks for reporting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment