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