The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

gbeljaeff (2) [Avatar] Offline
#1
Hi, I'm very new to JUnit, and to Java as well...

I've succeeded in writing a Junit test that mimics a message and sends it in to an EmailGateway.onMessage() handler. The onMessage handler parses the message OK... But when I put in code that tries to create an email, JUnit fails:

junit.framework.AssertionFailedError: mockContext: Unexpected call: lookup( <java:/Mail> )
Expected no methods
at com.mockobjects.dynamic.Mock.invoke(Mock.java:91)
...

Is this something that can't be done using JUnit? Or am I missing something? Thanks.
vmassol (51) [Avatar] Offline
#2
Re: email creation in an EmailGateway.onMessage() test
Hi,

It means there is call happening (lookup()) that you have not configured in your mock context. You need to tell the mock what to do when this call happens.

-Vincent
gbeljaeff (2) [Avatar] Offline
#3
Re: email creation in an EmailGateway.onMessage() test
Thank you. This sort-of helps...
This mock stuff is very new to me -- I'm pretty much just using the examples in the JUnit In ction book, without fully understanding everything. Can you give me any helpful sample code that would help?

Thanks!
vmassol (51) [Avatar] Offline
#4
Re: email creation in an EmailGateway.onMessage() test
err... There are lots of examples in the book... (you can also download the junit in action sample zip file).

Apart from this, you can check the website for the different mock objects frameworks (EasyMock, DynaMock - now named JMock with a slightly different API, etc).

More information can also be found on www.mockobjects.com

Thanks
-Vincent