title: Cannot mock grails domain class
body: <p>someone, please, explain why domain class behaves different when is mocked with new MockFor(..)?
  I use grails 2.4.1.
  I have create domain class GTest:</p>
  
  <pre><code>class GTest {
      static constraints = {
      }
  
      String amethod() {
          return "GTest.amethod"
      }
  }
  </code></pre>
  
  <p>And a groovy class DTest:</p>
  
  <pre><code>class DTest {
  
      String amethod() {
          return "DTest.amethod"
      }
  }
  </code></pre>
  
  <p>And here a groovy test:</p>
  
  <pre><code>class GroovyJUnitTest {
  
      @Test
      void testDTestAmethod() {
          def mock = new MockFor(DTest)
          mock.demand.amethod {
              return "Mock DTest"
          }
  
          mock.use {
              def dtest = new DTest()
              // Here dtest.metaClass=groovy.mock.interceptor.MockProxyMetaClass@...
              def ret = dtest.amethod()
              // This assertation successes
              assertEquals "Mock DTest", ret
          }
      }
  
      @Test
      void testGTestAmethod() {
          def mock = new MockFor(GTest)
          mock.demand.amethod {
              return "Mock GTest"
          }
  
          mock.use {
              def gtest = new GTest()
              // Here dtest.metaClass=groovy.lang.ExpandoMetaClass@...
              def ret = gtest.amethod()
              // This assertation fails
              assertEquals "Mock GTest", ret
          }
      }
  }
  </code></pre>
  
  <p>So, this question is how should Domain class be mocked programmatically?
  Thank you for explanation.</p>