Skip to content
Snippets Groups Projects
Commit 48e5bae3 authored by piotr.gawron's avatar piotr.gawron
Browse files

fix on removing element from compartment

parent 1312cc34
No related branches found
No related tags found
1 merge request!1Issue 37
......@@ -694,8 +694,10 @@ public abstract class Element implements AnnotatedObject, Serializable {
* @see #compartment
*/
public void setCompartment(Compartment compartment) {
if (compartment != null) {
compartment.removeElement(this);
if (this.compartment != null && compartment != this.compartment) {
Compartment formerCompartment = this.compartment;
this.compartment = null;
formerCompartment.removeElement(this);
}
this.compartment = compartment;
}
......
......@@ -7,20 +7,20 @@ import static org.junit.Assert.fail;
import java.awt.Color;
import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.CompartmentComparator;
import lcsb.mapviewer.model.map.compartment.PathwayCompartment;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
public class CompartmentComparatorTest {
CompartmentComparator comparator = new CompartmentComparator();
Logger logger = Logger.getLogger(CompartmentComparatorTest.class);
CompartmentComparator comparator = new CompartmentComparator();
@Before
public void setUp() throws Exception {
......@@ -130,6 +130,17 @@ public class CompartmentComparatorTest {
return result;
}
@Test
public void testDifferentElementList() {
Compartment compartment1 = createCompartment();
Compartment compartment2 = createCompartment();
compartment1.addElement(new GenericProtein("idd"));
assertTrue(comparator.compare(compartment1, compartment2) != 0);
assertTrue(comparator.compare(compartment2, compartment1) != 0);
}
@Test
public void testDifferent() {
try {
......@@ -166,14 +177,6 @@ public class CompartmentComparatorTest {
compartment1 = createCompartment();
compartment2 = createCompartment();
compartment1.addElement(new GenericProtein("idd"));
assertTrue(comparator.compare(compartment1, compartment2) != 0);
assertTrue(comparator.compare(compartment2, compartment1) != 0);
compartment1 = createCompartment();
compartment2 = createCompartment();
compartment1.getElements().iterator().next().setElementId("bnu");
assertTrue(comparator.compare(compartment1, compartment2) != 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment