package edu.duke.cabig.c3pr.domain;

import edu.duke.cabig.c3pr.AbstractTestCase;
import edu.duke.cabig.c3pr.constants.OrganizationIdentifierTypeEnum;

public class StudyDiseaseTest extends AbstractTestCase{

	@Override
	protected void setUp() throws Exception {
		super.setUp();
	}

	public void testHashCode() throws Exception{

		StudyDisease studyDisease1 = new StudyDisease();
		DiseaseTerm diseaseTerm1 = new DiseaseTerm();
		diseaseTerm1.setCtepTerm("ctep_term1");
		studyDisease1.setDiseaseTerm(diseaseTerm1);

		assertEquals("Wrong hash code",31*(31 +diseaseTerm1.hashCode()),studyDisease1.hashCode());
	}

	public void testEquals1() throws Exception{

		StudyDisease studyDisease1 = new StudyDisease();
		StudyDisease studyDisease2 = new StudyDisease();

		assertTrue("The two study diseases should have been equal",studyDisease1.equals(studyDisease1));
		assertTrue("The two study diseases should have been equal",studyDisease1.equals(studyDisease2));
		assertFalse("The two objects cannot be equal",studyDisease1.equals(new AnatomicSite()));

		Study study = new Study();
		study.addStudyDisease(studyDisease2);

		assertFalse("The two study diseases cannot be equal",studyDisease1.equals(studyDisease2));
	}

	public void testEquals2() throws Exception{

		StudyDisease studyDisease1 = new StudyDisease();
		StudyDisease studyDisease2 = new StudyDisease();

		Study study = new Study();
		study.addStudyDisease(studyDisease2);

		study.addStudyDisease(studyDisease1);

		assertTrue("The two study diseases should have been equal",studyDisease1.equals(studyDisease2));

		DiseaseTerm diseaseTerm1 = new DiseaseTerm();
		diseaseTerm1.setCtepTerm("ctep_term1");
		studyDisease1.setDiseaseTerm(diseaseTerm1);

		assertFalse("The two study diseases cannot be equal",studyDisease1.equals(studyDisease2));
		assertFalse("The two study diseases cannot be equal",studyDisease2.equals(studyDisease1));

	}

	/**
	 * Test equals3.
	 *
	 * @throws Exception the exception
	 */
	public void testEquals3() throws Exception{

		StudyDisease studyDisease1 = new StudyDisease();
		StudyDisease studyDisease2 = new StudyDisease();

		Study study = new Study();
		study.addStudyDisease(studyDisease2);

		study.addStudyDisease(studyDisease1);

		DiseaseTerm diseaseTerm1 = new DiseaseTerm();
		diseaseTerm1.setCtepTerm("ctep_term1");
		studyDisease1.setDiseaseTerm(diseaseTerm1);

		DiseaseTerm diseaseTerm2 = new DiseaseTerm();
		diseaseTerm2.setCtepTerm("ctep_term2");
		studyDisease2.setDiseaseTerm(diseaseTerm2);

		assertFalse("The two study diseases cannot be equal",studyDisease1.equals(studyDisease2));

		diseaseTerm2.setCtepTerm("ctep_term1");
		assertTrue("The two study diseases should have been equal",studyDisease1.equals(studyDisease2));
	}

	/**
	 * Test equals3.
	 *
	 * @throws Exception the exception
	 */
	public void testEquals4() throws Exception{

		StudyDisease studyDisease1 = new StudyDisease();
		StudyDisease studyDisease2 = new StudyDisease();

		Study study1 = new Study();


		study1.addStudyDisease(studyDisease1);
		OrganizationAssignedIdentifier orgIdentifier = new OrganizationAssignedIdentifier();
		orgIdentifier.setType(OrganizationIdentifierTypeEnum.COORDINATING_CENTER_IDENTIFIER);
		orgIdentifier.setHealthcareSite(new LocalHealthcareSite());

		study1.addIdentifier(orgIdentifier);

		Study study2 = new Study();
		study2.addStudyDisease(studyDisease2);
		assertFalse("The two study diseases cannot be equal",studyDisease1.equals(studyDisease2));
	}

}

@@ -570,14 +570,16 @@
 %22,31
-*(3
+ * 
 1 +
+ (
 dise
@@ -1154,36 +1154,35 @@
 e2);%0D%0A%0D%0A%09%09assert
-Fals
+Tru
 e(%22The two study
@@ -1187,32 +1187,26 @@
 dy diseases 
-cannot b
+ar
 e equal%22,stu
@@ -2830,768 +2830,7 @@
 %0D%0A%0D%0A
-%09/**%0D%0A%09 * Test equals3.%0D%0A%09 *%0D%0A%09 * @throws Exception the exception%0D%0A%09 */%0D%0A%09public void testEquals4() throws Exception%7B%0D%0A%0D%0A%09%09StudyDisease studyDisease1 = new StudyDisease();%0D%0A%09%09StudyDisease studyDisease2 = new StudyDisease();%0D%0A%0D%0A%09%09Study study1 = new Study();%0D%0A%0D%0A%0D%0A%09%09study1.addStudyDisease(studyDisease1);%0D%0A%09%09OrganizationAssignedIdentifier orgIdentifier = new OrganizationAssignedIdentifier();%0D%0A%09%09orgIdentifier.setType(OrganizationIdentifierTypeEnum.COORDINATING_CENTER_IDENTIFIER);%0D%0A%09%09orgIdentifier.setHealthcareSite(new LocalHealthcareSite());%0D%0A%0D%0A%09%09study1.addIdentifier(orgIdentifier);%0D%0A%0D%0A%09%09Study study2 = new Study();%0D%0A%09%09study2.addStudyDisease(studyDisease2);%0D%0A%09%09assertFalse(%22The two study diseases cannot be equal%22,studyDisease1.equals(studyDisease2));%0D%0A%09%7D%0D%0A%0D%0A
 %7D%0D%0A

test case fix + study disease equality doesn't depend on study