Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Testing and the fly likes null pointer exception while running unit test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "null pointer exception while running unit test" Watch "null pointer exception while running unit test" New topic
Author

null pointer exception while running unit test

irshad irshadoz
Greenhorn

Joined: Jan 16, 2013
Posts: 6
Hello,

i am running my unit test but for some reason i am getting a null pointer on this line

[code=java

mav.addObject(
"failLog",
messageSource.getMessage("login.user.fail", new String[] {
"a", "b" }, request.getLocale()));
][/code]

Please find below the method that my unit test will be based on:



Please find below my unit test:



Please see stack trace below:



line 100 for my loginController is shown below:


I am assuming that i need to mock message source. If this is the cause of my exception, how can i mock the messagesource in my unit test please?

However when i run my application it works fine no null pointer, its only when i run the unit test that i get the null pointer exception.

Thanks in advance.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Where is messageSource defined? I don't see it as an instance variable, parameter or local variable.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null pointer exception while running unit test
 
Similar Threads
Getting an EJB session bean which uses @SecurityDomain annotation, in a unit test case through JNDI
lookup for remote bean - failure (only from eclipse)
how to mock return value of method
assertEquals is wrong?
Class cast exception when grabbing remote EJB 3 interface