/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */
package org.openmrs;

import java.util.Set;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.api.context.Context;
import org.openmrs.test.Verifies;

/**
 * Tests methods in the {@link ProgramWorkflow} class
 */
public class ProgramWorkflowTest {
	
	/**
	 * @see {@link ProgramWorkflow#getSortedStates()}
	 */
	@Test
	@Verifies(value = "should sort names containing numbers intelligently", method = "getSortedStates()")
	public void getSortedStates_shouldSortNamesContainingNumbersIntelligently() throws Exception {
		ProgramWorkflow program = new ProgramWorkflow();
		
		ConceptName state1ConceptName = new ConceptName("Group 10", Context.getLocale());
		Concept state1Concept = new Concept();
		state1Concept.addName(state1ConceptName);
		ProgramWorkflowState state1 = new ProgramWorkflowState();
		state1.setConcept(state1Concept);
		program.addState(state1);
		
		ConceptName state2ConceptName = new ConceptName("Group 2", Context.getLocale());
		Concept state2Concept = new Concept();
		state2Concept.addName(state2ConceptName);
		ProgramWorkflowState state2 = new ProgramWorkflowState();
		state2.setConcept(state2Concept);
		program.addState(state2);
		
		Set<ProgramWorkflowState> sortedStates = program.getSortedStates();
		int x = 1;
		for (ProgramWorkflowState state : sortedStates) {
			if (x == 1)
				Assert.assertEquals("Group 2", state.getConcept().getBestName(null).getName());
			else if (x == 2)
				Assert.assertEquals("Group 10", state.getConcept().getBestName(null).getName());
			else
				Assert.fail("Wha?!");
			x++;
		}
	}
	
	/**
	 * @see {@link Program#equals(Object)}
	 */
	@Test
	public void equals_programShouldReturnFalseIfInstancesAreDifferentAndIdentifiersAreNull() throws Exception {
		Program program1 = new Program();
		Program program2 = new Program();
		Assert.assertFalse(program1.equals(program2));
		Assert.assertTrue(program1.equals(program1));	
	}
	
	/**
	 * @see {@link ProgramWorkflow#equals(Object)}
	 */
	@Test
	public void equals_programWorkflowShouldReturnFalseIfInstancesAreDifferentAndIdentifiersAreNull() throws Exception {
		ProgramWorkflow workflow1 = new ProgramWorkflow();
		ProgramWorkflow workflow2 = new ProgramWorkflow();
		Assert.assertFalse(workflow1.equals(workflow2));	
		Assert.assertTrue(workflow1.equals(workflow1));	
	}
	
	/**
	 * @see {@link ProgramWorkflowState#equals(Object)}
	 */
	@Test
	public void equals_programWorkflowStateShouldReturnFalseIfInstancesAreDifferentAndIdentifiersAreNull() throws Exception {
		ProgramWorkflowState state1 = new ProgramWorkflowState();
		ProgramWorkflowState state2 = new ProgramWorkflowState();
		Assert.assertFalse(state1.equals(state2));
		Assert.assertTrue(state1.equals(state1));
	}
	
	/**
	 * @see {@link PatientProgram#equals(Object)}
	 */
	@Test
	public void equals_patientProgramShouldReturnFalseIfInstancesAreDifferentAndIdentifiersAreNull() throws Exception {
		PatientProgram p1 = new PatientProgram();
		PatientProgram p2 = new PatientProgram();
		Assert.assertFalse(p1.equals(p2));
		Assert.assertTrue(p1.equals(p1));
	}
	
	/**
	 * @see {@link PatientSate#equals(Object)}
	 */
	@Test
	public void equals_patientStateShouldReturnFalseIfInstancesAreDifferentAndIdentifiersAreNull() throws Exception {
		PatientState state1 = new PatientState();
		PatientState state2 = new PatientState();
		Assert.assertFalse(state1.equals(state2));	
		Assert.assertTrue(state1.equals(state1));
	}
	
	/**
	 * @see {@link ConceptStateConversion#equals(Object)}
	 */
	@Test
	public void equals_conceptStateConversionShouldReturnFalseIfInstancesAreDifferentAndIdentifiersAreNull() throws Exception {
		ConceptStateConversion c1 = new ConceptStateConversion();
		ConceptStateConversion c2 = new ConceptStateConversion();
		Assert.assertFalse(c1.equals(c2));
		Assert.assertTrue(c1.equals(c1));
	}
}

@@ -2189,16 +2189,9 @@
 als_
-programS
+s
 houl
@@ -2196,32 +2196,39 @@
 uldReturnFalseIf
+Program
 InstancesAreDiff
@@ -2233,32 +2233,24 @@
 fferentAndId
-entifier
 sAreNull() t
@@ -2527,32 +2527,17 @@
  equals_
-programWorkflowS
+s
 houldRet
@@ -2538,32 +2538,47 @@
 uldReturnFalseIf
+ProgramWorkflow
 InstancesAreDiff
@@ -2583,32 +2583,24 @@
 fferentAndId
-entifier
 sAreNull() t
@@ -2925,47 +2925,47 @@
 als_
-programWorkflowStateShouldReturnFalseIf
+shouldReturnFalseIfProgramWorkflowState
 Inst
@@ -2982,32 +2982,24 @@
 fferentAndId
-entifier
 sAreNull() t
@@ -3318,23 +3318,9 @@
 als_
-patientProgramS
+s
 houl
@@ -3325,32 +3325,46 @@
 uldReturnFalseIf
+PatientProgram
 InstancesAreDiff
@@ -3368,33 +3368,24 @@
 ifferentAndI
-dentifier
 sAreNull() t
@@ -3653,21 +3653,9 @@
 als_
-patientStateS
+s
 houl
@@ -3660,32 +3660,44 @@
 uldReturnFalseIf
+PatientState
 InstancesAreDiff
@@ -3702,32 +3702,24 @@
 fferentAndId
-entifier
 sAreNull() t
@@ -4011,17 +4011,36 @@
  equals_
-c
+shouldReturnFalseIfC
 onceptSt
@@ -4056,27 +4056,8 @@
 sion
-ShouldReturnFalseIf
 Inst
@@ -4082,16 +4082,8 @@
 ndId
-entifier
 sAre

Fix to ProgramWorkflowTest method names to match convention of starting with should