title: Java Unit Testing Help for loop
body: <pre><code>public void login(String username, String password) {
  
      for(int i = 0; i &lt; Users.size(); i++) {
          user users = (user) Users.get(i);
          if(users.getUsername().contains(username)
                 &amp;&amp; users.getPassword().contains(password)) {
              userName = users.getUsername();
              userLevel = users.getUserLevel();
              isSuccess = true;
          }
      }    
  }
  </code></pre>
  
  <p>Hello everyone. I'm trying to do a java unit testing for this method using Java Junit. But i don't know how to do that? Because there's a for loop. </p>
  
  <p>Let me explain the method.</p>
  
  <pre><code>for(int i=0;i&lt;Users.size();i++){
  </code></pre>
  
  <p>This "Users" is a vector. This loop runs unit this vector ends.</p>
  
  <pre><code>user users = (user) Users.get(i);
  </code></pre>
  
  <p>Then im calling user class for user instance.</p>
  
  <pre><code> if((users.getUsername().contains(username)) &amp;&amp;
      (users.getPassword().contains(password))) {
  </code></pre>
  
  <p>Then if any of the users that matches with the values in the vectors, this gives the output.</p>
  
  <p>Can anyone tell me how to write a unit test for this?</p>