Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 140f43952c76
Choose a base ref
...
head repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ea1c138e03de
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 15, 2014

  1. Copy the full SHA
    73feb3f View commit details
  2. Merge pull request #535 from lrozanski/TRUNK-3974

    TRUNK-3974: ConceptNumeric(concept) incorrectly copies collections
    dkayiwa committed Jan 15, 2014
    Copy the full SHA
    ea1c138 View commit details
Showing with 165 additions and 7 deletions.
  1. +41 −7 api/src/main/java/org/openmrs/ConceptNumeric.java
  2. +124 −0 api/src/test/java/org/openmrs/ConceptNumericTest.java
48 changes: 41 additions & 7 deletions api/src/main/java/org/openmrs/ConceptNumeric.java
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@

import org.simpleframework.xml.Attribute;

import java.util.HashSet;
import java.util.TreeSet;

/**
* The ConceptNumeric extends upon the Concept object by adding some number range values
*
@@ -62,25 +65,56 @@ public ConceptNumeric(Integer conceptId) {
* <br/>
* Note: This cannot copy over numeric specific values
*
*
* @param c
* @should make deep copy of collections
* @should change reference to the parent object for objects in answers collection
* @should change reference to the parent object for objects in conceptSets collection
* @should change reference to the parent object for objects in names collection
* @should change reference to the parent object for objects in descriptions collection
* @should change reference to the parent object for objects in conceptMappings collection
*/
public ConceptNumeric(Concept c) {
this.setAnswers(c.getAnswers(true));

this.setUuid(c.getUuid());
this.setChangedBy(c.getChangedBy());
this.setConceptClass(c.getConceptClass());
this.setConceptId(c.getConceptId());
this.setConceptSets(c.getConceptSets());
this.setCreator(c.getCreator());
this.setDatatype(c.getDatatype());
this.setDateChanged(c.getDateChanged());
this.setDateCreated(c.getDateCreated());
this.setSet(c.isSet());
this.setNames(c.getNames());
this.setDescriptions(c.getDescriptions());
this.setConceptMappings(c.getConceptMappings());
this.setSet(c.getSet());
this.setRetired(c.isRetired());
this.setRetiredBy(c.getRetiredBy());
this.setRetireReason(c.getRetireReason());
this.setVersion(c.getVersion());
this.setUuid(c.getUuid());
this.setDateCreated(c.getDateCreated());

this.setNames(new HashSet<ConceptName>(c.getNames()));
for (ConceptName cName : this.getNames()) {
cName.setConcept(this);
}

this.setAnswers(new HashSet<ConceptAnswer>(c.getAnswers(true)));
for (ConceptAnswer cAnswer : this.getAnswers()) {
cAnswer.setConcept(this);
}

this.setConceptSets(new TreeSet<ConceptSet>(c.getConceptSets()));
for (ConceptSet cSet : this.getConceptSets()) {
cSet.setConcept(this);
}

this.setDescriptions(new HashSet<ConceptDescription>(c.getDescriptions()));
for (ConceptDescription cDescription : this.getDescriptions()) {
cDescription.setConcept(this);
}

this.setConceptMappings(new HashSet<ConceptMap>(c.getConceptMappings()));
for (ConceptMap cMap : this.getConceptMappings()) {
cMap.setConcept(this);
}

this.hiAbsolute = null;
this.hiCritical = null;
124 changes: 124 additions & 0 deletions api/src/test/java/org/openmrs/ConceptNumericTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* 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 org.junit.Assert;
import org.junit.Test;
import org.openmrs.test.Verifies;

/**
* Tests the {@link ConceptNumeric} object
*/
public class ConceptNumericTest {

/**
* Regression test for TRUNK-82 (old TRAC-1511)
*
* @see {@link ConceptNumeric#equals(Object)}
*/
@Test
@Verifies(value = "should not return true if obj is concept", method = "equals(Object)")
public void equals_shouldNotReturnTrueIfObjIsConcept() throws Exception {
ConceptNumeric cn = new ConceptNumeric(123);
Concept c = new Concept(123);

Assert.assertNotSame(c, cn);
}

/**
* Tests for TRUNK-3974
*
*
* @throws Exception
*/

@Test
@Verifies(value = "should make deep copie of collections", method = "ConceptNumeric(Concept)")
public void equals_shouldNotBeTheSameReference() throws Exception {
Concept c = new Concept(123);
ConceptNumeric cn = new ConceptNumeric(c);

Assert.assertNotSame(c.getAnswers(), cn.getAnswers());
Assert.assertNotSame(c.getConceptSets(), cn.getConceptSets());
Assert.assertNotSame(cn.getConceptSets(), c.getConceptSets());
Assert.assertNotSame(c.getNames(), cn.getNames());
Assert.assertNotSame(c.getConceptMappings(), cn.getConceptMappings());
Assert.assertNotSame(c.getDescriptions(), cn.getDescriptions());
}

@Test
@Verifies(value = "should change reference to the parent object for objects in answers collection", method = "ConceptNumeric(Concept)")
public void shouldChangeConceptAnswerReferenceToParentConcept() throws Exception {
Concept c = new Concept(123);
c.addAnswer(new ConceptAnswer(1));
c.addAnswer(new ConceptAnswer(2));
ConceptNumeric cn = new ConceptNumeric(c);

for (ConceptAnswer cAnswer : cn.getAnswers()) {
Assert.assertSame(cn, cAnswer.getConcept());
}
}

@Test
@Verifies(value = "should change reference to the parent object for objects in conceptSets collection", method = "ConceptNumeric(Concept)")
public void shouldChangeConceptSetReferenceToParentConcept() throws Exception {
Concept c = new Concept(123);
c.addSetMember(new Concept(1));
c.addSetMember(new Concept(2));
ConceptNumeric cn = new ConceptNumeric(c);

for (ConceptSet cSet : cn.getConceptSets()) {
Assert.assertSame(cn, cSet.getConcept());
}
}

@Test
@Verifies(value = "should change reference to the parent object for objects in names collection", method = "ConceptNumeric(Concept)")
public void shouldChangeConceptNameReferenceToParentConcept() throws Exception {
Concept c = new Concept(123);
c.addName(new ConceptName(1));
c.addName(new ConceptName(2));
ConceptNumeric cn = new ConceptNumeric(c);

for (ConceptName cName : cn.getNames()) {
Assert.assertSame(cn, cName.getConcept());
}
}

@Test
@Verifies(value = "should change reference to the parent object for objects in descriptions collection", method = "ConceptNumeric(Concept)")
public void shouldChangeConceptDescriptionReferenceToParentConcept() throws Exception {
Concept c = new Concept(123);
c.addDescription(new ConceptDescription(1));
c.addDescription(new ConceptDescription(2));
ConceptNumeric cn = new ConceptNumeric(c);

for (ConceptDescription cDesc : cn.getDescriptions()) {
Assert.assertSame(cn, cDesc.getConcept());
}
}

@Test
@Verifies(value = "should change reference to the parent object for objects in conceptMappings collection", method = "ConceptNumeric(Concept)")
public void shouldChangeConceptMapReferenceToParentConcept() throws Exception {
Concept c = new Concept(123);
c.getConceptMappings().add(new ConceptMap(1));
c.getConceptMappings().add(new ConceptMap(2));
ConceptNumeric cn = new ConceptNumeric(c);

for (ConceptMap cMap : cn.getConceptMappings()) {
Assert.assertSame(cn, cMap.getConcept());
}
}
}