I have a user class like such:
class User {
transient springSecurityService
String displayName
String password
protected void encode
I think the right thing to do is to mock out the service. You'll want to test the different cases that can be the return value and that the correct value is passed to the service method.
@Test
public void something() {
def user = ...
def expectedPassword = 'mock encoded pass'
controller.springSecurityService = [encodePassword: { String passwd -> return expectedPassword }]
...
}
or
@Test
public void something() {
def user = ...
def expectedPassword = 'mock encoded pass'
def mockSecurityService = mockFor(SpringSecurityService)
mockSecurityService.demand.encodePassword { String passwd -> return expectedPassword}
controller.springSecurityService = mockSecurityService.createMock()
...
mockSecurityService.verify() // throws exception if demands aren't met
}