package com.stormpath.sdk;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowLog;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(RobolectricGradleTestRunner.class)
public class LoggerTest extends BaseTest {

    private StormpathLogger logger;

    @Override
    public void setUp() throws Exception {
        super.setUp();
        ShadowLog.getLogs().clear();

        StormpathConfiguration configuration = new StormpathConfiguration.Builder()
                .baseUrl(mockServerUrl())
                .build();
        Stormpath.init(RuntimeEnvironment.application, configuration);

        logger = Stormpath.logger();
    }

    private void writeTestLogs() {
        logger.v("verbose");
        logger.d("debug");
        logger.i("info");
        logger.w("warn");
        logger.e("error");
        logger.wtf("assert");

        logger.v("verbose: %s", "v");
        logger.d("debug: %s", "d");
        logger.i("info: %s", "i");
        logger.w("warn: %s", "w");
        logger.e("error: %s", "e");
        logger.wtf("assert: %s", "wtf");

        logger.v(new RuntimeException("v"), "verbose");
        logger.d(new RuntimeException("d"), "debug");
        logger.i(new RuntimeException("i"), "info");
        logger.w(new RuntimeException("w"), "warn");
        logger.e(new RuntimeException("e"), "error");
        logger.wtf(new RuntimeException("wtf"), "assert");
    }

    @Test
    public void logsSilentByDefault() throws Exception {
        writeTestLogs();

        assertThat(ShadowLog.getLogs()).isEmpty();
    }

    @Test
    public void verboseLogs() throws Exception {
        Stormpath.setLogLevel(StormpathLogger.VERBOSE);
        writeTestLogs();

        assertThat(ShadowLog.getLogs()).hasSize(18);
    }

    @Test
    public void nullLogStatementsNotLogged() throws Exception {
        Stormpath.setLogLevel(StormpathLogger.VERBOSE);

        logger.v(null);
        logger.v(null, null);
        logger.v(null, null, null);

        assertThat(ShadowLog.getLogs()).isEmpty();
    }
}

@@ -1536,16 +1536,327 @@
 ssert%22);
+%0A%0A        logger.v(new RuntimeException(%22v%22), null);%0A        logger.d(new RuntimeException(%22d%22), null);%0A        logger.i(new RuntimeException(%22i%22), null);%0A        logger.w(new RuntimeException(%22w%22), null);%0A        logger.e(new RuntimeException(%22e%22), null);%0A        logger.wtf(new RuntimeException(%22wtf%22), null);
 %0A    %7D%0A%0A
@@ -2199,10 +2199,10 @@
 ize(
-18
+24
 );%0A 

Add logger test case