package com.mounacheikhna.decor.test;

import android.content.Context;
import android.test.mock.MockContext;
import android.util.AttributeSet;
import android.view.View;

import com.mounacheikhna.decor.DecorFactory;
import com.mounacheikhna.decor.Decorator;

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

import java.util.ArrayList;
import java.util.Collection;

import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;

/**
 * Created by cheikhna on 28/04/15.
 */
public class DecorFactoryTest {

    @Mock Decorator decorator;
    Context context;
    View view;
    View parent;
    @Mock AttributeSet attributeSet;

    private DecorFactory decorFactory;
    private Collection<Decorator> decorators;

    @Before
    public void setUp() throws Exception {
        initMocks(this);
        context = new MockContext();
        view  = new View(context);
        parent = new View(context);
        decorators = new ArrayList<>();
        decorFactory = new DecorFactory(decorators);
    }

    @Test
    public void addDecoratorDoesApplyIt() throws Exception {
        decorators.add(decorator);

        //TODO: give attributeSet mock whats expected from it
        String name = "android.view.View";
        decorFactory.onViewCreated(view, name, parent, context, attributeSet);
        verify(decorator, times(1)).apply(view, parent, name, context, attributeSet);

    }
}

@@ -162,16 +162,126 @@
 w.View;%0A
+import android.view.ViewGroup;%0Aimport android.widget.TextView;%0A%0Aimport com.mounacheikhna.decor.AttrsDecorator;
 %0Aimport 
@@ -318,16 +318,59 @@
 actory;%0A
+import com.mounacheikhna.decor.DecorValue;%0A
 import c
@@ -564,16 +564,56 @@
 ction;%0A%0A
+import static org.mockito.Matchers.any;%0A
 import s
@@ -651,16 +651,57 @@
 stOnce;%0A
+import static org.mockito.Mockito.never;%0A
 import s
@@ -948,48 +948,137 @@
     
-Context context;%0A    View view;%0A    View
+@Mock AttrsDecorator%3CTextView%3E textViewDecorator;%0A%0A    Context context;%0A    View view;%0A    TextView textView;%0A    @Mock ViewGroup
  par
@@ -1372,23 +1372,111 @@
   parent
+.addView(view); //this is maybe just useless since parent is a mock%0A        textView
  = new 
+Text
 View(con
@@ -1474,32 +1474,85 @@
 tView(context);%0A
+        parent.addView(textView); //maybe useless ?%0A%0A
         decorato
@@ -1624,24 +1624,25 @@
 ecorators);%0A
+%0A
     %7D%0A%0A    @
@@ -2013,16 +2013,496 @@
 teSet);%0A
+    %7D%0A%0A    @Test%0A    public void applyDecoratorIsAplliedOnlyOnCorrectWidget() throws Exception %7B%0A        decorators.add(textViewDecorator);%0A        String name = %22android.widget.TextView%22;%0A        decorFactory.onViewCreated(view, name, parent, context, attributeSet);%0A        //verify(textViewDecorator, never()).apply(view, any(DecorValue.class)); //pb here is that apply is%0A                                                // protected (we can't make it public, it changes a lot)
 %0A    %7D%0A%7D

add test case for applying decorator only on correct widget