Search code examples
grailsmockinggooglemock

Grails unit tests - checking arguments when using demand on mock


I can test that a mock method is called using 'demand'. However, i would like to also make sure the expected arguments are passed to the method. How can i do that?


Solution

  • I believe a simple assert within the demand closure will probably suffice.

    def mockedBook = mockFor(Book)
    
    mockedBook.demand.read { String author, String name ->
      assert author == 'Tolstoy'
      assert name == 'War and Peace'
    
      return true
    }