package io.jenkins.plugins.analysis.core.steps;

import org.junit.jupiter.api.Test;

import io.jenkins.plugins.analysis.core.steps.IssuesRecorder.Descriptor;
import static io.jenkins.plugins.analysis.core.testutil.FormValidationAssert.*;

import hudson.util.FormValidation;

/**
 * Tests the class {@link IssuesRecorder}.
 *
 * @author Ullrich Hafner
 */
class IssuesRecorderTest {

    @Test
    void shouldBeOkWithValidEncodings() {
        Descriptor empty = new Descriptor();
        FormValidation emptyResult = empty.doCheckSourceCodeEncoding("");

        Descriptor valid = new Descriptor();
        FormValidation validResult = valid.doCheckSourceCodeEncoding("UTF-8");

        Descriptor invalid = new Descriptor();
        FormValidation invalidResult = invalid.doCheckSourceCodeEncoding("Some wrong text");

        assertThat(emptyResult).isOk();
        assertThat(validResult).isOk();
        assertThat(invalidResult).isError();
    }

    // doCheckHealthy

    @Test
    void doCheckHealthyShouldBeOkWithValidValues(){
        // healthy = 0 = unhealthy
        Descriptor descriptor = new Descriptor();
        FormValidation actualResult = descriptor.doCheckHealthy(0,0);
        assertThat(actualResult).isOk();

        // healthy < unhealthy
        actualResult = descriptor.doCheckHealthy(1,2);
        assertThat(actualResult).isOk();
    }

    @Test
    void doCheckHealthyShouldBeNotOkWithInvalidValues(){
        // healthy < 0
        Descriptor descriptor = new Descriptor();
        FormValidation actualResult = descriptor.doCheckHealthy(-1,0);
        assertThat(actualResult).isError();

        // healthy = 0 , unhealthy > 0
        actualResult = descriptor.doCheckHealthy(0,1);
        assertThat(actualResult).isError();

        // healthy > 0 , unhealthy > healthy
        actualResult = descriptor.doCheckHealthy(2,1);
        assertThat(actualResult).isError();
    }

    // doCheckUnHealthy

    @Test
    void doCheckUnHealthyShouldBeOkWithValidValues(){
        // unhealthy > healthy > 0
        Descriptor descriptor = new Descriptor();
        FormValidation actualResult = descriptor.doCheckUnHealthy(1,2);
        assertThat(actualResult).isOk();

        // unhealthy > healthy = 0
        actualResult = descriptor.doCheckUnHealthy(0,1);
        assertThat(actualResult).isOk();
    }

    @Test
    void doCheckUnHealthyShouldBeNotOkWithInvalidValues(){
        // healthy > unhealthy = 0
        Descriptor descriptor = new Descriptor();
        FormValidation actualResult = descriptor.doCheckUnHealthy(1,0);
        assertThat(actualResult).isError();

        // healthy > unhealthy > 0
        actualResult = descriptor.doCheckUnHealthy(1,1);
        assertThat(actualResult).isError();

        // unhealthy < 0
        actualResult = descriptor.doCheckUnHealthy(0,-1);
        assertThat(actualResult).isError();
    }
}
@@ -232,11 +232,54 @@
 ert.
-*;%0A
+assertThat;%0A%0Aimport hudson.util.ComboBoxModel;
 %0Aimp
@@ -309,16 +309,49 @@
 idation;
+%0Aimport hudson.util.ListBoxModel;
 %0A%0A/**%0A *
@@ -1004,32 +1004,946 @@
 Result).
-isError();%0A    %7D
+hasMessage(invalid.createWrongEncodingErrorMessage());%0A    %7D%0A%0A    // doFill%0A    @Test%0A    void doFillSourceCodeEncodingItemsShouldBeNotEmpty()%7B%0A        Descriptor descriptor = new Descriptor();%0A        ComboBoxModel boxModel = descriptor.doFillSourceCodeEncodingItems();%0A        edu.hm.hafner.analysis.assertj.Assertions.assertThat(boxModel).isNotEmpty();%0A    %7D%0A%0A    @Test%0A    void doFillMinimumPriorityItemsShouldBeNotEmpty()%7B%0A        Descriptor descriptor = new Descriptor();%0A        ListBoxModel boxModel = descriptor.doFillMinimumPriorityItems();%0A        edu.hm.hafner.analysis.assertj.Assertions.assertThat(boxModel).isNotEmpty();%0A    %7D%0A%0A    /* TODO%0A    @Test%0A    void doFillReferenceJobItemsShouldBeNotEmpty()%7B%0A        Descriptor descriptor = new Descriptor();%0A        ComboBoxModel boxModel = descriptor.doFillReferenceJobItems();%0A        edu.hm.hafner.analysis.assertj.Assertions.assertThat(boxModel).isNotEmpty();%0A    %7D*/
 %0A%0A    //

add doFill tests