samples/codeinjection/test/org/apidesign/codeinjection/Version20Test.java
changeset 303 77b6002451c4
child 305 e6b3dc7d5795
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/codeinjection/test/org/apidesign/codeinjection/Version20Test.java	Sat Jan 10 21:29:22 2009 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +/*
     1.5 + * To change this template, choose Tools | Templates
     1.6 + * and open the template in the editor.
     1.7 + */
     1.8 +
     1.9 +package org.apidesign.codeinjection;
    1.10 +
    1.11 +import org.apidesign.codeinjection.spi.CountDownExtender;
    1.12 +import org.junit.Test;
    1.13 +import org.netbeans.junit.MockServices;
    1.14 +import static org.junit.Assert.*;
    1.15 +
    1.16 +/** Final count down test.
    1.17 + *
    1.18 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.19 + */
    1.20 +public class Version20Test {
    1.21 +
    1.22 +    public Version20Test() {
    1.23 +    }
    1.24 +
    1.25 +    /** creates version 2.0 */
    1.26 +    private static CountDown create(int value) {
    1.27 +        return new CountDownImplV2(value);
    1.28 +    }
    1.29 +
    1.30 +    @Test
    1.31 +    public void testDecrementFourTimes() {
    1.32 +        MockServices.setServices();
    1.33 +        CountDown counter = create(4);
    1.34 +        assertFalse("Not down yet", counter.isDown()); counter.down();
    1.35 +        assertFalse("Not down yet", counter.isDown()); counter.down();
    1.36 +        assertFalse("Not down yet", counter.isDown()); counter.down();
    1.37 +        assertFalse("Not down yet", counter.isDown()); counter.down();
    1.38 +        assertTrue("Down now", counter.isDown());
    1.39 +    }
    1.40 +
    1.41 +    @Test
    1.42 +    public void testDecrementTwoTimesEnough() {
    1.43 +        MockServices.setServices(DecrementByTwo.class);
    1.44 +        CountDown counter = create(4);
    1.45 +        assertFalse("Not down yet", counter.isDown()); counter.down();
    1.46 +        assertFalse("Not down yet", counter.isDown()); counter.down();
    1.47 +        assertTrue("Two Down is enough", counter.isDown());
    1.48 +    }
    1.49 +
    1.50 +    public static final class DecrementByTwo implements CountDownExtender {
    1.51 +        public int decrement(int value) {
    1.52 +            return value - 2;
    1.53 +        }
    1.54 +    }
    1.55 +}
    1.56 \ No newline at end of file