|
|
|
Hi James,
I'm not sure what is causing the NullPointer but I don't think the casting is the problem. I've tried executing following test: public class MockObjectCastTest extends UnitilsJUnit4 { private Mock<ClassToMock> mockClass; @Test public void testCasting() { assertNotNull("Ooops..", (TimerTask) mockClass.getMock()); } public class ClassToMock extends TimerTask { public void run() { } } } This test is succesful, so the casting seems to work. Are you sure that the mocks are being created? I think mockClass.getMock() is giving the NullPointerException. Did you extend from a unitils base class, e.g. extends UnitilsJUnit4 By extending this base class, unitils will be able to create and inject the mocks during the test Note: you can also create mocks programmatically: Mock<ClassToMock> mockClass = new MockObject<ClassToMock>("mockName', ClassToMock.class, this); grtz, Tim Ok, after a little bit more poking around, I think I figured out what's going on...
What was throwing the NPR was a lock object in the TimerTask being null. Looking at the code, it should be initialized when the object is instantiated, but isn't. So, this ties back into another bug I opened a while ago about the mocks not calling the constructors correctly. |
||||||||||||||||||||||||||||||||||||||||||||||
The way they have solved it is to create a mock that can mock multiple interfaces or classes.
I'm not sure how something like that would look with unitils, but I do believe it would make a good addition.