In the following test case where no Expectations have been recorded, I would expect that the dynamic partial mocking feature will be used for the fields A and B which are initialized in UnitToTest using @Injectable. But instead always the method calls are mocked. Only using an invalid filter value for static partial mocking, it is possible to call the real methods:
@Service
class A {
public String doSomething() { return "doSomething"; }
public String doSomethingElse() { return "doSomethingElse"; }
}
@Service
class B {
public String doSomething() { return "doSomething"; }
public String doSomethingElse() { return "doSomethingElse"; }
}
@Service
class UnitToTest {
@Autowired B b;
@Autowired A a;
public B getB() { return b; }
public A getA() { return a; }
}
public class TestClass {
@Tested UnitToTest unit;
// @Mocked({ "someInvalidFilter()" })
@Injectable A a;
// @Mocked({ "someInvalidFilter()" })
@Injectable B b;
@Test
public void test() {
// actual return value is always null if no invalid static partial
// mocking filters are specified above
assertEquals("doSomething", unit.getA().doSomething());
assertEquals("doSomethingElse", unit.getA().doSomethingElse());
assertEquals("doSomething", unit.getB().doSomething());
assertEquals("doSomethingElse", unit.getB().doSomethingElse());
}
}
For me it looks like dynamic partial mocking with JMockit doesn't work for @Injectables. Is that a known restriction?
Aucun commentaire:
Enregistrer un commentaire