title: junit testing for user input using Scanner
body: <p>I have to test a method in a class which takes an input using Scanner class.</p>
  
  <pre><code>package com.math.calculator;
  
  import java.util.Scanner;
  
  public class InputOutput {
  
      public String getInput() {
          Scanner sc = new Scanner(System.in);
          return sc.nextLine();
      }
  }
  </code></pre>
  
  <p>I want to test it using JUnit but not sure how to do it.</p>
  
  <p>I tried using the following code but it wont work.</p>
  
  <pre><code>package com.math.calculator;
  
  import org.junit.Test;
  
  import static org.junit.Assert.assertEquals;
  
  public class InputOutputTest {
  
      @Test
      public void shouldTakeUserInput() {
          InputOutput inputOutput= new InputOutput();
  
          assertEquals("add 5", inputOutput.getInput());
      }
  }
  </code></pre>
  
  <p>I want to also try it with Mockito (using mock... when ... thenReturn) but not sure how to do it.</p>