title: junit testing - assertEquals for exception
body: <p>How can I use assertEquals to see if the exception message is correct?
  The test passes but I don't know if it hits the correct error or not.</p>
  
  <p>The test I am running.</p>
  
  <pre><code>@Test
  public void testTC3()
  {
      try {
      assertEquals("Legal Values: Package Type must be P or R", Shipping.shippingCost('P', -5));
      } 
      catch (Exception e) {
      }        
  }
  </code></pre>
  
  <p>The method being tested.</p>
  
  <pre><code>public static int shippingCost(char packageType, int weight) throws Exception
  {
      String e1 = "Legal Values: Package Type must be P or R";
      String e2 = "Legal Values: Weight &lt; 0";
      int cost = 0;
          if((packageType != 'P')&amp;&amp;(packageType != 'R'))
          {
               throw new Exception(e1);
          }
  
          if(weight &lt; 0)
          {
               throw new Exception(e2);
          }        
           if(packageType == 'P')
           {
               cost += 10;
           }
           if(weight &lt;= 25)
           {   
               cost += 10;
           }
           else
           {
              cost += 25;
           }
           return cost;       
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks for the help.</p>