import org.joda.time.LocalDate
import static org.joda.time.Days.*
date1 = new LocalDate(2008, 3, 10)
date2 = new LocalDate(2008, 3, 12)
assert 2 == daysBetween(date1, date2).days
What's not to like? :o)
import org.joda.time.LocalDate
import static org.joda.time.Days.*
date1 = new LocalDate(2008, 3, 10)
date2 = new LocalDate(2008, 3, 12)
assert 2 == daysBetween(date1, date2).days
void testUpdateNotFound() {
def bc
def mock = new MockFor(BookmarkController)
mock.demand.redirect { Map params ->
assert params.action == bc.edit
}
mock.use {
bc = new BookmarkController()
bc.params.id = 5
bc.update.call()
}
}
import groovy.mock.interceptor.*
class BookmarkController {
def update = { redirect("value from original") }
def redirect = { println "Original class: $it" }
}
class BookmarkTests extends GroovyTestCase {
void testUpdate() {
def bc
def mock = new MockFor(BookmarkController)
mock.demand.redirect { println "Mock class: $it" }
mock.use {
bc = new BookmarkController()
bc.&update.call()
}
}
}
new BookmarkController().&update.call()
new BookmarkTests().testUpdate()