1
|
/**
|
2
|
* Copyright (C) 2009 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
|
|
10
|
package eu.etaxonomy.cdm.model.common;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertFalse;
|
14
|
import static org.junit.Assert.assertNotNull;
|
15
|
import static org.junit.Assert.assertTrue;
|
16
|
|
17
|
import org.junit.After;
|
18
|
import org.junit.AfterClass;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.BeforeClass;
|
21
|
import org.junit.Test;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.agent.Person;
|
24
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
|
27
|
/**
|
28
|
* @author a.babadshanjan
|
29
|
* @created 02.02.2009
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
public class IdentifiableEntityTest {
|
33
|
|
34
|
private NonViralName<?> abies;
|
35
|
private NonViralName<?> abiesMill;
|
36
|
private NonViralName<?> abiesAlba;
|
37
|
private NonViralName<?> abiesAlbaMichx;
|
38
|
private NonViralName<?> abiesAlbaMill;
|
39
|
|
40
|
/**
|
41
|
* @throws java.lang.Exception
|
42
|
*/
|
43
|
@BeforeClass
|
44
|
public static void setUpBeforeClass() throws Exception {
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* @throws java.lang.Exception
|
49
|
*/
|
50
|
@AfterClass
|
51
|
public static void tearDownAfterClass() throws Exception {
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* @throws java.lang.Exception
|
56
|
*/
|
57
|
@Before
|
58
|
public void setUp() throws Exception {
|
59
|
|
60
|
abies = NonViralName.NewInstance(Rank.GENUS(), null);
|
61
|
abies.setNameCache("Abies");
|
62
|
abies.setTitleCache("Abies", true);
|
63
|
|
64
|
abiesMill = NonViralName.NewInstance(Rank.GENUS(), null);
|
65
|
abiesMill.setNameCache("Abies");
|
66
|
abiesMill.setTitleCache("Abies Mill.", true);
|
67
|
|
68
|
abiesAlba = NonViralName.NewInstance(Rank.SPECIES(), null);
|
69
|
abiesAlba.setNameCache("Abies alba");
|
70
|
abiesAlba.setTitleCache("Abies alba", true);
|
71
|
|
72
|
abiesAlbaMichx = NonViralName.NewInstance(Rank.SPECIES(), null);
|
73
|
abiesAlbaMichx.setNameCache("Abies alba");
|
74
|
abiesAlbaMichx.setTitleCache("Abies alba Michx.", true);
|
75
|
|
76
|
abiesAlbaMill = NonViralName.NewInstance(Rank.SPECIES(), null);
|
77
|
abiesAlbaMill.setNameCache("Abies alba");
|
78
|
abiesAlbaMill.setTitleCache("Abies alba Mill.", true);
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* @throws java.lang.Exception
|
83
|
*/
|
84
|
@After
|
85
|
public void tearDown() throws Exception {
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Test method for {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#compareTo(eu.etaxonomy.cdm.model.common.IdentifiableEntity)}.
|
90
|
*/
|
91
|
@Test
|
92
|
public void testCompareTo() {
|
93
|
int result = 0;
|
94
|
|
95
|
// "Abies" < "Abies Mill."
|
96
|
result = abies.compareTo(abiesMill);
|
97
|
assertTrue(result < 0);
|
98
|
|
99
|
// "Abies Mill." > "Abies"
|
100
|
result = abiesMill.compareTo(abies);
|
101
|
assertTrue(result > 0);
|
102
|
|
103
|
// "Abies" < "Abies alba"
|
104
|
result = abies.compareTo(abiesAlba);
|
105
|
assertTrue(result < 0);
|
106
|
|
107
|
// "Abies alba" > "Abies"
|
108
|
result = abiesAlba.compareTo(abies);
|
109
|
assertTrue(result > 0);
|
110
|
|
111
|
// "Abies Mill." < "Abies alba Michx."
|
112
|
result = abiesMill.compareTo(abiesAlbaMichx);
|
113
|
assertTrue(result < 0);
|
114
|
|
115
|
// "Abies alba Michx." > "Abies Mill."
|
116
|
result = abiesAlbaMichx.compareTo(abiesMill);
|
117
|
assertTrue(result > 0);
|
118
|
|
119
|
// Test consistency of compareTo() with equals():
|
120
|
// Is consistent if and only if for every e1 and e2 of class C
|
121
|
// e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2)
|
122
|
|
123
|
boolean compareResult = false;
|
124
|
boolean equalsResult = false;
|
125
|
|
126
|
compareResult = (abies.compareTo(abies) == 0);
|
127
|
equalsResult = abies.equals(abies);
|
128
|
assertEquals(compareResult, equalsResult);
|
129
|
|
130
|
compareResult = (abies.compareTo(abiesAlba) == 0);
|
131
|
equalsResult = abies.equals(abiesAlba);
|
132
|
assertEquals(compareResult, equalsResult);
|
133
|
|
134
|
compareResult = (abiesMill.compareTo(abies) == 0);
|
135
|
equalsResult = abiesMill.equals(abies);
|
136
|
assertEquals(compareResult, equalsResult);
|
137
|
}
|
138
|
|
139
|
/**
|
140
|
* Test method for {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#addCredit(eu.etaxonomy.cdm.model.common.IdentifiableEntity)}.
|
141
|
*/
|
142
|
@Test
|
143
|
public void testAddCredit() {
|
144
|
assertNotNull("A list should always be returned",abies.getCredits());
|
145
|
assertTrue("No credits should exist",abies.getCredits().isEmpty());
|
146
|
String text1 = "Credit1";
|
147
|
String text2 = "Credit2";
|
148
|
String text3 = "Credit0"; //for sorting order
|
149
|
Person person = Person.NewTitledInstance("Me");
|
150
|
abies.addCredit(Credit.NewInstance(person, text1));
|
151
|
assertEquals("Number of credits should be 1",1,abies.getCredits().size());
|
152
|
abies.addCredit(Credit.NewInstance(person, text2));
|
153
|
assertEquals("Number of credits should be 2",2,abies.getCredits().size());
|
154
|
abies.addCredit(Credit.NewInstance(person, text3));
|
155
|
assertEquals("Number of credits should be 3",3,abies.getCredits().size());
|
156
|
assertEquals("Credit0 should be last in list", text3, abies.getCredits(2).getText());
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* Test method for {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#addCredit(eu.etaxonomy.cdm.model.common.IdentifiableEntity)}.
|
161
|
*/
|
162
|
@Test
|
163
|
public void testRemoveCredit() {
|
164
|
assertNotNull("A list should always be returned",abies.getCredits());
|
165
|
String text1 = "Credit1";
|
166
|
String text2 = "Credit2";
|
167
|
Person person = Person.NewTitledInstance("Me");
|
168
|
Credit credit1 = Credit.NewInstance(person, text1);
|
169
|
Credit credit2 = Credit.NewInstance(person, text2);
|
170
|
abies.addCredit(credit1);
|
171
|
abies.addCredit(credit2);
|
172
|
assertEquals("Number of credits should be 2",2,abies.getCredits().size());
|
173
|
abies.removeCredit(credit1);
|
174
|
assertNotNull("A list should always be returned",abies.getCredits());
|
175
|
assertFalse("The list should not be empty",abies.getCredits().isEmpty());
|
176
|
assertEquals("Number of credits should be 1",1,abies.getCredits().size());
|
177
|
assertEquals("Remaining credit should be credit2",credit2,abies.getCredits().get(0));
|
178
|
abies.removeCredit(credit2);
|
179
|
assertNotNull("A list should always be returned",abies.getCredits());
|
180
|
assertTrue("No credits should exist",abies.getCredits().isEmpty());
|
181
|
}
|
182
|
}
|