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?
     1 package org.apidesign.samples;
     2 
     3 public class CodeThatCanBeCalledOnlyByTest {
     4     private static int number;
     5 
     6     public static int getNumber() {
     7         return number;
     8     }
     9     
    10     public static void setNumber(int n) {
    11         // BEGIN: call.only.by.test
    12         boolean assertionsOn = false;
    13         assert assertionsOn = true;
    14         if (!assertionsOn) {
    15             throw new IllegalStateException("This is a testing method only!");
    16         }
    17         // END: call.only.by.test
    18         number = n;
    19     }
    20 }