Thoppan / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Mockito @InjectMocks annotations on superclasses of test class are ignored #343

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
PowerMock does not support '@InjectMocks' annotations on superclasses of a 
testclass. This feature has been improved in Mockito 1.9.0 and is particularly 
useful for testing applications that make extensive use of Dependency Injection.

Here is an example that demonstrates the problem (it throws a 
NullPointerException):

interface Something {
    void invoke();
}

class ObjectUnderTest {
    private final Something _something;

    ObjectUnderTest(final Something something) {
        _something = something;
    }

    void performOperation() {
        _something.invoke();
    }
}

@Ignore
public abstract class BaseTest {
  @Mock
  Something _something;
  @InjectMocks
  ObjectUnderTest _objectUnderTest;

  @RunWith(PowerMockRunner.class)
  public static class PerformOperationTest extends BaseTest {
    @Test
    public void performsTheOperation() {
      _objectUnderTest.performOperation();

      verify(_something).invoke();
    }
  }
}

Original issue reported on code.google.com by ewald.s...@gmail.com on 19 Aug 2011 at 7:38

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for reporting and thanks for the patch. The fix is now available in 
trunk.

Original comment by johan.ha...@gmail.com on 21 Aug 2011 at 9:22