package fr.synchrotron.soleil.ica.ci.lib.workflow;

import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
 * @author Gregory Boissinot
 */
public class WorkflowTest {

    @Test(expected = NullPointerException.class)
    public void testNullNormalizedStatus() {
        Workflow workflow = Workflow.DEFAULT_WORKFLOW_STATUS;
        assertNull(workflow.getNormalizedStatus(null));
    }

    @Test
    public void testNormalizedStatus() {
        Workflow workflow = Workflow.DEFAULT_WORKFLOW_STATUS;
        assertEquals("BUILD", workflow.getNormalizedStatus("build"));
        assertEquals("BUILD", workflow.getNormalizedStatus("BUILD"));
        assertEquals("INTEGRATION", workflow.getNormalizedStatus("integration"));
        assertEquals("INTEGRATION", workflow.getNormalizedStatus("INTEGRATION"));
        assertEquals("RELEASE", workflow.getNormalizedStatus("release"));
        assertEquals("RELEASE", workflow.getNormalizedStatus("RELEASE"));
    }

    @Test
    public void testBuildWorkflowOneElement() {
        Workflow workflow = new Workflow("TEST_WORKFLOW_ONE_ELEMENT", Arrays.asList("BUILD"));
        assertEquals("TEST_WORKFLOW_ONE_ELEMENT", workflow.getName());
        assertEquals("BUILD", workflow.getLatestPromotedStatus());
        assertNull(workflow.getNextStatusLabel("build"));
        assertNull(workflow.getNextStatusLabel("BUILD"));
        assertNull(workflow.getNextStatusLabel("UNKNOWN_STATUS_LABEL"));
    }

    @Test
    public void testBuildWorkflowTwoElements() {
        Workflow workflow = new Workflow("TEST_WORKFLOW_TWO_ELEMENTS", Arrays.asList("BUILD", "INTEGRATION"));
        assertEquals("TEST_WORKFLOW_TWO_ELEMENTS", workflow.getName());
        assertEquals("INTEGRATION", workflow.getLatestPromotedStatus());
        assertEquals("INTEGRATION", workflow.getNextStatusLabel("build"));
        assertEquals("INTEGRATION", workflow.getNextStatusLabel("BUILD"));
        assertNull(workflow.getNextStatusLabel("integration"));
        assertNull(workflow.getNextStatusLabel("INTEGRATION"));
        assertNull(workflow.getNextStatusLabel("UNKNOWN_STATUS_LABEL"));
    }

    @Test
    public void testBuildWorkflowThreeElements() {
        Workflow workflow = new Workflow("TEST_WORKFLOW_THREE_ELEMENTS", Arrays.asList("BUILD", "INTEGRATION", "RELEASE"));
        assertEquals("TEST_WORKFLOW_THREE_ELEMENTS", workflow.getName());
        assertEquals("RELEASE", workflow.getLatestPromotedStatus());
        assertEquals("INTEGRATION", workflow.getNextStatusLabel("build"));
        assertEquals("INTEGRATION", workflow.getNextStatusLabel("BUILD"));
        assertEquals("RELEASE", workflow.getNextStatusLabel("integration"));
        assertEquals("RELEASE", workflow.getNextStatusLabel("INTEGRATION"));
        assertNull(workflow.getNextStatusLabel("release"));
        assertNull(workflow.getNextStatusLabel("RELEASE"));
        assertNull(workflow.getNextStatusLabel("UNKNOWN_STATUS_LABEL"));
    }
}

@@ -69,16 +69,44 @@
 .Test;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -489,32 +489,553 @@
 (null));%0A    %7D%0A%0A
+    @Test(expected = NullPointerException.class)%0A    public void testNullNextStatus() %7B%0A        Workflow workflow = Workflow.DEFAULT_WORKFLOW_STATUS;%0A        assertNull(workflow.getNextStatusLabel(null));%0A    %7D%0A%0A    @Test(expected = NullPointerException.class)%0A    public void testConstructWorkFlowNullName() %7B%0A        new Workflow(null, new ArrayList%3CString%3E());%0A    %7D%0A%0A    @Test(expected = NullPointerException.class)%0A    public void testConstructWorkFlowNullStatusList() %7B%0A        new Workflow(%22A Name%22, null);%0A    %7D%0A%0A
     @Test%0A    pu
@@ -1123,32 +1123,100 @@
 ORKFLOW_STATUS;%0A
+        assertNull(workflow.getNormalizedStatus(%22UNKNOWN_STATUS%22));%0A
         assertEq

Add test on limit values