Skip to content

Only fields with name-matching injectables get injected into fullyInitialized SUT #343

@Vampire

Description

@Vampire

According to the JavaDoc of fullyInitialized, each and every field that otherwise stays null should be initialized.

Having the SUT

public class Foo {
    String foo;
    String bar;
}

and the test class

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

    @Injectable("bam")
    String bam;

    @Injectable("baz")
    String baz;

    @Test
    public void test() {
        System.out.println(sut.foo);
        System.out.println(sut.bar);
    }
}

no field gets filled, though two type-matching injectables are found.

With the test class

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

    @Injectable("bam")
    String bam;

    @Injectable("bar")
    String bar;

    @Test
    public void test() {
        System.out.println(sut.foo);
        System.out.println(sut.bar);
    }
}

only the bar field is filled.

With the test class

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

    @Injectable("foo")
    String foo;

    @Injectable("baz")
    String baz;

    @Test
    public void test() {
        System.out.println(sut.foo);
        System.out.println(sut.bar);
    }
}

only the foo field is filled.

With the test class

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

    @Injectable("foo")
    String foo;

    @Injectable("bar")
    String bar;

    @Test
    public void test() {
        System.out.println(sut.foo);
        System.out.println(sut.bar);
    }
}

both fields are filled.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions