Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong><code>cmd</code> is not <code>null</code></strong>; however, <code>assertTrue</code> throws an <code>AssertionFailedError</code> with a <code>null</code> message. Either provide a default message (<code>assertTrue "default message", cmd.hasErrors()</code>) or just state, <code>assert cmd.hasErrors()</code>.</p> <p>So, let's see why <code>cmd.hasErrors()</code> returns <code>false</code>. - That's because the custom validator does not return <code>false</code>, but some string instead, that evaluates to <code>true</code> according to the "Groovy Truth". (There, the Grails API appears to have changed since the book has been published.)</p> <p>In the <code>LoginCommand</code> class, change</p> <pre><code>login blank:false, validator:{ val, cmd -&gt; if(!cmd.user) return "user.not.found" } </code></pre> <p>to</p> <pre><code>login blank:false, validator:{ val, cmd -&gt; if(!cmd.user) return false } </code></pre> <p>Then, the error code will be "LoginCommand.login.validator".<br> If you need a custom error code, you can <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/validation/AbstractErrors.html" rel="nofollow">add an error object</a> yourself (without returning anything), like so:</p> <pre><code>login blank:false, validator:{ val, cmd -&gt; if(!cmd.user) cmd.errors.rejectValue('login', 'user.not.found') } </code></pre> <p>P.S.: You <a href="http://markmail.org/message/o6iwawbq4ouxtztw" rel="nofollow">shouldn't use</a> the <code>MockUtils</code> class, directly, but instead <code>extend GrailsUnitTest</code>. Also, <code>MockUtils.prepareForConstraintsTests(Class)</code> is deprecated; moreover, it doesn't suit well for command objects. - Use the <code>mockForConstraintsTests(Class)</code> method instead, inherited from <code>GrailsUnitTest</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload