title: How to mock static Map property in grails service class unit test
body: <p>I have a static map in a service class.I am unit testing the method which populates the map. I want to know how to mock the map used in the service class.</p>
  
  <pre><code>SomeService
  --------------
  
  class SomeService {
      static Map&lt;Integer,String&gt; tempMap = new HashMap&lt;Integer,String&gt;()
          //This map is used in some other service api
  }
  
  OtherService
  ------------
  
  class OtherService {
      void method1(Integer i, String str) {
          // here it populates the map
          def test = SomeService.tempMap.put(i,str)
          println "After putting : "+test 
      }
  }
  </code></pre>
  
  <p>Unit test case</p>
  
  <pre><code>OtherServiceTests
  ------------------
  class OtherServiceTests {
      void testMethod1() {
          def mockedMap = mockFor(Map)
          SomeService.metaClass.static.tempMap = mockedMap.createMock()
          SomeService.metaClass.static.tempMap.put = {Integer i, String str -&gt; "Testing"} // how to mock??
      }
  }
  </code></pre>
  
  <p>When I run the test case it is invoking the real map instead of making use of the mocked <code>"put"</code> api, which is returning null instead of "testing"
  I tried couple of ways to mock it but still no luck. How to mock <code>Map api</code> which is a <code>static</code> property of a service class?</p>