コード例 #1
0
  @Test
  public void testAllInjectionElementsArePopulated() {
    // given
    when(mockedMockEngine.createMock(Object.class)).thenReturn(new Object());
    engine = new InjectionEngine(mockedMockEngine);

    // when
    SutDescriptor<ClassWithAllTypesOfInjectionElements> sutDescriptor =
        engine.createAndInject(
            ClassWithAllTypesOfInjectionElements.class, new AnnotatedInjectionPoint(Inject.class));

    // then
    assertThat(sutDescriptor).isNotNull();
    assertThat(sutDescriptor.getMocks()).hasSize(5);

    ClassWithAllTypesOfInjectionElements sut = sutDescriptor.getSystemUnderTest();

    assertThat(sut.getFieldInjectionPoint()).isNotNull().isInstanceOf(Object.class);
    assertThat(sut.getNotMeantForInjection()).isNull();
    assertThat(sut.getUsedBySetterInjector()).isNotNull();
    assertThat(sut.getUsedByPrivateSetterInjector()).isNotNull();

    assertThat(sut.getFirstArgSetByCtor()).isNotNull();
    assertThat(sut.getSecondArgSetByCtor()).isNotNull();
  }
コード例 #2
0
  @Test
  public void testNoArgumentsCtorIsUsedAndFieldsAreSettersInjectionElementsAreUsed() {
    // given
    when(mockedMockEngine.createMock(Object.class))
        .thenReturn(new Object())
        .thenReturn(new Object())
        .thenReturn(new Object());

    // when
    SutDescriptor<ClassWithFieldAndSetterInjectionElements> sutDescriptor =
        engine.createAndInject(
            ClassWithFieldAndSetterInjectionElements.class,
            new AnnotatedInjectionPoint(Inject.class));

    // then
    assertThat(sutDescriptor).isNotNull();
    assertThat(sutDescriptor.getSystemUnderTest()).isNotNull();

    ClassWithFieldAndSetterInjectionElements sut = sutDescriptor.getSystemUnderTest();

    assertThat(sut.getFieldInjectionPoint()).isNotNull().isInstanceOf(Object.class);
    assertThat(sut.getNotMeantForInjection()).isNull();

    assertThat(sut.getUsedBySetterInjector()).isNotNull();
    assertThat(sut.getUsedByPrivateSetterInjector()).isNotNull();
  }