Skip to content
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

ENH: Enhance @InjectTest with support for @Setup methods & when @Inject, @Mock provide values use them #260

Closed
rbygrave opened this issue Jan 12, 2023 · 0 comments · Fixed by #259
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@rbygrave
Copy link
Contributor

Add support for @Setup methods like:

  @Inject
  HelloService helloService;

  HelloData myTestDouble;

  @Setup
  void setup(BeanScopeBuilder builder) {
    myTestDouble = mock(HelloData.class);
    when(myTestDouble.helloData()).thenReturn("MockedViaSetupMethod");
    builder.bean(HelloData.class, myTestDouble);
  }

  @Test
  void hello_1() {
    assertEquals("hello+MockedViaSetupMethod", helloService.hello());
  }

Change such that when @Inject field has a value then it's expected to be a provided test double and the instance value is registered and used for wiring.

  @Inject HelloService helloService;    // Get this OUT of the DI BeanScope

  @Inject HelloData myTestDouble = () -> "ImActuallyATestDouble";    // Put this INTO the DI BeanScope

  @Test
  void hello_1() {
    assertEquals("hello+ImActuallyATestDouble", helloService.hello());
    assertEquals("ImActuallyATestDouble", myTestDouble.helloData());
  }
rbygrave added a commit that referenced this issue Jan 13, 2023
@rbygrave rbygrave self-assigned this Jan 13, 2023
@rbygrave rbygrave added the enhancement New feature or request label Jan 13, 2023
@rbygrave rbygrave added this to the 8.12 milestone Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant