Timing problem in Eclipse

Posted by Mike Haller on Friday, March 23. 2007 at 00:00 in Java

Is this a timing problem in Eclipse, in JUnit4 or in Java 6 (Mustang) ?

See the test, which is assumed to fail after approx 5seconds. In reality, you have to wait twice the time - 10 seconds - for it to fail. Why?

EasyMock Arguments

Posted by Mike Haller on Sunday, March 4. 2007 at 08:26 in Java
EasyMock Arguments

To mock objects, you need to know which methods are called with what parameters, so you can assert them.
For simple parameters like Strings or numbers, this is easy and you can record the value just by simply calling
the method:

IMyMock mock = myControl.createMock(IMyMock.class);
mock.doSomething("Foo"); // Point of interest
mock.replay();

// This will call IMyMock.doSomething("Bar")
// public void methodUnderTest() { myMock.doSomething("Bar"); }
classUnderTest.methodUnderTest();

// This will compare "Foo" with "Bar" and fail the test
mock.verify();


Here, mock.doSomething("Foo") will 1) record the method invocation of doSomething and 2) record the value "Foo"
for the first and only parameter.

For more complex parameter objects, or if you want to ease restrictions, you will probably want
to implement your own EasyMock IArgumentMatcher. In this case, the actual parameter within the unit test
source code does not matter and you can use null for them...

How to Mock a thirdparty final class

Posted by Mike Haller on Friday, March 2. 2007 at 17:45 in Java
Thirdparty - you dont have access to the source code and can let the class implement an interface.
Final - you cannot use JMock or EasyMock Feature using CGLIB to manipulate the class.
So, what can you do to mock (simulate) the thirdparty class in your application?

About

My name is Mike Haller and I'm a software developer and architect at Bosch Software Innovations in Germany. I love programming, playing games and reading books. I like good food, making photos and learning and mentoring about the craftsmanship of commercial software development. Stack Overflow profile for mhaller

Quicksearch

Archives