Rev 254 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2011.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
package test.display.check;
/**
* Printing routines.
*
* @author Steve Ratcliffe
*/
public class Log
{
private static boolean showLogs =
true;
private static boolean error
;
private static int errorCount
;
public static void error
(String fmt,
Object...
args) {
error =
true;
errorCount++
;
System.
out.
printf("ERROR: " + ensureNewLine
(fmt
), args
);
}
public static void log
(String fmt,
Object...
args) {
if (showLogs
)
System.
out.
format(ensureNewLine
(fmt
), args
);
}
public static void checkNotNull
(Object obj,
String msg,
Object...
args) {
if (obj ==
null)
error
(msg, args
);
}
private static String ensureNewLine
(String msg
) {
if (msg.
charAt(msg.
length() -
1) ==
'\n') return msg
;
else return msg +
'\n';
}
public static void checkEqual
(Object expected,
Object found,
String fmt,
Object ...
args) {
if (expected ==
null) {
if (found
!=
null)
error
(fmt +
" expected null", args
);
} else if (found ==
null) {
error
(fmt +
" was null", args
);
} else if (!expected.
equals(found
)) {
error
(fmt +
" was " + found +
", expected " + expected, args
);
}
}
public static void checkNotZero
(int value,
String fmt,
Object...
args) {
if (value ==
0)
error
(fmt, args
);
}
public static boolean isError
() {
return error
;
}
public static int getErrorCount
() {
return errorCount
;
}
public static void setShowLogs
(boolean showLogs
) {
Log.
showLogs = showLogs
;
}
}