samples/individualsamples/src/org/apidesign/samples/CodeThatCanBeCalledOnlyByTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Wed, 08 Aug 2012 23:55:35 +0200
changeset 399 06362e8bbcd9
parent 143 20dad4daf81b
permissions -rw-r--r--
Was this a reverted condition? It seems that a code that can only be called be a test needs to be allowed when assertions are on.
When assertions are off, it should throw IllegalStateException. Right?
jtulach@143
     1
package org.apidesign.samples;
jtulach@143
     2
jtulach@143
     3
public class CodeThatCanBeCalledOnlyByTest {
jtulach@143
     4
    private static int number;
jtulach@143
     5
jtulach@143
     6
    public static int getNumber() {
jtulach@143
     7
        return number;
jtulach@143
     8
    }
jtulach@143
     9
    
jtulach@143
    10
    public static void setNumber(int n) {
jtulach@143
    11
        // BEGIN: call.only.by.test
jtulach@143
    12
        boolean assertionsOn = false;
jtulach@143
    13
        assert assertionsOn = true;
jtulach@399
    14
        if (!assertionsOn) {
jtulach@143
    15
            throw new IllegalStateException("This is a testing method only!");
jtulach@143
    16
        }
jtulach@143
    17
        // END: call.only.by.test
jtulach@143
    18
        number = n;
jtulach@143
    19
    }
jtulach@143
    20
}