samples/sidemeanings/test/org/apidesign/sidemeanings/test/MixedTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 18:51:38 +0200
changeset 263 7e8e995065c5
parent 208 897361847d12
child 326 1657c68af062
permissions -rw-r--r--
Tests of all modules are executed and can fail the build
jtulach@208
     1
package org.apidesign.sidemeanings.test;
jtulach@208
     2
jtulach@208
     3
jtulach@208
     4
import org.apidesign.sidemeanings.MixedClass;
jtulach@208
     5
import org.apidesign.sidemeanings.NonMixed;
jtulach@208
     6
import org.apidesign.sidemeanings.NonMixed.Callback;
jtulach@208
     7
import org.junit.After;
jtulach@208
     8
import org.junit.Before;
jtulach@208
     9
import org.junit.Test;
jtulach@208
    10
import static org.junit.Assert.*;
jtulach@208
    11
jtulach@208
    12
public class MixedTest {
jtulach@208
    13
jtulach@208
    14
    public MixedTest() {
jtulach@208
    15
    }
jtulach@208
    16
jtulach@208
    17
    @Before
jtulach@208
    18
    public void setUp() {
jtulach@208
    19
    }
jtulach@208
    20
jtulach@208
    21
    @After
jtulach@208
    22
    public void tearDown() {
jtulach@208
    23
    }
jtulach@208
    24
jtulach@208
    25
    // BEGIN: sidemeanings.Mixed.Use
jtulach@208
    26
    @Test public void useOfClassWithMixedMeanings() {
jtulach@208
    27
        class AddFiveMixedCounter extends MixedClass {
jtulach@208
    28
            @Override
jtulach@208
    29
            protected int toBeImplementedBySubclass() {
jtulach@208
    30
                toBeCalledBySubclass();
jtulach@208
    31
                return 5;
jtulach@208
    32
            }
jtulach@208
    33
        }
jtulach@208
    34
        AddFiveMixedCounter add5 = new AddFiveMixedCounter();
jtulach@208
    35
        assertEquals("5/1 = 5", 5, add5.apiForClients());
jtulach@208
    36
        assertEquals("10/2 = 5", 5, add5.apiForClients());
jtulach@208
    37
        assertEquals("15/3 = 5", 5, add5.apiForClients());
jtulach@208
    38
    }
jtulach@208
    39
    // END: sidemeanings.Mixed.Use
jtulach@208
    40
    
jtulach@208
    41
    // BEGIN: sidemeanings.Mixed.Clean.Use
jtulach@208
    42
    @Test public void useWithoutMixedMeanings() {
jtulach@208
    43
        class AddFiveMixedCounter implements NonMixed.Provider {
jtulach@208
    44
            private Callback callback;
jtulach@208
    45
            
jtulach@208
    46
            public int toBeImplementedBySubclass() {
jtulach@208
    47
                callback.toBeCalledBySubclass();
jtulach@208
    48
                return 5;
jtulach@208
    49
            }
jtulach@208
    50
jtulach@208
    51
            public void initialize(Callback c) {
jtulach@208
    52
                callback = c;
jtulach@208
    53
            }
jtulach@208
    54
        }
jtulach@208
    55
        NonMixed add5 = NonMixed.create(new AddFiveMixedCounter());
jtulach@208
    56
        assertEquals("5/1 = 5", 5, add5.apiForClients());
jtulach@208
    57
        assertEquals("10/2 = 5", 5, add5.apiForClients());
jtulach@208
    58
        assertEquals("15/3 = 5", 5, add5.apiForClients());
jtulach@208
    59
    }
jtulach@208
    60
    // END: sidemeanings.Mixed.Clean.Use
jtulach@208
    61
}
jtulach@208
    62