Monday, April 12, 2010

Grails goof-ups

Wanted to write simple test cases. Caught up for an hour in the following. Should have shown a compile-time error had it been strongly-typed language
Try and spot the difference between the following two groovy statements
Hint: Having statement 1 throws an "org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No such property: changefreq for class: MyServiceTests"
Statement2 is the correct one.

Statement 1:
mockDomain(NewSitemapUrl, [
    new NewSitemapUrl(id: 10, loc:"http://example.com/10",lastmod:today, changefreq:"daily", priority: '1.0'),
new NewSitemapUrl(id: 20, loc:"http://example.com/20", lastmod:today, changefreq="daily", priority:'1.0'),
new NewSitemapUrl(id: 30, loc:"http://example.com/30", lastmod:today, changefreq="daily", priority:'1.0')
])

Statement 2: 
mockDomain(NewSitemapUrl, [ 
    new NewSitemapUrl(id: 10, loc:"http://example.com/10",lastmod:today, changefreq:"daily", priority: '1.0'),
new NewSitemapUrl(id: 20, loc:"http://example.com/20", lastmod:today, changefreq:"daily", priority:'1.0'),
new NewSitemapUrl(id: 30, loc:"http://example.com/30", lastmod:today, changefreq:"daily", priority:'1.0')
])

No comments:

Post a Comment