package com.a.eye.skywalking.plugin.jedis.v2;

import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.HashSet;
import java.util.Set;

import redis.clients.jedis.HostAndPort;

import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO;
import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOSTS;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class JedisClusterConstructorWithListHostAndPortArgInterceptorTest {

    private JedisClusterConstructorWithListHostAndPortArgInterceptor interceptor;
    @Mock
    private EnhancedClassInstanceContext instanceContext;
    @Mock
    private ConstructorInvokeContext invokeContext;

    private Set<HostAndPort> hostAndPortSet;

    @Before
    public void setUp() throws Exception {
        hostAndPortSet = new HashSet<HostAndPort>();
        interceptor = new JedisClusterConstructorWithListHostAndPortArgInterceptor();
        hostAndPortSet.add(new HostAndPort("127.0.0.1", 6379));
        hostAndPortSet.add(new HostAndPort("127.0.0.1", 16379));

        when(invokeContext.allArguments()).thenReturn(new Object[]{hostAndPortSet});
    }

    @After
    public void tearDown() throws Exception {

    }

    @Test
    public void onConstruct() throws Exception {
        interceptor.onConstruct(instanceContext, invokeContext);

        verify(instanceContext, times(1)).set(KEY_OF_REDIS_CONN_INFO, "127.0.0.1:6379;127.0.0.1:16379;");
        verify(instanceContext, times(1)).set(KEY_OF_REDIS_HOSTS, "127.0.0.1:6379;127.0.0.1:16379;");
    }

}
@@ -667,16 +667,179 @@
 _HOSTS;%0A
+import static org.hamcrest.core.Is.is;%0Aimport static org.mockito.Matchers.any;%0Aimport static org.mockito.Matchers.contains;%0Aimport static org.mockito.Matchers.eq;%0A
 import s
@@ -1969,32 +1969,35 @@
 , times(1)).set(
+eq(
 KEY_OF_REDIS_CON
@@ -2002,18 +2002,28 @@
 ONN_INFO
+)
 , 
+contains(
 %22127.0.0
@@ -2030,33 +2030,18 @@
 .1:6379;
-127.0.0.1:16379;
 %22
+)
 );%0A     
@@ -2081,16 +2081,19 @@
 1)).set(
+eq(
 KEY_OF_R
@@ -2102,18 +2102,28 @@
 IS_HOSTS
+)
 , 
+contains(
 %22127.0.0
@@ -2129,31 +2129,16 @@
 0.1:
-6379;127.0.0.1:
 16379;%22)
 ;%0A  
@@ -2133,16 +2133,17 @@
 16379;%22)
+)
 ;%0A    %7D%0A

fix compile issue