patterntesting.runtime.util.Assertions Maven / Gradle / Ivy
/*
* $Id: Assertions.java,v 1.5 2011/07/09 21:43:22 oboehm Exp $
*
* Copyright (c) 2008 by Oliver Boehm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* (c)reated 31.01.2009 by oliver ([email protected])
*/
package patterntesting.runtime.util;
import org.slf4j.*;
/**
* If you want to know if assertions are enabled (java option "-ea"), you can
* use this helper class.
* At runtime you can use the 'jconsole' and look at the java.lang.Runtime
* MXBean (java.lang.management.RuntimeMXBean). Here you can look at the
* attribute "InputArguments" if "-ea" is set.
*
* @author oliver
* @since 31.01.2009
* @version $Revision: 1.5 $
*/
public class Assertions {
private static final Logger log = LoggerFactory.getLogger(Assertions.class);
/** Utility class - no need to instantiate it */
private Assertions() {}
/** The Constant enabled. */
public static final boolean enabled;
static {
boolean assertsEnabled = false;
try {
assert false;
log.info("assertions are disabled - call 'java -ea' (SunVM) to enable it)");
} catch (AssertionError expected) {
assertsEnabled = true;
log.info("assertions are enabled");
}
enabled = assertsEnabled;
}
/**
* If you want to know if the JavaVM was started with "Assertion enabled"
* (option -ea for SunVM) you can use this method.
*
* Or you can ask the RuntimeMXBean for the input arguements and look for
* the argument "-ea".
*
* @see java.lang.management.RuntimeMXBean#getInputArguments()
* @return true, if are enabled
*/
public static boolean areEnabled() {
return enabled;
}
}
/**
* $Log: Assertions.java,v $
* Revision 1.5 2011/07/09 21:43:22 oboehm
* switched from commons-logging to SLF4J
*
* Revision 1.4 2010/12/30 17:33:23 oboehm
* checkstyle warnings reduced
*
* Revision 1.3 2010/04/22 18:32:01 oboehm
* compiler warnings fixed
*
* Revision 1.2 2010/04/22 18:27:19 oboehm
* code cleanup of src/main/java
*
* Revision 1.1 2010/01/05 13:26:17 oboehm
* begin with 1.0
*
* Revision 1.4 2009/12/19 22:34:09 oboehm
* trailing spaces removed
*
* Revision 1.3 2009/09/25 14:49:43 oboehm
* javadocs completed with the help of JAutodoc
*
* Revision 1.2 2009/06/10 19:56:57 oboehm
* DontLogMe annotation added to hide parameters logged by @ProfileMe
*
* Revision 1.1 2009/02/03 19:46:54 oboehm
* DbC support moved from patterntesting-check to here
*
* $Source: /cvsroot/patterntesting/PatternTesting10/patterntesting-rt/src/main/java/patterntesting/runtime/util/Assertions.java,v $
*/