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
jtulach@54
     1
package apifest;
jtulach@54
     2
jtulach@54
     3
import junit.framework.TestCase;
jtulach@54
     4
import org.netbeans.apifest.boolcircuit.Circuit;
jtulach@54
     5
jtulach@54
     6
jtulach@54
     7
/** Write a test that works with version from day A and fails with version B.
jtulach@54
     8
 */
jtulach@59
     9
// BEGIN: apifest.day3.against-welltestedsolution
jtulach@54
    10
public class CircuitTest extends TestCase {
jtulach@54
    11
    public CircuitTest(String n) {
jtulach@54
    12
        super(n);
jtulach@54
    13
    }
jtulach@54
    14
    
jtulach@54
    15
    public void testClass() throws Exception {
jtulach@54
    16
        // OK, this is not fair as well.
jtulach@132
    17
        assertEquals("Created AND circuit", "AndCircuit", 
jtulach@132
    18
            getName(Circuit.createAndCircuit(null, null))
jtulach@132
    19
        );
jtulach@132
    20
        assertEquals("Created OR circuit", "OrCircuit", 
jtulach@132
    21
            getName(Circuit.createOrCircuit(null, null))
jtulach@132
    22
        );
jtulach@54
    23
    }
jtulach@54
    24
    
jtulach@54
    25
    private String getName(Object obj) {
jtulach@54
    26
        String base = obj.getClass().getName();
jtulach@54
    27
        int lastDot = base.lastIndexOf('.');
jtulach@54
    28
        int last = base.lastIndexOf('$');
jtulach@54
    29
        if (lastDot > last) last = lastDot;
jtulach@54
    30
        return base.substring(last+1);
jtulach@54
    31
    }
jtulach@54
    32
}
jtulach@59
    33
// END: apifest.day3.against-welltestedsolution