samples/apifest1/day3-intermezzo/pnejedly/against-welltestedsolution/test/apifest/CircuitTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:56:12 +0200
changeset 132 3bc4c54f4bcc
parent 59 02e05defc6a0
child 153 b5cbb797ec0a
permissions -rw-r--r--
Truncating all examples to 80 characters per line
     1 package apifest;
     2 
     3 import junit.framework.TestCase;
     4 import org.netbeans.apifest.boolcircuit.Circuit;
     5 
     6 
     7 /** Write a test that works with version from day A and fails with version B.
     8  */
     9 // BEGIN: apifest.day3.against-welltestedsolution
    10 public class CircuitTest extends TestCase {
    11     public CircuitTest(String n) {
    12         super(n);
    13     }
    14     
    15     public void testClass() throws Exception {
    16         // OK, this is not fair as well.
    17         assertEquals("Created AND circuit", "AndCircuit", 
    18             getName(Circuit.createAndCircuit(null, null))
    19         );
    20         assertEquals("Created OR circuit", "OrCircuit", 
    21             getName(Circuit.createOrCircuit(null, null))
    22         );
    23     }
    24     
    25     private String getName(Object obj) {
    26         String base = obj.getClass().getName();
    27         int lastDot = base.lastIndexOf('.');
    28         int last = base.lastIndexOf('$');
    29         if (lastDot > last) last = lastDot;
    30         return base.substring(last+1);
    31     }
    32 }
    33 // END: apifest.day3.against-welltestedsolution