miércoles, 13 de abril de 2011

Mocking the lock method

Just another issue with the grails unit test. I found, (like many others i guess jeje), that the static lock method is not mocked when i use mockDomain(Something).

There is a simple way to mock this:

// URLController.groovy
public class SomethingToTest extends GrailsUnitTestCase{
    public void test_lockMethod(){
        def strictControlUser = mockFor(User); 
        //And then simply do:
        strictControlUser.demand.static.lock(1..1){ Long param1 ->
        return User.get(param1); //In the unit test the get simply works 
    }
}

And done!
Now we are happy again

No hay comentarios:

Publicar un comentario