FlexTradeUKLtd / jfixture

JFixture is an open source library based on the popular .NET library, AutoFixture
MIT License
105 stars 22 forks source link

Annotated fixtures in private static inner class #23

Closed anettambrus closed 8 years ago

anettambrus commented 9 years ago

FixtureRule works in the tests, however, it doesn't initialise the annotated fixtures of a private static inner class - which would be useful in cases when inner classes are used in order to make the code cleaner.

Currently the following test fails because 'new InnerClass().field' is not initialised.

public class FixtureTest {

@Rule public final FixtureRule fixtureRule = FixtureRule.initFixtures();

@Fixture private String field;

@org.junit.Test
public void test() {
    assertThat(field).isNotNull();
    assertThat(new InnerClass().field).isNotNull();
}

private static class InnerClass {

    @Fixture private String field;

}

}

richkeenan commented 8 years ago

This is because you're "newing" up the instance of InnerClass rather than getting JFixture to create it. If you use JFixture to create the instance you can remove @Fixture' from theString field` too