Mocking Spring Security Context for Unit


Mocking Spring Security Context for Unit Testing – Today, while writing unit test case for one of the Java method which looks like below: public ApplicationUser getApplicationUser() { ApplicationUser applicationUser = (ApplicationUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return applicationUser; } I want to mock Spring Security Context to get the Principal, to achieve the same I mocked each level of method calls as follows: import org.j… http://ow.ly/oOaV50bChyM

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s