diff -r 000000000000 -r 77b6002451c4 samples/codeinjection/test/org/apidesign/codeinjection/Version20Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/codeinjection/test/org/apidesign/codeinjection/Version20Test.java Sat Jan 10 21:29:22 2009 +0100 @@ -0,0 +1,52 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.apidesign.codeinjection; + +import org.apidesign.codeinjection.spi.CountDownExtender; +import org.junit.Test; +import org.netbeans.junit.MockServices; +import static org.junit.Assert.*; + +/** Final count down test. + * + * @author Jaroslav Tulach + */ +public class Version20Test { + + public Version20Test() { + } + + /** creates version 2.0 */ + private static CountDown create(int value) { + return new CountDownImplV2(value); + } + + @Test + public void testDecrementFourTimes() { + MockServices.setServices(); + CountDown counter = create(4); + assertFalse("Not down yet", counter.isDown()); counter.down(); + assertFalse("Not down yet", counter.isDown()); counter.down(); + assertFalse("Not down yet", counter.isDown()); counter.down(); + assertFalse("Not down yet", counter.isDown()); counter.down(); + assertTrue("Down now", counter.isDown()); + } + + @Test + public void testDecrementTwoTimesEnough() { + MockServices.setServices(DecrementByTwo.class); + CountDown counter = create(4); + assertFalse("Not down yet", counter.isDown()); counter.down(); + assertFalse("Not down yet", counter.isDown()); counter.down(); + assertTrue("Two Down is enough", counter.isDown()); + } + + public static final class DecrementByTwo implements CountDownExtender { + public int decrement(int value) { + return value - 2; + } + } +} \ No newline at end of file