In my class under test (CUT) - an ejb - I have a private method "getConnection". I want to test another method of the CUT but this method will fail before hand.
I tried it like shown below, but "invoke" is wrong. I don't want to invoke the method, I want to stub it. But how? ('connection' is a stub)
new NonStrictExpectations() {
{
invoke(archivingBean, "getConnection");result = connection;
}
};
archivingBean.moveCreditBasic2Archive(new Date());
Your test is correct, except that it's missing a declaration for the mocked type. The EJB class, in this case.
Normally, mocked types are mocked in full (all methods). In such cases, you would declare a @Mocked MyEJB archivingBean
parameter to the test method, for example.
For partial mocking, on the other hand, you use the NonStrictExpectations(Object...)
constructor, like this:
new NonStrictExpectations(archivingBean) {{ // <== note the argument here
invoke(archivingBean, "getConnection"); result = connection;
}};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With