package com.basgeekball.awesomevalidation.validators;

import android.widget.EditText;

import com.basgeekball.awesomevalidation.ValidationHolder;
import com.basgeekball.awesomevalidation.utility.ViewsInfo;

import junit.framework.TestCase;

import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.api.support.membermodification.MemberModifier;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.ArrayList;

import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
public class UnderlabelValidatorTest extends TestCase {

    private UnderlabelValidator mSpiedUnderlabelValidator;
    private ValidationHolder mMockedValidationHolder;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mSpiedUnderlabelValidator = PowerMockito.spy(new UnderlabelValidator());
        mMockedValidationHolder = mock(ValidationHolder.class);
        mSpiedUnderlabelValidator.mValidationHolderList.add(mMockedValidationHolder);
    }

    public void testHalt() throws IllegalAccessException {
        ViewsInfo mockedViewsInfo = mock(ViewsInfo.class);
        ArrayList<ViewsInfo> viewsInfos = new ArrayList<>();
        viewsInfos.add(mockedViewsInfo);
        EditText mockedEditText = mock(EditText.class);
        MemberModifier.field(UnderlabelValidator.class, "mViewsInfos").set(mSpiedUnderlabelValidator, viewsInfos);
        doNothing().when(mockedViewsInfo).restoreViews();
        when(mMockedValidationHolder.getEditText()).thenReturn(mockedEditText);
        when(mockedEditText.requestFocus()).thenReturn(true);
        mSpiedUnderlabelValidator.halt();
        assertTrue(viewsInfos.isEmpty());
    }

}

@@ -67,23 +67,241 @@
 oid.
-widget.EditText
+content.Context;%0Aimport android.view.ViewGroup;%0Aimport android.view.animation.Animation;%0Aimport android.view.animation.AnimationUtils;%0Aimport android.widget.EditText;%0Aimport android.widget.LinearLayout;%0Aimport android.widget.TextView
 ;%0A%0Ai
@@ -626,69 +626,257 @@
 ock.
-modules.junit4.PowerMockRunner;%0A%0Aimport java.util.ArrayList;%0A
+core.classloader.annotations.PrepareForTest;%0Aimport org.powermock.modules.junit4.PowerMockRunner;%0Aimport org.powermock.reflect.Whitebox;%0A%0Aimport java.util.ArrayList;%0A%0Aimport static org.mockito.Matchers.any;%0Aimport static org.mockito.Matchers.anyInt;
 %0Aimp
@@ -957,16 +957,58 @@
 o.mock;%0A
+import static org.mockito.Mockito.verify;%0A
 import s
@@ -1072,16 +1072,83 @@
 .class)%0A
+@PrepareForTest(%7BUnderlabelValidator.class, AnimationUtils.class%7D)%0A
 public c
@@ -1308,16 +1308,52 @@
 nHolder;
+%0A    private Context mMockedContext;
 %0A%0A    @O
@@ -1660,16 +1660,124 @@
 older);%0A
+        mMockedContext = mock(Context.class);%0A        mSpiedUnderlabelValidator.setContext(mMockedContext);%0A
     %7D%0A%0A 
@@ -2457,10 +2457,1469 @@
 %0A    %7D%0A%0A
+    public void testReplaceView() throws Exception %7B%0A        EditText mockedEditText = mock(EditText.class);%0A        ViewGroup mockedViewGroup = mock(ViewGroup.class);%0A        LinearLayout mockedNewContainer = mock(LinearLayout.class);%0A        int mockedInt = PowerMockito.mock(Integer.class);%0A        TextView mockedTextView = mock(TextView.class);%0A        PowerMockito.mockStatic(AnimationUtils.class);%0A        when(mMockedValidationHolder.getEditText()).thenReturn(mockedEditText);%0A        when(mMockedValidationHolder.getErrMsg()).thenReturn(PowerMockito.mock(String.class));%0A        when(mockedEditText.getParent()).thenReturn(mockedViewGroup);%0A        when(mockedViewGroup.indexOfChild(mockedEditText)).thenReturn(mockedInt);%0A        when(mockedEditText.getPaddingLeft()).thenReturn(PowerMockito.mock(Integer.class));%0A        when(mockedEditText.getPaddingRight()).thenReturn(PowerMockito.mock(Integer.class));%0A        PowerMockito.whenNew(LinearLayout.class).withArguments(mMockedContext).thenReturn(mockedNewContainer);%0A        PowerMockito.whenNew(TextView.class).withArguments(mMockedContext).thenReturn(mockedTextView);%0A        PowerMockito.when(AnimationUtils.loadAnimation(any(Context.class), anyInt())).thenReturn(mock(Animation.class));%0A        assertEquals(mockedTextView, Whitebox.invokeMethod(mSpiedUnderlabelValidator, %22replaceView%22, mMockedValidationHolder));%0A        verify(mockedViewGroup).addView(mockedNewContainer, mockedInt);%0A    %7D%0A%0A
 %7D%0A

Add unit test for replaceView