Advertisement
Lighta

junit sample

Jan 14th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. /*
  2.  * 2005-06-12
  3.  * Code source inspire et traduit e partir d'un enonce de laboratoire du MIT
  4.  * 6.170    Laboratory in Software Engineering, Fall 2002
  5.  * http://6170.lcs.mit.edu/www-archive/Old-2002-Fall/psets/ps2/ps2.html
  6.  *
  7.  */
  8.  
  9. package test;
  10.  
  11. import cartes.*;
  12. import junit.framework.Assert;
  13. import junit.framework.Test;
  14. import junit.framework.TestCase;
  15. import junit.framework.TestSuite;
  16.  
  17. /**
  18.  * Ensemble de tests dans JUnit pour tester la classe Denomination
  19.  */
  20. public class DenominationTest extends TestCase
  21. {
  22.  
  23.     /**
  24.      * Constructor for DenominationTest.
  25.      * @param arg0
  26.      */
  27.     public DenominationTest(String arg0)
  28.     {
  29.         super(arg0);
  30.     }
  31.  
  32.     //
  33.     // METHODS
  34.     //
  35.  
  36.     public static Test suite() {        
  37.         return new TestSuite(DenominationTest.class);
  38.     }
  39.  
  40.  
  41.     public void testCompareTo() {
  42.        
  43.         // Comparing to a null card suit should throw a NullPointerException.
  44.         try {
  45.             Denomination.VALET.compareTo(null);
  46.             fail("Devrait lancer une NullPointerException");
  47.         }
  48.         catch (NullPointerException npe) {
  49.         }
  50.         catch (Exception e) {
  51.             fail("Devrait lancer une NullPointerException: " + e.toString());
  52.         }
  53.  
  54.  
  55.         // Comparing to a String should throw a ClassCastException.
  56.         // test desuet avec Java 1.5 et "generics"
  57.         /*
  58.         try {
  59.             Denomination.TROIS.compareTo("test");
  60.             fail("Devrait lancer une ClassCastException");
  61.         }
  62.         catch (ClassCastException cce) {
  63.         }
  64.         catch (Exception e) {
  65.             fail("Devrait lancer une ClassCastException: " + e.toString());
  66.         }
  67.         */
  68.  
  69.  
  70.         // A card value cannot be less than the same card value.
  71.         assertTrue(Denomination.HUIT.compareTo(Denomination.HUIT) == 0);
  72.  
  73.         // Test two different card values.
  74.         assertTrue(Denomination.AS.compareTo(Denomination.DEUX) > 0);
  75.         assertTrue(Denomination.DEUX.compareTo(Denomination.AS) < 0);
  76.     }
  77.  
  78.  
  79.     public void testEquals() {
  80.         assertTrue(!Denomination.VALET.equals(null));
  81.         assertEquals(Denomination.SEPT, Denomination.SEPT);
  82.         Assert.assertTrue(!Denomination.DEUX.equals(Denomination.AS));
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement