title: How does java junit catch the error for testing?
body: <p>I'm new to java I'm trying to create the account deposit using what the junit testing below for test the account deposit with "zero" , I'm starting with deposit method  but I could not figured it out what I am missing here. </p>
  
  <p>I don't understand the part that .. If I already try to catch the deposit &lt;= 0 in my if statement , why junit still fail me ? </p>
  
  <pre><code>   public void testZeroDeposit()
      {   System.out.println("---testZeroDeposit");
          Account account = new AccountImpl(0);
          try {  System.out.println("---testZeroDeposit -- try");
              account.deposit(0);
              fail();
          } catch (IllegalArgumentException e) {  System.out.println("---testZeroDeposit -- catch");
              // Expected
          }
      }
  </code></pre>
  
  <p>my bank account plan to have deposit / balance and withdraw as follow .. </p>
  
  <p>====Account.java====</p>
  
  <pre><code>public interface Account
  {
      int id();
      long balance();
      void deposit(long amount);
      void withdraw(long amount) throws InsufficientFundsException;
  }
  </code></pre>
  
  <p>======AccountImpl.java======</p>
  
  <pre><code>public class AccountImpl implements Account {
  
      private long balance;
      private int id;
  
      private int getId() {
          return id;
      }
  
      public AccountImpl(int id) {
          // 
          this.id = id;
      }
  
  
      @Override
      public long balance() {
          // TODO Auto-generated method stub
          return 0;
      }
  
      /**
       * deposit money ( amount ) =&gt; account balance go up 
       */
      @Override
      public void deposit(long amount) {
          // TODO Auto-generated method stub
          if ( amount &lt;= 0 ) {
              System.out.println("Please deposit positive amount");
          }
          balance += amount;
          System.out.println("Transaction : Account " + getId() + ": deposit: $ " + amount + " new balance : $" + balance);
      }
  
  
      @Override
      public void withdraw(long amount) throws InsufficientFundsException {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public int id() {
          // TODO Auto-generated method stub
          return 0;
      }
  
  }
  </code></pre>
  
  <p>===== the console result ===</p>
  
  <p>**</p>
  
  <pre><code>**---testZeroDeposit -- try
  Please deposit positive amount
  Transaction : Account 0: deposit: $ 0 new balance : $0**
  </code></pre>
  
  <p>**</p>
  
  <p>====junit result ====
  <img src="https://i.stack.imgur.com/ypoUs.png" alt="enter image description here"></p>