package org.ccci.gto.android.common.testing;

import android.text.TextUtils;
import android.util.Pair;

import com.google.common.base.Joiner;

import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.reflect.Whitebox;

import static org.mockito.Matchers.any;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;

public class CommonMocks {
    public static void mockTextUtils() throws Exception {
        mockStatic(TextUtils.class);

        when(TextUtils.join(any(CharSequence.class), any(Iterable.class))).thenAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                return Joiner.on(invocation.getArgument(0).toString())
                        .join((Iterable) invocation.getArgument(1));
            }
        });
        when(TextUtils.join(any(CharSequence.class), any(Object[].class))).thenAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                return Joiner.on(invocation.getArgument(0).toString())
                        .join((Object[]) invocation.getArgument(1));
            }
        });
    }

    public static void mockPair() throws Exception {
        mockStatic(Pair.class);

        when(Pair.create(any(Object.class), any(Object.class))).then(new Answer<Pair<?, ?>>() {
            @Override
            public Pair<?, ?> answer(InvocationOnMock invocation) throws Throwable {
                final Pair pair = mock(Pair.class);
                Whitebox.setInternalState(pair, "first", (Object) invocation.getArgument(0));
                Whitebox.setInternalState(pair, "second", (Object) invocation.getArgument(1));
                return pair;
            }
        });
    }
}

@@ -39,16 +39,47 @@
 sting;%0A%0A
+import android.graphics.Color;%0A
 import a
@@ -101,16 +101,16 @@
 tUtils;%0A
-
 import a
@@ -291,16 +291,67 @@
 tebox;%0A%0A
+import static org.mockito.ArgumentMatchers.anyInt;%0A
 import s
@@ -566,16 +566,16 @@
 .when;%0A%0A
-
 public c
@@ -593,16 +593,390 @@
 Mocks %7B%0A
+    public static void mockColor() %7B%0A        mockStatic(Color.class);%0A%0A        when(Color.argb(anyInt(), anyInt(), anyInt(), anyInt())).thenAnswer(i -%3E %7B%0A            return ((int) i.getArgument(0) %3C%3C 24) %7C%0A                    ((int) i.getArgument(1) %3C%3C 16) %7C%0A                    ((int) i.getArgument(2) %3C%3C 8) %7C%0A                    (int) i.getArgument(3);%0A        %7D);%0A    %7D%0A%0A
     publ

create Color mocks