diff options
author | Allan Wang <me@allanwang.ca> | 2017-12-31 03:10:58 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-12-31 03:10:58 -0500 |
commit | b556c42daa61c99c1a2f8de06e1c526425228450 (patch) | |
tree | 5b4c29c3d49a2a8ce33c40c36afdf0e80956f3ee /app/src/test/kotlin/android/util | |
parent | 6ca914798fb7d2f8712ab04e6885155d3ca3b632 (diff) | |
download | frost-b556c42daa61c99c1a2f8de06e1c526425228450.tar.gz frost-b556c42daa61c99c1a2f8de06e1c526425228450.tar.bz2 frost-b556c42daa61c99c1a2f8de06e1c526425228450.zip |
Mock logger in unit tests
Diffstat (limited to 'app/src/test/kotlin/android/util')
-rw-r--r-- | app/src/test/kotlin/android/util/Log.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/app/src/test/kotlin/android/util/Log.java b/app/src/test/kotlin/android/util/Log.java new file mode 100644 index 00000000..e7095563 --- /dev/null +++ b/app/src/test/kotlin/android/util/Log.java @@ -0,0 +1,60 @@ +package android.util; + +import java.util.Locale; + +/** + * Created by Allan Wang on 31/12/17. + */ +public class Log { + + /** + * Priority constant for the println method; use Log.v. + */ + public static final int VERBOSE = 2; + + /** + * Priority constant for the println method; use Log.d. + */ + public static final int DEBUG = 3; + + /** + * Priority constant for the println method; use Log.i. + */ + public static final int INFO = 4; + + /** + * Priority constant for the println method; use Log.e. + */ + public static final int ERROR = 6; + + public static int e(String tag, String msg, Throwable t) { + System.err.println("ERROR: " + tag + ": " + msg + "\n\tThrowable: " + t.getMessage()); + return 0; + } + + public static int println(int priority, String tag, String message) { + switch (priority) { + case VERBOSE: + p("V", tag, message); + break; + case INFO: + p("I", tag, message); + break; + case DEBUG: + p("D", tag, message); + break; + case ERROR: + p("E", tag, message); + break; + default: + p("L " + priority, tag, message); + break; + } + return 0; + } + + private static void p(String flag, String tag, String msg) { + System.out.println(String.format(Locale.CANADA, "%s: %s: %s", flag, tag, msg)); + } + +}
\ No newline at end of file |