From b556c42daa61c99c1a2f8de06e1c526425228450 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 31 Dec 2017 03:10:58 -0500 Subject: Mock logger in unit tests --- .../frost/facebook/requests/FbRequest.kt | 2 - app/src/test/kotlin/android/util/Log.java | 60 ++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 app/src/test/kotlin/android/util/Log.java (limited to 'app') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt index ca4aa4ac..ae8652e6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt @@ -106,14 +106,12 @@ fun String.getAuth(): RequestAuth { val text = StringEscapeUtils.unescapeEcmaScript(it) val fb_dtsg = FB_DTSG_MATCHER.find(text)[1] if (fb_dtsg != null) { - L._d { "fb_dtsg for ${auth.userId}: $fb_dtsg" } auth = auth.copy(fb_dtsg = fb_dtsg) if (auth.isValid) return auth } val rev = FB_REV_MATCHER.find(text)[1] if (rev != null) { - L._d { "rev for ${auth.userId}: $rev" } auth = auth.copy(rev = rev) if (auth.isValid) return auth } 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 -- cgit v1.2.3