samples/apifest1/day3-intermezzo/pnejedly/against-welltestedsolution/test/apifest/CircuitTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:52 +0200
changeset 59 02e05defc6a0
parent 54 45b0d58e66ca
child 132 3bc4c54f4bcc
permissions -rw-r--r--
URLs in apifest chapter replaced with code snippets
     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", getName(Circuit.createAndCircuit(null, null)));
    18         assertEquals("Created OR circuit", "OrCircuit", getName(Circuit.createOrCircuit(null, null)));
    19     }
    20     
    21     private String getName(Object obj) {
    22         String base = obj.getClass().getName();
    23         int lastDot = base.lastIndexOf('.');
    24         int last = base.lastIndexOf('$');
    25         if (lastDot > last) last = lastDot;
    26         return base.substring(last+1);
    27     }
    28 }
    29 // END: apifest.day3.against-welltestedsolution