@Test public void testLManagerInitialization() { L l = L.getInstance(LTest.class); assertThat(l, is(notNullValue())); }
/** To work on unit tests, switch the Test Artifact in the Build Variants view. */ @RunWith(PowerMockRunner.class) @PrepareForTest(Log.class) public class LTest { private static final String TAG = LTest.class.getName(); private static final String STRING_WITH_NO_ARGS = "Some String"; private static final String STRING_WITH_ARGS = "Some String with Params: {} {} {}"; private static final String STRING_WITH_ARGS_FILLED_IN = "Some String with Params: I AM LEGEND"; private static final String[] ARGS = {"I", "AM", "LEGEND"}; private static final Exception EXCEPTION = new Exception("Some type of exception."); static L l = L.getInstance(LTest.class); @Before public void before() { PowerMockito.mockStatic(Log.class); } @After public void after() { // want to wait a few milliseconds to verify calls because everything is asynchronous try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } @AfterClass public static void cleanup() { l.destroy(); } @Test public void testLManagerInitialization() { L l = L.getInstance(LTest.class); assertThat(l, is(notNullValue())); } @Test public void testDebugNoArgs() { l.d(STRING_WITH_NO_ARGS); PowerMockito.verifyStatic(); Log.d(TAG, STRING_WITH_NO_ARGS); } @Test public void testDebugWithArgs() { l.d(STRING_WITH_ARGS, ARGS); PowerMockito.verifyStatic(); Log.d(TAG, STRING_WITH_ARGS_FILLED_IN); } @Test public void testDebugWithExceptionNoArgs() { l.d(STRING_WITH_NO_ARGS, EXCEPTION); PowerMockito.verifyStatic(); Log.d(TAG, STRING_WITH_NO_ARGS, EXCEPTION); } @Test public void testDebugWithExceptionWithArgs() { l.d(STRING_WITH_ARGS, EXCEPTION, ARGS); PowerMockito.verifyStatic(); Log.d(TAG, STRING_WITH_ARGS_FILLED_IN, EXCEPTION); } // @Test public void testErrorNoArgs() { l.e(STRING_WITH_NO_ARGS); PowerMockito.verifyStatic(); Log.e(TAG, STRING_WITH_NO_ARGS); } @Test public void testErrorWithArgs() { l.e(STRING_WITH_ARGS, ARGS); PowerMockito.verifyStatic(); Log.e(TAG, STRING_WITH_ARGS_FILLED_IN); } @Test public void testErrorWithExceptionNoArgs() { l.e(STRING_WITH_NO_ARGS, EXCEPTION); PowerMockito.verifyStatic(); Log.e(TAG, STRING_WITH_NO_ARGS, EXCEPTION); } @Test public void testErrorWithExceptionWithArgs() { l.e(STRING_WITH_ARGS, EXCEPTION, ARGS); PowerMockito.verifyStatic(); Log.e(TAG, STRING_WITH_ARGS_FILLED_IN, EXCEPTION); } // @Test public void testInfoNoArgs() { l.e(STRING_WITH_NO_ARGS); PowerMockito.verifyStatic(); Log.e(TAG, STRING_WITH_NO_ARGS); } @Test public void testInfoWithArgs() { l.e(STRING_WITH_ARGS, ARGS); PowerMockito.verifyStatic(); Log.e(TAG, STRING_WITH_ARGS_FILLED_IN); } @Test public void testInfoWithExceptionNoArgs() { l.e(STRING_WITH_NO_ARGS, EXCEPTION); PowerMockito.verifyStatic(); Log.e(TAG, STRING_WITH_NO_ARGS, EXCEPTION); } @Test public void testInfoWithExceptionWithArgs() { l.e(STRING_WITH_ARGS, EXCEPTION, ARGS); PowerMockito.verifyStatic(); Log.e(TAG, STRING_WITH_ARGS_FILLED_IN, EXCEPTION); } @Test public void testVerboseNoArgs() { l.v(STRING_WITH_NO_ARGS); PowerMockito.verifyStatic(); Log.v(TAG, STRING_WITH_NO_ARGS); } @Test public void testVerboseWithArgs() { l.v(STRING_WITH_ARGS, ARGS); PowerMockito.verifyStatic(); Log.v(TAG, STRING_WITH_ARGS_FILLED_IN); } @Test public void testVerboseWithExceptionNoArgs() { l.v(STRING_WITH_NO_ARGS, EXCEPTION); PowerMockito.verifyStatic(); Log.v(TAG, STRING_WITH_NO_ARGS, EXCEPTION); } @Test public void testVerboseWithExceptionWithArgs() { l.v(STRING_WITH_ARGS, EXCEPTION, ARGS); PowerMockito.verifyStatic(); Log.v(TAG, STRING_WITH_ARGS_FILLED_IN, EXCEPTION); } @Test public void testWarnNoArgs() { l.w(STRING_WITH_NO_ARGS); PowerMockito.verifyStatic(); Log.w(TAG, STRING_WITH_NO_ARGS); } @Test public void testWarnWithArgs() { l.w(STRING_WITH_ARGS, ARGS); PowerMockito.verifyStatic(); Log.w(TAG, STRING_WITH_ARGS_FILLED_IN); } @Test public void testWarnWithExceptionNoArgs() { l.w(STRING_WITH_NO_ARGS, EXCEPTION); PowerMockito.verifyStatic(); Log.w(TAG, STRING_WITH_NO_ARGS, EXCEPTION); } @Test public void testWarnWithExceptionWithArgs() { l.w(STRING_WITH_ARGS, EXCEPTION, ARGS); PowerMockito.verifyStatic(); Log.w(TAG, STRING_WITH_ARGS_FILLED_IN, EXCEPTION); } @Test public void testWarnWithException() { l.w(EXCEPTION); PowerMockito.verifyStatic(); Log.w(TAG, EXCEPTION); } // @Test public void testWTFNoArgs() { l.wtf(STRING_WITH_NO_ARGS); PowerMockito.verifyStatic(); Log.wtf(TAG, STRING_WITH_NO_ARGS); } @Test public void testWTFWithArgs() { l.wtf(STRING_WITH_ARGS, ARGS); PowerMockito.verifyStatic(); Log.wtf(TAG, STRING_WITH_ARGS_FILLED_IN); } @Test public void testWTFWithExceptionNoArgs() { l.wtf(STRING_WITH_NO_ARGS, EXCEPTION); PowerMockito.verifyStatic(); Log.wtf(TAG, STRING_WITH_NO_ARGS, EXCEPTION); } @Test public void testWTFWithExceptionWithArgs() { l.wtf(STRING_WITH_ARGS, EXCEPTION, ARGS); PowerMockito.verifyStatic(); Log.wtf(TAG, STRING_WITH_ARGS_FILLED_IN, EXCEPTION); } @Test public void testWTFWithException() { l.wtf(EXCEPTION); PowerMockito.verifyStatic(); Log.wtf(TAG, EXCEPTION); } @Test public void testPrintLnWithNoArgs() { l.println(L.LogType.DEBUG, STRING_WITH_NO_ARGS); PowerMockito.verifyStatic(); Log.println(Log.DEBUG, TAG, STRING_WITH_NO_ARGS); } @Test public void testPrintLnWithArgs() { l.println(L.LogType.DEBUG, STRING_WITH_ARGS, ARGS); PowerMockito.verifyStatic(); Log.println(Log.DEBUG, TAG, STRING_WITH_ARGS_FILLED_IN); } @Test public void testGetStackTraceString() { String stackTrace = "We will pretend this is a stack trace."; PowerMockito.when(Log.getStackTraceString(EXCEPTION)).thenReturn(stackTrace); String stackTraceReturn = l.getStackTraceString(EXCEPTION); assertThat(stackTrace, is(equalTo(stackTraceReturn))); } }