title: How to write test cases for the following method that holds the local object return by the database?
body: <p>Currently, I am using TestNG and try to write the test case for the 
  manipulateMetaData() method. Inside that method, metaData is given by the repository. And then the metaData is updated according to the given list of contact.</p>
  
  <p>I stuck while writing the test case for manipulateMetaData() method.</p>
  
  <pre><code>public class MetaData {
  
      String email;
      Map&lt;String, Integer&gt; count = new HashMap&lt;&gt;();
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public void updateCount(List&lt;String&gt; contact) {
          // perform the calculation and update the count.
      }
  }
  
  public class MetaDataHandler {
  
      @Autowired
      MetaDataRepository metaDataRepository;
  
      public MetaData manipulateMetaData(String emailAddress, List&lt;String&gt; contact) {
          MetaData metaData = metaDataRepository.findOneByEmail(emailAddress);
  
          if (metaData == null) {
              metaData = new MetaData();
              metaData.setEmail(emailAddress);
          }
  
          metaData.updateCount(contact);
  
          return metaData;
      }
  }
  </code></pre>
  
  <p>TestCase</p>
  
  <pre><code>@Mock
  MetaDataRepository metaDataReporitory;
  
  @InjectMocks
  MetaDataHandler metaDataHandler = new MetaDataHandler();
  
  @BeforeMethod
  public void setUp() {
      MockitoAnnotations.initMocks(this);
  }
  
  @Test
  public void testManipulateMetaData() {
      List&lt;String&gt; contact = new ArrayList&lt;&gt;();
  
      String emailAddress = "someone@gmail.com";
  
      Mockito.when(metaDataReporitory.findOneByEmail(emailAddress)).thenReturn(null);
     //Stuck Here
     //Want to test manipulateMetaData() method
  }
  </code></pre>