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
|
\* @since 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
|
}
|