Trying to find the best way to do something that seems very simple: test that a specific method is a collaborator From a class under test I'm Mokito (1.9.5) & amp; PowerMock (1.5.1) with JKK6
Setting a partial mimetic via Mokita As much as possible, here is the class under trial: Here is the exam that is not working: If I remove whitebox ... for But I had this problem quite simple. This was also not possible in the first version of this question. The problem was when the Also the object ())). Then return (Mockbar); ... and pass the trial, no error. Detective is a general approach, set internal code via PowerMock
WhiteBox methods, and then I do the test Call method:
creatFoo () .
public class FooGate {BlackBox.Factory factory; black box. Repeatedly; Public Zero createFoo (Fu Fu) {Bar = Factory. Produce (blackbox bars.); Bar.create (bbFoo); } ...}
@RunWith (PowerMockRunner.class) @PrepareForTest (FooGate.class ) Public Class FooGateTest {@Test Public Zero Test ({{FooGate testGate = Mockito.spy (New FooGate ()); Blackbucks Factor docfactry = Fake (Blackbox Factor class); black box. Bark Mockbair = Fake (Blackbox Bars.); Whitebox .Setsteinstate (TestGate, Blackbox. Factor, MockFactry); Whitebox .Setsteinstate (TestGate, Blackbox Bar, Mockbair); Fu fu = new foo (); Foo.setSetting ("X"); DoAnswer (new answer & lt; null & gt; () {public zero answer (invocationOnmock invocation) {... do stuff ...}}). (Mockbar) .create (any (Foo.class)); // NPE here: It seems that the test in the bar gate is testGate.createFoo (foo); AssertStuff (...); }}
factory , I get a NPE at
factory.produce () . So, it seems that work is to be done.
doAnswer () is not apparently. Note: It does not look like it is an issue with imports, so I left them, but if you think they can be useful, then I can include them.
product at
factory i
bar was zero when I tried to call
bar.create () : hence the NPE
No comments:
Post a Comment