File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing EJB Local Bean with Mockito

 
Shashi Shankar
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am getting some nul pointer exception while testing my EJB local bean with mockito.
I am using mockito to mock entityManager for the local bean.




I am getting null pointer exception for the line 41 of local bean:
List<SourceDestination> sourceDestList = getSourceDestinationQuery.getResultList();

So any inputs to solve this issue will be really helpful.

Thanks in advance.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to record your mock. Notice that you invoke:

entityManager.createQuery(getSourceDestination, SourceDestination.class)

However your mock is not prepared for such invocation and it return null (with EasyMock you could even get Exception) - like nice mock.

To sum up, you should record your mock:
when(X).thenReturn(Y);

X - your invocation,
Y - can be empty list or another mock.


 
Shashi Shankar
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply Smith,
As per your suggestion I need to record my mock object. But still I am not getting how can I execute my test case as mentioned in earlier post.

It would be really helpful if you provide me some work around.

 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know what you want to achieve. You can run the test from Eclipse (Run as JUnit Test) or you can run it within Maven build process.

Please, precise what your problem really is.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic