title: How to get started with testing(jMock)
body: <p>I'm trying to learn how to write tests. I'm also learning Java, I was told I should learn/use/practice jMock, I've found some articles online that help to certain extend like :</p>
  
  <p><a href="http://www.theserverside.com/news/1365050/Using-JMock-in-Test-Driven-Development" rel="nofollow noreferrer">http://www.theserverside.com/news/1365050/Using-JMock-in-Test-Driven-Development</a></p>
  
  <p><a href="http://jeantessier.com/SoftwareEngineering/Mocking.html#jMock" rel="nofollow noreferrer">http://jeantessier.com/SoftwareEngineering/Mocking.html#jMock</a></p>
  
  <p>And most articles I found was about test driven development, write tests first then write code to make the test pass. I'm not looking for that at the moment, I'm trying to write tests for already existing code with jMock. </p>
  
  <p>The <a href="http://www.jmock.org/getting-started.html" rel="nofollow noreferrer">official documentation</a> is vague to say the least and just too hard for me. Does anybody have better way to learn this. Good books/links/tutorials would help me a lot.  thank you</p>
  
  <p><strong>EDIT - more concrete question :</strong></p>
  
  <p><a href="http://jeantessier.com/SoftwareEngineering/Mocking.html#jMock" rel="nofollow noreferrer">http://jeantessier.com/SoftwareEngineering/Mocking.html#jMock</a> - from this article </p>
  
  <p><em>Tried this to mock this simple class :</em></p>
  
  <pre><code>import java.util.Map;
      public class Cache {
          private Map&lt;Integer, String&gt; underlyingStorage;
          public Cache(Map&lt;Integer, String&gt; underlyingStorage) {
              this.underlyingStorage = underlyingStorage;
          }
          public String get(int key) {
              return underlyingStorage.get(key);
          }
          public void add(int key, String value) {
              underlyingStorage.put(key, value);
          }
          public void remove(int key) {
              underlyingStorage.remove(key);
          }
          public int size() {
              return underlyingStorage.size();
          }
          public void clear() {
              underlyingStorage.clear();
          }
      }
  </code></pre>
  
  <p>Here is how I tried to create a test/mock :</p>
  
  <pre><code>public class CacheTest extends TestCase {
  
      private Mockery context;
      private Map mockMap;
      private Cache cache;
  
      @Override
      @Before
      public void setUp() {
          context = new Mockery() {
              {
                  setImposteriser(ClassImposteriser.INSTANCE);
              }
          };
  
          mockMap = context.mock(Map.class);
          cache = new Cache(mockMap);
      }
  
      public void testCache() {
          context.checking(new Expectations() {{
              atLeast(1).of(mockMap).size(); 
              will(returnValue(int.class));
          }});
  
      }
  }
  </code></pre>
  
  <p>It passes the test and basically does nothing, what I wanted is to create a map and check its size, and you know work some variations try to get a grip on this. Understand better trough examples, what else could I test here or any other exercises would help me a lot. tnx</p>