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