assert testing environment

Run Settings
LanguageJava
Language Version
Run Command
/** * Assertions have been enabled via (-ea-)flag in run command * * @author orochi-100 * @version 13 May 2020 */ public class Main { private static boolean isTestingEnvironment; static { assert isTestingEnvironment = true; } public static void main(String[] args) { Verify.verify(!isTestingEnvironment, "if you want to run the program, remove the -ea flag in the run command"); System.out.println("Hello World!"); } }
/** * Inspired by Google Guava * * @author orochi-100 * @version 15 May 2020 */ public class VerifyException extends RuntimeException { public VerifyException() {} public VerifyException(Throwable cause) { super(cause); } public VerifyException(String message) { super(message); } }
/** * Inspired by Google Guava * * @author orochi-100 * @version 15 May 2020 */ public class Verify { private Verify() { assert false; } public static void verify(boolean condition) { if (!condition) throw new VerifyException(); } public static void verify(boolean condition, Object errorMsg) { if (!condition) throw new VerifyException(errorMsg.toString()); } }
Editor Settings
Theme
Key bindings
Full width
Lines