title: When unit testing (with Mockito), should I "implement" the internal logic when mocking?
body: <p>Edit:
  Sorry, my example is not very proper, I changed it a little.</p>
  
  <p>I'm not sure if the title shows my question properly.<br>
  For example, I have functions:</p>
  
  <pre><code>class Dependency {
      // create an element with id and data, add it into a list and return the element
      public Element addElement(int id, data d) throws SomeException;
  
      // remove an element from the list and return it
      public Element removeElement(int id) throws SomeException;
  }
  </code></pre>
  
  <p>Then I can mock it like:</p>
  
  <pre><code>private Element mockElement(int id, data dt) {
      Element e = mock(Element.class);
      when(e.getId()).thenReturn(id);
      when(e.getData()).thenReturn(dt);
      return e;
  }
  
  private Dependency mockDependency() {
      List l = new List();
      Dependency dependency = mock(Dependency.class);    
  
      // should I "implement" the internal logic when mocking?
      when(dependency.addElement(intCaptor.capture(), dataCapture.capture())).thenAnswer(a-&gt;{
          int id = intCaptor.getValue();
          data dt = dataCaptor.getValue();
          if (id &lt; 0) { throw someException; }
          Element e = mockElement(id, dt);
          l.add(e);
          return e;
      };
  
      when(dependency.removeElement(intCaptor.capture())).thenAnswer(a-&gt;{
          int id = intCaptor.getValue();
          if (id &lt; 0) { throw someException; }
          Element e = l.findElementInListById(id);
          if (e == null) { return null; }
          l.remove(e);
          return e;
      };
      return dependency;
  }
  
  ...
  
  @Test
  public void test() {
      ...
      Dependency dependencyMock = mockDependency();
      MyClass c = new MyClass(dependencyMock);
  
      // it calls dependency.addElement()
      c.addElement(1, data)
  
      // it calls dependency.removeElement()
      assertEquals(1, c.removeElement(1).getId());
      ...
  }    
  </code></pre>
  
  <p>This does work, but I wonder if it is a good idea to do so. All the examples I can find online about Mockito are basically simple when().then() statements. Can anyone please give me some advice?</p>