Details
Description
Mocking validate() method as no effect. Calls to validate() always return true. It worked in Grails 2.0.0.
The test : it should be green but it isn't
@TestFor(BookController)
class BookControllerTests {
Book book
@Test
void testValid() {
def controlBook = mockFor(Book)
controlBook.demand.static.get(0..1)
controlBook.demand.validate(0..1) {-> Boolean.FALSE}
book = controlBook.createMock()
book.title = 'Title'
book.author = 'Author'
controller.test()
assert response.text == 'Book invalid'
}
}
The controller :
class BookController {
static scaffold = true
def test() {
def book = Book.get(1)
if(book.validate())
{ render "Book valid" return }render "Book invalid"
}
}
The domain class :
class Book {
String title
String author
static constraints =
{ title (nullable:false, blank: false) author (nullable:false, blank: false) }}
-
Hide
- test.zip
- 15/Feb/12 8:30 AM
- 1.06 MB
- Sebastien Errien
-
- tests/.classpath 4 kB
- tests/.../HibernateGrailsPlugin.groovy 2 kB
- tests/.link_to_grails_plugins/.../LICENSE 0.6 kB
- tests/.../application.properties 0.1 kB
- tests/.../dependencies.groovy 2 kB
- tests/.link_to_grails_plugins/.../plugin.xml 2 kB
- tests/.../_Install.groovy 0.4 kB
- tests/.../_Uninstall.groovy 0.2 kB
- tests/.../_Upgrade.groovy 0.4 kB
- tests/.../JqueryGrailsPlugin.groovy 4 kB
- tests/.../LICENSE.txt 9 kB
- tests/.../application.properties 0.1 kB
- tests/.../dependencies.groovy 0.3 kB
- tests/.../JqueryGrailsPlugin.html 14 kB
- tests/.../package-frame.html 0.7 kB
- tests/.../package-summary.html 3 kB
- tests/.../allclasses-frame.html 2 kB
- tests/.../deprecated-list.html 3 kB
- tests/.../JQueryConfig.html 7 kB
- tests/.../package-frame.html 0.7 kB
- tests/.../package-summary.html 3 kB
- tests/.../JQueryService.html 15 kB
- tests/.../package-frame.html 0.8 kB
- tests/.../package-summary.html 3 kB
- tests/.../JQueryResourceTagLib.html 10 kB
- tests/.../JQueryTagLib.html 15 kB
- tests/.../package-frame.html 0.9 kB
- tests/.../package-summary.html 4 kB
- tests/.link_to_grails_plugins/.../groovy.ico 9 kB
- tests/.../help-doc.html 7 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
If validate methode is mocked before static get methode :
controlBook.demand.validate {-> Boolean.FALSE}
{ Integer id -> id == 1 ? book : null}controlBook.demand.static.get(0..1)
Validate return false, but test fail with message :
junit.framework.AssertionFailedError: No more calls to 'validate' expected at this point. End of demands.
at grails.test.MockClosureProxy.doBeforeCall(MockClosureProxy.java:66)
at grails.test.AbstractClosureProxy.call(AbstractClosureProxy.java:74)
at grails.test.GrailsMock$_createMock_closure1.doCall(GrailsMock.groovy:125)
at tests.BookController.test(BookController.groovy:11)
at tests.BookControllerTests.testValid(BookControllerTests.groovy:33)