title: grails, unit test mock domain with assigned id
body: <p>I am using assigned id in my domain </p>
  
  <pre><code>class Book {
  
  Integer id
  String name
  
  static mapping = {
      id generator: 'assigned'
      }   
  }
  </code></pre>
  
  <p>so to add a new book:</p>
  
  <pre><code>def book = new Book([name: "The Adventures of Huckleberry Finn"])
  book.id = 123
  book.save(flush: true)
  </code></pre>
  
  <p>everything works perfectly, the problem is in my unit tests</p>
  
  <p>first of all I can only mock 1 domain class,
  secondly, I cannot use .save() on unit test, so my only option (as far as i know) is to use mockDomain as follow:</p>
  
  <pre><code>mockDomain(Book, [ [id: 123, name: "The Adventures of Huckleberry Finn"] ])
  </code></pre>
  
  <p>but it is not working, it would work in a normal domain without "id generator: 'assigned'"</p>
  
  <p>any ideas?
  I read that I wouldn't face this problem in integrated test, it is just a problem in unit test
  thanks </p>