viewing paste junit sample | Java

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