samples/sidemeanings/test/org/apidesign/sidemeanings/test/ProtectedTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Wed, 25 Mar 2009 22:14:46 +0100
changeset 324 a9ad091ed069
permissions -rw-r--r--
New samples for converting sidemeaning modifiers to clarity ones
jtulach@324
     1
package org.apidesign.sidemeanings.test;
jtulach@324
     2
jtulach@324
     3
import org.apidesign.sidemeanings.Protected;
jtulach@324
     4
import org.junit.Test;
jtulach@324
     5
jtulach@324
     6
public class ProtectedTest {
jtulach@324
     7
jtulach@324
     8
    @Test public void testCallTenDoubleIncrementOnDirtyAPI() {
jtulach@324
     9
        // BEGIN: sidemeanings.Protected.Dirty.test
jtulach@324
    10
        class DoubleIncrement extends Protected.Dirty {
jtulach@324
    11
            @Override
jtulach@324
    12
            protected void increment() {
jtulach@324
    13
                super.increment();
jtulach@324
    14
                super.increment();
jtulach@324
    15
            }
jtulach@324
    16
        }
jtulach@324
    17
        DoubleIncrement doubleIncr = new DoubleIncrement();
jtulach@324
    18
        doubleIncr.incrementTenTimes();
jtulach@324
    19
        doubleIncr.assertCounter(20);
jtulach@324
    20
        // END: sidemeanings.Protected.Dirty.test
jtulach@324
    21
    }
jtulach@324
    22
jtulach@324
    23
    @Test public void testCallTenDoubleIncrementOnCleanAPI() {
jtulach@324
    24
        // BEGIN: sidemeanings.Protected.Clean.test
jtulach@324
    25
        class DoubleIncrement extends Protected.Clean {
jtulach@324
    26
            @Override
jtulach@324
    27
            protected void increment() {
jtulach@324
    28
                // cannot be access directly, it is abstract:
jtulach@324
    29
                // super.increment();
jtulach@324
    30
                // we need to call default implementation instead
jtulach@324
    31
                defaultIncrement();
jtulach@324
    32
                defaultIncrement();
jtulach@324
    33
            }
jtulach@324
    34
        }
jtulach@324
    35
        DoubleIncrement doubleIncr = new DoubleIncrement();
jtulach@324
    36
        doubleIncr.incrementTenTimes();
jtulach@324
    37
        doubleIncr.assertCounter(20);
jtulach@324
    38
        // END: sidemeanings.Protected.Clean.test
jtulach@324
    39
    }
jtulach@324
    40
}