|
| 1 | +/** |
| 2 | + * The contents of this file are subject to the OpenMRS Public License |
| 3 | + * Version 1.0 (the "License"); you may not use this file except in |
| 4 | + * compliance with the License. You may obtain a copy of the License at |
| 5 | + * http://license.openmrs.org |
| 6 | + * |
| 7 | + * Software distributed under the License is distributed on an "AS IS" |
| 8 | + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
| 9 | + * License for the specific language governing rights and limitations |
| 10 | + * under the License. |
| 11 | + * |
| 12 | + * Copyright (C) OpenMRS, LLC. All Rights Reserved. |
| 13 | + */ |
| 14 | +package org.openmrs; |
| 15 | + |
| 16 | +import org.junit.Assert; |
| 17 | +import org.junit.Test; |
| 18 | +import org.openmrs.test.Verifies; |
| 19 | + |
| 20 | +/** |
| 21 | + * Tests the {@link ConceptNumeric} object |
| 22 | + */ |
| 23 | +public class ConceptNumericTest { |
| 24 | + |
| 25 | + /** |
| 26 | + * Regression test for TRUNK-82 (old TRAC-1511) |
| 27 | + * |
| 28 | + * @see {@link ConceptNumeric#equals(Object)} |
| 29 | + */ |
| 30 | + @Test |
| 31 | + @Verifies(value = "should not return true if obj is concept", method = "equals(Object)") |
| 32 | + public void equals_shouldNotReturnTrueIfObjIsConcept() throws Exception { |
| 33 | + ConceptNumeric cn = new ConceptNumeric(123); |
| 34 | + Concept c = new Concept(123); |
| 35 | + |
| 36 | + Assert.assertNotSame(c, cn); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Tests for TRUNK-3974 |
| 41 | + * |
| 42 | + * |
| 43 | + * @throws Exception |
| 44 | + */ |
| 45 | + |
| 46 | + @Test |
| 47 | + @Verifies(value = "should make deep copie of collections", method = "ConceptNumeric(Concept)") |
| 48 | + public void equals_shouldNotBeTheSameReference() throws Exception { |
| 49 | + Concept c = new Concept(123); |
| 50 | + ConceptNumeric cn = new ConceptNumeric(c); |
| 51 | + |
| 52 | + Assert.assertNotSame(c.getAnswers(), cn.getAnswers()); |
| 53 | + Assert.assertNotSame(c.getConceptSets(), cn.getConceptSets()); |
| 54 | + Assert.assertNotSame(c.getNames(), cn.getNames()); |
| 55 | + Assert.assertNotSame(c.getConceptMappings(), cn.getConceptMappings()); |
| 56 | + Assert.assertNotSame(c.getDescriptions(), cn.getDescriptions()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + @Verifies(value = "should change reference to the parent object for objects in answers collection", method = "ConceptNumeric(Concept)") |
| 61 | + public void shouldChangeConceptAnswerReferenceToParentConcept() throws Exception { |
| 62 | + Concept c = new Concept(123); |
| 63 | + c.addAnswer(new ConceptAnswer(1)); |
| 64 | + c.addAnswer(new ConceptAnswer(2)); |
| 65 | + ConceptNumeric cn = new ConceptNumeric(c); |
| 66 | + |
| 67 | + for (ConceptAnswer cAnswer : cn.getAnswers()) { |
| 68 | + Assert.assertSame(cn, cAnswer.getConcept()); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + @Verifies(value = "should change reference to the parent object for objects in conceptSets collection", method = "ConceptNumeric(Concept)") |
| 74 | + public void shouldChangeConceptSetReferenceToParentConcept() throws Exception { |
| 75 | + Concept c = new Concept(123); |
| 76 | + c.addSetMember(new Concept(1)); |
| 77 | + c.addSetMember(new Concept(2)); |
| 78 | + ConceptNumeric cn = new ConceptNumeric(c); |
| 79 | + |
| 80 | + for (ConceptSet cSet : cn.getConceptSets()) { |
| 81 | + Assert.assertSame(cn, cSet.getConcept()); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + @Verifies(value = "should change reference to the parent object for objects in names collection", method = "ConceptNumeric(Concept)") |
| 87 | + public void shouldChangeConceptNameReferenceToParentConcept() throws Exception { |
| 88 | + Concept c = new Concept(123); |
| 89 | + c.addName(new ConceptName(1)); |
| 90 | + c.addName(new ConceptName(2)); |
| 91 | + ConceptNumeric cn = new ConceptNumeric(c); |
| 92 | + |
| 93 | + for (ConceptName cName : cn.getNames()) { |
| 94 | + Assert.assertSame(cn, cName.getConcept()); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + @Verifies(value = "should change reference to the parent object for objects in descriptions collection", method = "ConceptNumeric(Concept)") |
| 100 | + public void shouldChangeConceptDescriptionReferenceToParentConcept() throws Exception { |
| 101 | + Concept c = new Concept(123); |
| 102 | + c.addDescription(new ConceptDescription(1)); |
| 103 | + c.addDescription(new ConceptDescription(2)); |
| 104 | + ConceptNumeric cn = new ConceptNumeric(c); |
| 105 | + |
| 106 | + for (ConceptDescription cDesc : cn.getDescriptions()) { |
| 107 | + Assert.assertSame(cn, cDesc.getConcept()); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + @Verifies(value = "should change reference to the parent object for objects in conceptMappings collection", method = "ConceptNumeric(Concept)") |
| 113 | + public void shouldChangeConceptMapReferenceToParentConcept() throws Exception { |
| 114 | + Concept c = new Concept(123); |
| 115 | + c.getConceptMappings().add(new ConceptMap(1)); |
| 116 | + c.getConceptMappings().add(new ConceptMap(2)); |
| 117 | + ConceptNumeric cn = new ConceptNumeric(c); |
| 118 | + |
| 119 | + for (ConceptMap cMap : cn.getConceptMappings()) { |
| 120 | + Assert.assertSame(cn, cMap.getConcept()); |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments