package test;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import app.outlay.utils.DeviceUtils;
import app.outlay.utils.ResourceUtils;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Created by robin on 2017. 05. 01..
 */

public class TestDeviceUtils {
    private Activity activity = Mockito.mock(Activity.class);
    private View view = Mockito.mock(View.class);
    private InputMethodManager inputMethodManager = Mockito.mock(InputMethodManager.class);
    private Context context = Mockito.mock(Context.class);
    private TypedValue tv = Mockito.mock(TypedValue.class);
    private Resources.Theme theme = Mockito.mock(Resources.Theme.class);
    private Resources resources = Mockito.mock(Resources.class);

    @Before
    public void setup(){

    }

    @Test
    public void screenSizeTest(){

    }
    @Test
    public void getStatusBarHeightBranchTrue(){

    }
    @Test
    public void getStatusBarHeightBranchFalse(){

    }
    //cannot tested, because the creation of the TypedValue object in the method
    @Test
    public void getActionBarHeightBranchTrue(){

        when(context.getTheme()).thenReturn(theme);
        when(context.getResources()).thenReturn(resources);

        Assert.assertEquals(0,DeviceUtils.getActionBarHeight(context));


    }
    @Test
    public void getActionBarHeightBranchFalse(){
        when(context.getTheme()).thenReturn(theme);
        when(theme.resolveAttribute(android.R.attr.actionBarSize, tv, true)).thenReturn(false);

        Assert.assertEquals(0,DeviceUtils.getActionBarHeight(context));

        verify(context, never()).getResources();

    }
    @Test
    public void hideKeyboardBranchTrue(){
        when(activity.getCurrentFocus()).thenReturn(view);
        when(activity.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(inputMethodManager);

        DeviceUtils.hideKeyboard(activity);

        verify(activity, times(1)).getSystemService(Context.INPUT_METHOD_SERVICE);
        verify(inputMethodManager, times(1)).hideSoftInputFromWindow(view.getWindowToken(),0);
    }
    @Test
    public void hideKeyboardBranchFalse(){
        when(activity.getCurrentFocus()).thenReturn(null);

        DeviceUtils.hideKeyboard(activity);

        verify(activity, never()).getSystemService(Context.INPUT_METHOD_SERVICE);
        verify(inputMethodManager, never()).hideSoftInputFromWindow(view.getWindowToken(),0);
    }

}

@@ -126,80 +126,34 @@
 oid.
-inputmethodservice.InputMethodService;%0Aim
+sup
 port
- android.util.DisplayMetric
+.annotation.DimenRe
 s;%0Ai
@@ -261,17 +261,16 @@
 anager;%0A
-%0A
 import j
@@ -292,17 +292,16 @@
 Assert;%0A
-%0A
 import o
@@ -368,17 +368,16 @@
 ockito;%0A
-%0A
 import a
@@ -409,48 +409,8 @@
 ls;%0A
-import app.outlay.utils.ResourceUtils;%0A%0A
 impo
@@ -1154,16 +1154,70 @@
 %0A%0A    %7D%0A
+    //cannot be tested because getMetrics returns void
 %0A    @Te
@@ -1249,25 +1249,24 @@
 SizeTest()%7B%0A
-%0A
     %7D%0A    @T
@@ -1321,74 +1321,971 @@
 ()%7B%0A
-%0A    %7D%0A    @Test%0A    public void getStatusBarHeightBranchFalse()%7B%0A
+        @DimenRes%0A        int dim = 1;%0A        when(context.getTheme()).thenReturn(theme);%0A        when(context.getResources()).thenReturn(resources);%0A        when(resources.getIdentifier(%22status_bar_height%22, %22dimen%22, %22android%22)).thenReturn(1);%0A        when(resources.getDimensionPixelSize(dim)).thenReturn(1);%0A        Assert.assertEquals(1, DeviceUtils.getStatusBarHeight(context));%0A%0A        verify(resources, times(1)).getDimensionPixelSize(dim);%0A%0A    %7D%0A    @Test%0A    public void getStatusBarHeightBranchFalse()%7B%0A        @DimenRes%0A        int dim = 1;%0A        when(context.getTheme()).thenReturn(theme);%0A        when(context.getResources()).thenReturn(resources);%0A        when(resources.getIdentifier(%22status_bar_height%22, %22dimen%22, %22android%22)).thenReturn(-1);%0A        when(resources.getDimensionPixelSize(dim)).thenReturn(1);%0A        Assert.assertEquals(0, DeviceUtils.getStatusBarHeight(context));%0A%0A        verify(resources, never()).getDimensionPixelSize(dim);
 %0A   

screenSizeTest, getStatusBarHeightBranchTrue, getStatusBarHeightBranchFalse