samples/codeinjection/test/org/apidesign/codeinjection/Version20Test.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 10 Jan 2009 21:29:22 +0100
changeset 303 77b6002451c4
child 305 e6b3dc7d5795
permissions -rw-r--r--
Initial version of sample to explain 'code injection'
     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     @Test
    39     public void testDecrementTwoTimesEnough() {
    40         MockServices.setServices(DecrementByTwo.class);
    41         CountDown counter = create(4);
    42         assertFalse("Not down yet", counter.isDown()); counter.down();
    43         assertFalse("Not down yet", counter.isDown()); counter.down();
    44         assertTrue("Two Down is enough", counter.isDown());
    45     }
    46 
    47     public static final class DecrementByTwo implements CountDownExtender {
    48         public int decrement(int value) {
    49             return value - 2;
    50         }
    51     }
    52 }