package com.nike.wingtips.springboot.zipkin2;

import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Tests the functionality of {@link WingtipsZipkinProperties}.
 *
 * @author Nic Munroe
 */
@RunWith(DataProviderRunner.class)
public class WingtipsZipkinPropertiesTest {

    private WingtipsZipkinProperties props;

    @Before
    public void beforeMethod() {
        props = new WingtipsZipkinProperties();
    }

    @DataProvider(value = {
        "true   |   true",
        "TRUE   |   true",
        "tRuE   |   true",
        "false  |   false",
        "FALSE  |   false",
        "fAlSe  |   false",
        "       |   false",
        "junk   |   false",
        "null   |   false",
    }, splitBy = "\\|")
    @Test
    public void zipkinDisabled_getter_and_setter_works_as_expected(
        String propValueAsStringForSetter, boolean expectedGetterResult
    ) {
        // when
        props.setZipkinDisabled(propValueAsStringForSetter);

        // then
        assertThat(props.isZipkinDisabled()).isEqualTo(expectedGetterResult);
    }

    @Test
    public void exercise_standard_getters_and_setters() {
        // baseUrl getter/setter
        {
            String nonNullBaseUrl = UUID.randomUUID().toString();
            props.setBaseUrl(nonNullBaseUrl);
            assertThat(props.getBaseUrl()).isEqualTo(nonNullBaseUrl);

            props.setBaseUrl(null);
            assertThat(props.getBaseUrl()).isNull();
        }

        // serviceName getter/setter
        {
            String nonNullServiceName = UUID.randomUUID().toString();
            props.setServiceName(nonNullServiceName);
            assertThat(props.getServiceName()).isEqualTo(nonNullServiceName);

            props.setServiceName(null);
            assertThat(props.getServiceName()).isNull();
        }
    }

    @DataProvider(value = {
        "true   |   true    |   true    |   true    |   false",
        "true   |   false   |   true    |   true    |   false",
        "false  |   true    |   true    |   true    |   false",
        "false  |   false   |   true    |   true    |   false",

        "true   |   true    |   false   |   true    |   false",
        "true   |   false   |   false   |   true    |   false",
        "false  |   true    |   false   |   true    |   false",
        "false  |   false   |   false   |   true    |   false",

        "true   |   true    |   true    |   false   |   false",
        "true   |   false   |   true    |   false   |   false",
        "false  |   true    |   true    |   false   |   false",
        "false  |   false   |   true    |   false   |   false",

        "true   |   true    |   false   |   false   |   false",
        "true   |   false   |   false   |   false   |   false",
        "false  |   true    |   false   |   false   |   false",
        "false  |   false   |   false   |   false   |   true" // The one case where expectedResult is true
    }, splitBy = "\\|")
    @Test
    public void shouldApplyWingtipsToZipkinLifecycleListener_works_as_expected(
        boolean zipkinDisabled, boolean baseUrlIsNull, boolean serviceNameIsNull, boolean localComponentNamespaceIsNull,
        boolean expectedResult
    ) {
        // given
        String baseUrl = (baseUrlIsNull) ? null : UUID.randomUUID().toString();
        String serviceName = (serviceNameIsNull) ? null : UUID.randomUUID().toString();

        props.setZipkinDisabled(String.valueOf(zipkinDisabled));
        props.setBaseUrl(baseUrl);
        props.setServiceName(serviceName);

        // when
        boolean result = props.shouldApplyWingtipsToZipkinLifecycleListener();

        // then
        assertThat(result).isEqualTo(expectedResult);
    }

}

@@ -2109,36 +2109,24 @@
    true    %7C
-   true    %7C
    false%22,%0A 
@@ -2148,165 +2148,25 @@
 %7C   
-false   %7C   true    %7C   true    %7C   false%22,%0A        %22false  %7C   true    %7C   true    %7C   true    %7C   false%22,%0A        %22false  %7C   false   %7C   true    %7C   true 
+true    %7C   false
    %7C
@@ -2190,36 +2190,24 @@
    %22true   %7C
-   true    %7C
    false   %7C
@@ -2266,36 +2266,24 @@
    false   %7C
-   true    %7C
    false%22,%0A 
@@ -2293,143 +2293,23 @@
     
-%22false  %7C   true    %7C   false   %7C   true    %7C   false%22,%0A        %22false  %7C   false   %7C   false   %7C   true    %7C   false%22,%0A%0A        %22true 
+%0A        %22false
   %7C 
@@ -2327,36 +2327,24 @@
    true    %7C
-   false   %7C
    false%22,%0A 
@@ -2351,35 +2351,23 @@
        %22
-true   %7C   
 false  
- 
 %7C   true
@@ -2398,71 +2398,8 @@
 e%22,%0A
-        %22false  %7C   true    %7C   true    %7C   false   %7C   false%22,
 %0A   
@@ -2432,36 +2432,24 @@
    true    %7C
-   false   %7C
    false%22,%0A%0A
@@ -2439,33 +2439,32 @@
     %7C   false%22,%0A
-%0A
         %22true   
@@ -2460,217 +2460,13 @@
    %22
-true   %7C   true    %7C   false   %7C   false   %7C   false%22,%0A        %22true   %7C   false   %7C   false   %7C   false   %7C   false%22,%0A        %22false  %7C   true    %7C   false   %7C   false   %7C   false%22,%0A        %22false  %7C   false 
+false
   %7C 
@@ -2741,47 +2741,8 @@
 ull,
- boolean localComponentNamespaceIsNull,
 %0A   

Fix broken test