title: How to write a JUnit test for an atm validation program?
body: <p>I'm new to java and I'm writing an ATM program where <strong>user can enter pin code three times and if they fail to enter the correct one, their card is blocked.</strong> I've tried to write a Junit test for the following code but I couldn't seem to figure it out. I have two classes AtmPin and AtmTester. AtmTester is where the main class is.</p>
  <p><strong>AtmPin.java</strong></p>
  <pre><code>import java.util.Scanner;
  
  public class AtmPin {
  
     public static boolean validPIN(int user, int orignal){
  
        
  
         return user==orignal;
  
     }
  
     public static int getPin(Scanner sc){
  
        
  
         System.out.print(&quot;Enter PIN: &quot;);
  
         int pin = sc.nextInt();
  
         return pin;
  
     }
  
    
  }
  </code></pre>
  <p><strong>AtmTester.java</strong></p>
  <pre><code>package atm;
  
  import java.util.Scanner;
  
  public class ATMTester {
       public static void main(String[] args) {
  
            
  
             Scanner keyboard = new Scanner(System.in);
  
             int i = 0, userpin;
  
            int PIN = 1234;
            while(i&lt; 3){
  
                
  
                 userpin = AtmPin.getPin(keyboard);
  
                
  
                 if(AtmPin.validPIN(userpin, PIN)){
  
                     System.out.println(&quot;Your PIN is correct&quot;);
  
                     System.exit(0);
  
                 }
                 else {
                     System.out.println(&quot;Your PIN is incorrect&quot;);
                 }
                
  
                 i++;
  
             }
  
            
  
             System.out.println(&quot;Your Bank Card is blocked&quot;);
  
         }
  
  }
  </code></pre>