title: How should I use mock for certain case?
body: <p>Suppose that there are classes like:</p>
  <p><strong>CivilAddSystem class :</strong></p>
  <pre><code>class CivilAddSystem{
  
      List&lt;People&gt; people = new ArrayList&lt;&gt;();
      List&lt;Town&gt; towns = new ArrayList&lt;&gt;();
  
      public People addPeople(People people) {
          people.add(people);
          return people;
      }
  
      public Town addTown(Town town) {
          towns.add(town);
          return town;
      }
  
      public House addHouse (House house, String townName) throws IllegalStateException {
          
          Town town = getTown(townName);
          if (null == town) throw new IllegalStateException(&quot;No matching town&quot;);
  
          town.addHouse(house);
          return house;
      }
  
  public List&lt;String&gt; getTown(String name) {
  
          for (Town town : towns) {
              if (town.getName().equals(name)) return town;
          }
  
          return null;
      }
  }
  </code></pre>
  <p><strong>Town class:</strong></p>
  <pre><code>public class Town {
      List&lt;House&gt; houses = new ArrayList&lt;&gt;();
  
      String name;
      String abbreviation;
  
      public Town (String name, String abbreviation) {
        
          this.name = name;
          this.abbreviation = abbreviation;
      }
      
      public String getName() {
          return name;
      }
      
      public String getAbbreviation() {
          return abbreviation;
      }
      
      public void addHouse(House house) {
          houses.add(house);
      }
      
      public House getHouse(String unitNumber) {
          for (House house : houses) {
              if (house.getUnitNumber().equals(unitNumber)) return house;
          }
  
          return null;
      }
  }
  </code></pre>
  <p><strong>House class</strong></p>
  <pre><code>public class House {
      private final List&lt;People&gt; people = new ArrayList&lt;&gt;();
  
      private final String unitNumber;
      private final String houseName;
  
      public House (String unitNumber, String houseName) {
  
          this.unitNumber= unitNumber;
          this.houseName= houseName;
      }
  
      public String getUnitNumber() {
          return unitNumber;
      }
  
      public String getHouseName() {
          return houseName;
      }
  
      private People checkMovedInPeople(People person) {
          if (null == person) throw new NullPointerException();
  
          for (People movedIn : people) {
              if (movedIn.getName().equals(person.getName())) return movedIn;
              if (movedIn.getPersonID().equals(person.getPersonID())) return movedIn;
          }
  
          return null;
      }
  
      public void moveInPeople(People person) throws IllegalArgumentException, IllegalStateException {
           if (null == person) throw new IllegalArgumentException(&quot;Person shouldn't be null&quot;);
           if (null != checkMovedInPeople(person)) throw new IllegalStateException(&quot;Person is already in the house&quot;);
  
           people.add(person);
      }
  
      public List&lt;String&gt; getPeople() {
          List&lt;String&gt; results = new ArrayList&lt;&gt;();
  
          for (People person: people) {
              results.add(person.getPersonID());
          }
  
          return results;
      }
  
      public People getPerson(String match) {
          for (People person: people) {
              if (person.getPersonID().equals(match)) return person;
              if (person.getName().equals(match)) return person;
          }
  
          return null;
      }
  }
  </code></pre>
  <p>And for the <strong>people class</strong>, it just has two variables: String PersonID and String Name and their getter methods.</p>
  <p>So, what I want to achieve is that, I am currently trying to test the addPeople method in CivilAddSystem class and I want to test it independently using mockito.</p>
  <p>The test case I wrote using JUnit is like this:</p>
  <pre><code>@Test
      public void testAddPeople() {
          CivilAddSystem CAS = new CivilAddSystem();
          Town town = CAS.addTown(&quot;BlueTown&quot;, &quot;BT&quot;);
          House house = CAS.addHouse(&quot;U180&quot;, &quot;BlueHouse&quot;, &quot;BlueTown&quot;);
          People bob = CAS.addPeople(&quot;1&quot;, &quot;Bob&quot;);
          Assert.assertEquals(CAS.getTown(&quot;BlueTown&quot;).getHouse(&quot;U180&quot;).getPerson(&quot;1&quot;), null);
  
          house.moveInPeople(bob);
          Assert.assertEquals(CAS.getTown(&quot;BlueTown&quot;).getHouse(&quot;U180&quot;).getPerson(&quot;1&quot;).getPersonID, 1);
      }
  </code></pre>
  <p>But I am really struggling with applying mockito for this test case.</p>
  <p>What I did so far is just mocking Town, House and People classes, (not the CivilAddSystem class since it is the one that is being tested), and stopped there...</p>
  <p>Can anyone gives me a hint on how to apply mockito for that above test case?</p>
  <p>p.s) A little bit of modification for the codes above is accepted (for example, applying dependency injection and something like this are accepted).</p>
  <p>Thanks in advance!</p>