title: How to mock a For Loop using Mockito
body: <p>I'm a newbie to mockito. My question is how can I mock a for loop using Mockito? </p>
  
  <p>For Eg: This is the main Class: </p>
  
  <pre><code>import java.util.HashSet;
  import java.util.Set;
  
      public class stringConcatination {
  
          public static void main(String[] args) {
              Set&lt;String&gt; stringSet = new HashSet();
              stringSet.add("Robert");
              stringSet.add("Jim");
              for (String s:stringSet) {
                  s = "hi " + s;
              }
          }
  
  }
  </code></pre>
  
  <p>This is the Test Class:</p>
  
  <pre><code>import java.util.HashSet;
  import java.util.Set;
  
  import org.junit.Test;
  import static org.mockito.Mockito.mock;
  
  public class stringConcatinationTest {
  
      @Test
      public void testMain() {
          Set mockSet = mock(HashSet.class);
          // --  How to mock For Loop --
      }
  
  }
  </code></pre>
  
  <p>I saw this <a href="https://stackoverflow.com/questions/18483176/mockito-mocking-an-arraylist-that-will-be-looped-in-a-for-loop">related question</a>. But I couldn't understand, how a for loop can be mocked.</p>