tags:

views:

57

answers:

2

Is there any framework, whick allows to mock concrete classes, not only interfaces in java 1.4? I have third party code with a singleton class, where I wanna change one function, without touching orignal code. Is it possible?

+1  A: 

I recommend Mockito. A port to Java 1.4 is available here.

Robert Petermeier
+1  A: 

JMock 1.2 supports this. Details here.

Yishai
Can I use JMock without unit tests? As I see I need to extend class MockObjectTestCase? In my situation it would be very unhandy to use unit tests...
Filip
You don't need to use a unit test, but certain methods will need to be run. I haven't tried it, but you can check the source code of MockObjectTestCase and see if it does anything special that has to be called separately.
Yishai
Is it possible to mock some class so _all_ instantiation of some class created after some moment are mocked? I know it is possible in jmockit, but it's only available for newer java.
Filip
@Filip, I don't think JMock naitively supports such a concept. Of course you could fake it by having a factory produce the object with that logic in it. AFAIK such a feature requires classloader intervention, which would make it tricky to run in a production system.
Yishai