package kr.co.zumo.app.lifeplus.util;

import android.util.Log;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Log.class})
public class LoggTest {

  @Before
  public void setUp() throws Exception {
    PowerMockito.mockStatic(Log.class);
  }

  @Test
  public void v() {
    System.out.println("Running test-------" + "v");


    // Log warnings to the console
    when(Log.v(anyString(), anyString())).thenAnswer(new Answer<Void>()      {
      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        Object[] args = invocation.getArguments();
        if (args.length > 1) { //cause I'm paranoid
          System.out.println(invocation.getMethod().getName() + " - Tag: " + args[0] + ", Msg: " + args[1]);

          assertEquals("tag", args[0]);
          assertEquals("msg", args[1]);
        }
        return null;
      }
    });

    Logg.v("tag", "msg");
  }

  @Test
  public void d() {
    System.out.println("Running test-------" + "d");


    // Log warnings to the console
    when(Log.d(anyString(), anyString())).thenAnswer(new Answer<Void>()      {
      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        Object[] args = invocation.getArguments();
        if (args.length > 1) { //cause I'm paranoid
          System.out.println(invocation.getMethod().getName() + " - Tag: " + args[0] + ", Msg: " + args[1]);

          assertEquals("tag", args[0]);
          assertEquals("msg", args[1]);
        }
        return null;
      }
    });

    Logg.d("tag", "msg");
  }

  @Test
  public void i() {
    System.out.println("Running test-------" + "i");


    // Log warnings to the console
    when(Log.i(anyString(), anyString())).thenAnswer(new Answer<Void>()      {
      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        Object[] args = invocation.getArguments();
        if (args.length > 1) { //cause I'm paranoid
          System.out.println(invocation.getMethod().getName() + " - Tag: " + args[0] + ", Msg: " + args[1]);

          assertEquals("tag", args[0]);
          assertEquals("msg", args[1]);
        }
        return null;
      }
    });

    Logg.i("tag", "msg");
  }

  @Test
  public void w() {
    System.out.println("Running test-------" + "w");


    // Log warnings to the console
    when(Log.w(anyString(), anyString())).thenAnswer(new Answer<Void>()      {
      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        Object[] args = invocation.getArguments();
        if (args.length > 1) { //cause I'm paranoid
          System.out.println(invocation.getMethod().getName() + " - Tag: " + args[0] + ", Msg: " + args[1]);

          assertEquals("tag", args[0]);
          assertEquals("msg", args[1]);
        }
        return null;
      }
    });

    Logg.w("tag", "msg");
  }

  @Test
  public void e() {
    System.out.println("Running test-------" + "e");


    // Log warnings to the console
    when(Log.e(anyString(), anyString())).thenAnswer(new Answer<Void>()      {
      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        Object[] args = invocation.getArguments();
        if (args.length > 1) { //cause I'm paranoid
          System.out.println(invocation.getMethod().getName() + " - Tag: " + args[0] + ", Msg: " + args[1]);

          assertEquals("tag", args[0]);
          assertEquals("msg", args[1]);
        }
        return null;
      }
    });

    Logg.e("tag", "msg");
  }

  @Test
  public void e1() {
    Exception e = mock(Exception.class);

    Logg.e(e);

    verify(e).printStackTrace();
  }

  @Test
  public void e2() {
    Throwable e = mock(Throwable.class);

    Logg.e(e);

    verify(e).printStackTrace();
  }
}