title: How can I unit test user input in java
body: <p>I am trying to understand how can I test a user's input (please note I am not trying to do a mock test but a test of actual user's input)</p>
  
  <p>Currently as you may see in my program I have hard coded the values for my test case and it is passing all tests but how can I get a user's input and test it .</p>
  
  <p>Is there a way where I can call System.in my constructor and pass it when I create an instance of MyClass1 in the test class?</p>
  
  <p>Please, if possible give me some example code so I can better understand.</p>
  
  <p>If I have a interface as such</p>
  
  <pre><code>public interface IMyClass{
     public int getvalue1();
     public int getvalue2();
     public int getvalue3();
  }
  </code></pre>
  
  <p>and then interface implementation as such</p>
  
  <pre><code>public class MyClass1 implements MyClass{
  
  private int _value1 = 0;
  private int _value2 = 0;
  private int _value3 = 0;
  
  
  
  public MyClass1(int number1, int number2, int number3)
  {
  
     _value1 = number1;
      _value2 = number2;
      _value3 = number3;
  }
  
  public void setLength1(int value1)
  {
      _value1 = value1;
  }
  
  public void setLength2(int length2)
  {
      _value2 = value2;
  }
  
  public void setLength3(int length3)
  {
      _value3 = value3;
  }
  
  public int getValue1()
  {
      return _value1;
  }
  
  public int getValue2()
  {
      return _value2;
  }
  
  public int getValue3()
  {
      return _value3;
  }
  }
  </code></pre>
  
  <p>and finally a test class as such:</p>
  
  <pre><code>public class ClasTest extends TestCase {
  
  public void testNumbers()
  {
     MyClass1 numbers= new MyClass1(1,2,3);
     assertThat(numbers.getValue1(),is(not(numbers.getValue2())));
  
  }
  }
  </code></pre>
  
  <p>Thankyou, I appreciate any help.</p>