author | Jaroslav Tulach <jtulach@netbeans.org> |
Sun, 06 Oct 2013 22:05:14 +0200 | |
changeset 407 | e1439046d96e |
parent 303 | 77b6002451c4 |
permissions | -rw-r--r-- |
jtulach@303 | 1 |
/* |
jtulach@303 | 2 |
* To change this template, choose Tools | Templates |
jtulach@303 | 3 |
* and open the template in the editor. |
jtulach@303 | 4 |
*/ |
jtulach@303 | 5 |
|
jtulach@303 | 6 |
package org.apidesign.codeinjection; |
jtulach@303 | 7 |
|
jtulach@303 | 8 |
import org.apidesign.codeinjection.spi.CountDownExtender; |
jtulach@303 | 9 |
import org.junit.Test; |
jtulach@303 | 10 |
import org.netbeans.junit.MockServices; |
jtulach@303 | 11 |
import static org.junit.Assert.*; |
jtulach@303 | 12 |
|
jtulach@303 | 13 |
/** Final count down test. |
jtulach@303 | 14 |
* |
jtulach@303 | 15 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jtulach@303 | 16 |
*/ |
jtulach@303 | 17 |
public class Version20Test { |
jtulach@303 | 18 |
|
jtulach@303 | 19 |
public Version20Test() { |
jtulach@303 | 20 |
} |
jtulach@303 | 21 |
|
jtulach@303 | 22 |
/** creates version 2.0 */ |
jtulach@303 | 23 |
private static CountDown create(int value) { |
jtulach@303 | 24 |
return new CountDownImplV2(value); |
jtulach@303 | 25 |
} |
jtulach@303 | 26 |
|
jtulach@303 | 27 |
@Test |
jtulach@303 | 28 |
public void testDecrementFourTimes() { |
jtulach@303 | 29 |
MockServices.setServices(); |
jtulach@303 | 30 |
CountDown counter = create(4); |
jtulach@303 | 31 |
assertFalse("Not down yet", counter.isDown()); counter.down(); |
jtulach@303 | 32 |
assertFalse("Not down yet", counter.isDown()); counter.down(); |
jtulach@303 | 33 |
assertFalse("Not down yet", counter.isDown()); counter.down(); |
jtulach@303 | 34 |
assertFalse("Not down yet", counter.isDown()); counter.down(); |
jtulach@303 | 35 |
assertTrue("Down now", counter.isDown()); |
jtulach@303 | 36 |
} |
jtulach@303 | 37 |
|
jtulach@305 | 38 |
// BEGIN: codeinjection.twice |
jtulach@303 | 39 |
@Test |
jtulach@303 | 40 |
public void testDecrementTwoTimesEnough() { |
jtulach@303 | 41 |
MockServices.setServices(DecrementByTwo.class); |
jtulach@303 | 42 |
CountDown counter = create(4); |
jtulach@303 | 43 |
assertFalse("Not down yet", counter.isDown()); counter.down(); |
jtulach@303 | 44 |
assertFalse("Not down yet", counter.isDown()); counter.down(); |
jtulach@303 | 45 |
assertTrue("Two Down is enough", counter.isDown()); |
jtulach@303 | 46 |
} |
jtulach@303 | 47 |
|
jtulach@303 | 48 |
public static final class DecrementByTwo implements CountDownExtender { |
jtulach@303 | 49 |
public int decrement(int value) { |
jtulach@303 | 50 |
return value - 2; |
jtulach@303 | 51 |
} |
jtulach@303 | 52 |
} |
jtulach@305 | 53 |
// END: codeinjection.twice |
jtulach@305 | 54 |
} |