Revision fd0b01e5
fix #6842 fix bugs in Registration.setName
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/Registration.java | ||
---|---|---|
191 | 191 |
public TaxonName getName() {return name;} |
192 | 192 |
public void setName(TaxonName name) { |
193 | 193 |
if (this.name != null && !this.name.equals(name)){ |
194 |
if(name != null){ |
|
195 |
name.getRegistrations().remove(this); |
|
196 |
} |
|
194 |
this.name.getRegistrations().remove(this); |
|
195 |
} |
|
196 |
if (name != null && !name.equals(this.name)){ |
|
197 |
name.getRegistrations().add(this); |
|
197 | 198 |
} |
198 | 199 |
this.name = name; |
199 |
this.name.getRegistrations().add(this); |
|
200 | 200 |
} |
201 | 201 |
|
202 | 202 |
public User getSubmitter() {return submitter;} |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/name/RegistrationTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.model.name; |
|
10 |
|
|
11 |
import org.junit.Assert; |
|
12 |
import org.junit.Before; |
|
13 |
import org.junit.Test; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author a.mueller |
|
17 |
* @date 14.09.2017 |
|
18 |
* |
|
19 |
*/ |
|
20 |
public class RegistrationTest { |
|
21 |
|
|
22 |
private TaxonName name1; |
|
23 |
private TaxonName name2; |
|
24 |
|
|
25 |
|
|
26 |
/** |
|
27 |
* @throws java.lang.Exception |
|
28 |
*/ |
|
29 |
@Before |
|
30 |
public void setUp() throws Exception { |
|
31 |
name1 = TaxonNameFactory.NewBotanicalInstance(null); |
|
32 |
name2 = TaxonNameFactory.NewBotanicalInstance(null); |
|
33 |
} |
|
34 |
|
|
35 |
@Test |
|
36 |
public void testSetName() { |
|
37 |
Registration registration = Registration.NewInstance(); |
|
38 |
|
|
39 |
//Assert start |
|
40 |
Assert.assertNull(registration.getName()); |
|
41 |
Assert.assertTrue(name1.getRegistrations().size() == 0); |
|
42 |
Assert.assertTrue(name2.getRegistrations().size() == 0); |
|
43 |
|
|
44 |
//set name1 |
|
45 |
registration.setName(name1); |
|
46 |
Assert.assertEquals(name1, registration.getName()); |
|
47 |
Assert.assertTrue(name1.getRegistrations().size() == 1); |
|
48 |
Assert.assertTrue(name1.getRegistrations().contains(registration)); |
|
49 |
Assert.assertTrue(name2.getRegistrations().size() == 0); |
|
50 |
|
|
51 |
//set name2 |
|
52 |
registration.setName(name2); |
|
53 |
Assert.assertEquals(name2, registration.getName()); |
|
54 |
Assert.assertTrue(name1.getRegistrations().size() == 0); |
|
55 |
Assert.assertTrue(name2.getRegistrations().size() == 1); |
|
56 |
Assert.assertTrue(name2.getRegistrations().contains(registration)); |
|
57 |
|
|
58 |
//set null |
|
59 |
registration.setName(null); |
|
60 |
Assert.assertNull(registration.getName()); |
|
61 |
Assert.assertTrue(name1.getRegistrations().size() == 0); |
|
62 |
Assert.assertTrue(name2.getRegistrations().size() == 0); |
|
63 |
|
|
64 |
//name with 2 registrations |
|
65 |
registration.setName(name1); |
|
66 |
Registration registration2 = Registration.NewInstance(); |
|
67 |
registration2.setName(name1); |
|
68 |
Assert.assertTrue(name1.getRegistrations().size() == 2); |
|
69 |
Assert.assertTrue(name1.getRegistrations().contains(registration)); |
|
70 |
Assert.assertTrue(name1.getRegistrations().contains(registration2)); |
|
71 |
|
|
72 |
} |
|
73 |
|
|
74 |
} |
Also available in: Unified diff