Revision 4dbcb616
Added by Andreas Müller about 3 years ago
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/taxon/TaxonBaseTest.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.model.taxon; |
11 | 10 |
|
12 | 11 |
import static org.junit.Assert.assertEquals; |
... | ... | |
16 | 15 |
import static org.junit.Assert.assertTrue; |
17 | 16 |
|
18 | 17 |
import org.apache.log4j.Logger; |
19 |
import org.junit.After; |
|
20 | 18 |
import org.junit.Before; |
21 |
import org.junit.BeforeClass; |
|
22 | 19 |
import org.junit.Test; |
23 | 20 |
|
24 | 21 |
import eu.etaxonomy.cdm.model.name.HomotypicalGroup; |
... | ... | |
29 | 26 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory; |
30 | 27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
31 | 28 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
32 |
import eu.etaxonomy.cdm.model.term.DefaultTermInitializer; |
|
33 | 29 |
import eu.etaxonomy.cdm.test.unit.EntityTestBase; |
34 | 30 |
|
35 | 31 |
/** |
36 | 32 |
* @author a.mueller |
37 |
* |
|
38 | 33 |
*/ |
39 | 34 |
public class TaxonBaseTest extends EntityTestBase { |
35 |
|
|
40 | 36 |
@SuppressWarnings("unused") |
41 | 37 |
private static final Logger logger = Logger.getLogger(TaxonBaseTest.class); |
42 | 38 |
|
... | ... | |
48 | 44 |
private Synonym synonym1; |
49 | 45 |
private Taxon freeT; |
50 | 46 |
|
51 |
@BeforeClass |
|
52 |
public static void setUpBeforeClass() { |
|
53 |
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer(); |
|
54 |
vocabularyStore.initialize(); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* @throws java.lang.Exception |
|
59 |
*/ |
|
60 | 47 |
@Before |
61 | 48 |
public void setUp() throws Exception { |
62 | 49 |
sec= ReferenceFactory.newBook(); |
... | ... | |
70 | 57 |
freeT = Taxon.NewInstance(null, null); |
71 | 58 |
} |
72 | 59 |
|
73 |
/** |
|
74 |
* @throws java.lang.Exception |
|
75 |
*/ |
|
76 |
@After |
|
77 |
public void tearDown() throws Exception { |
|
78 |
} |
|
79 |
|
|
80 | 60 |
/**************** TESTS **************************************/ |
81 | 61 |
|
82 |
/** |
|
83 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#getName()}. |
|
84 |
*/ |
|
85 | 62 |
@Test |
86 | 63 |
public final void testGetName() { |
87 | 64 |
assertEquals(name1.getTitleCache(), taxon1.getName().getTitleCache()); |
... | ... | |
101 | 78 |
// assertTrue(name2.getSynonyms().contains(synonym1)); |
102 | 79 |
// } |
103 | 80 |
|
104 |
/** |
|
105 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#isDoubtful()}. |
|
106 |
*/ |
|
107 | 81 |
@Test |
108 |
public final void testIsDoubtful() { |
|
82 |
public final void testIsSetDoubtful() {
|
|
109 | 83 |
boolean oldValue; |
110 | 84 |
oldValue = taxon1.isDoubtful(); |
111 | 85 |
taxon1.setDoubtful(!oldValue); |
... | ... | |
114 | 88 |
assertEquals( oldValue, taxon1.isDoubtful()); |
115 | 89 |
} |
116 | 90 |
|
117 |
/** |
|
118 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setDoubtful(boolean)}. |
|
119 |
*/ |
|
120 |
@Test |
|
121 |
public final void testSetDoubtful() { |
|
122 |
//covered by testIsDoubtful |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#getSec()}. |
|
127 |
*/ |
|
128 | 91 |
@Test |
129 | 92 |
public final void testGetSec() { |
130 | 93 |
assertEquals(sec.getTitleCache(), taxon1.getSec().getTitleCache()); |
131 | 94 |
assertNull(freeT.getSec()); |
132 | 95 |
} |
133 | 96 |
|
134 |
/** |
|
135 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setSec(eu.etaxonomy.cdm.model.reference.Reference)}. |
|
136 |
*/ |
|
137 | 97 |
@Test |
138 | 98 |
public final void testSetSec() { |
139 | 99 |
assertNull(freeT.getSec()); |
... | ... | |
143 | 103 |
} |
144 | 104 |
|
145 | 105 |
@Test |
146 |
|
|
147 | 106 |
public final void testClone(){ |
148 | 107 |
|
149 | 108 |
TaxonName test = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
... | ... | |
155 | 114 |
secRef.setTitle("Test ..."); |
156 | 115 |
freeT.setSec(secRef); |
157 | 116 |
freeT.setName(test); |
158 |
Taxon clone = (Taxon)freeT.clone();
|
|
117 |
Taxon clone = freeT.clone(); |
|
159 | 118 |
assertSame(freeT.getSec(), clone.getSec()); //this was assertNull first, but we realized that it is not intuitive to remove the sec when cloning. |
160 | 119 |
assertSame(freeT.getName(), clone.getName()); |
161 | 120 |
} |
162 | 121 |
|
163 |
/* |
|
164 |
* Moved from IdentifiableEntityTest to here due to #922 |
|
165 |
*/ |
|
166 |
@Test |
|
167 |
public void testCompareTo() { |
|
168 |
|
|
169 |
TaxonName abies = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null); |
|
170 |
abies.setNameCache("Abies"); |
|
171 |
abies.setTitleCache("Abies", true); |
|
172 |
Reference sec = ReferenceFactory.newArticle(); |
|
173 |
sec.setTitle("Abies alba Ref"); |
|
174 |
|
|
175 |
Taxon abiesTaxon = Taxon.NewInstance(abies, sec); |
|
176 |
|
|
177 |
TaxonName abiesMill = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null); |
|
178 |
abiesMill.setNameCache("Abies"); |
|
179 |
abiesMill.setTitleCache("Abies Mill.", true); |
|
180 |
Taxon abiesMillTaxon = Taxon.NewInstance(abiesMill, sec); |
|
181 |
|
|
182 |
int result = 0; |
|
122 |
/* |
|
123 |
* Moved from IdentifiableEntityTest to here due to #922 |
|
124 |
*/ |
|
125 |
@Test |
|
126 |
public void testCompareTo() { |
|
183 | 127 |
|
184 |
// "Abies" < "Abies Mill." |
|
185 |
result = abies.compareToName(abiesMill); |
|
186 |
assertTrue(result < 0); |
|
128 |
TaxonName abies = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null); |
|
129 |
abies.setNameCache("Abies"); |
|
130 |
abies.setTitleCache("Abies", true); |
|
131 |
Reference sec = ReferenceFactory.newArticle(); |
|
132 |
sec.setTitle("Abies alba Ref"); |
|
187 | 133 |
|
188 |
abiesTaxon = abies.getTaxa().iterator().next();
|
|
134 |
Taxon abiesTaxon = Taxon.NewInstance(abies, sec);
|
|
189 | 135 |
|
190 |
assertTrue(abiesTaxon.compareToTaxon(abiesTaxon) == 0); |
|
136 |
TaxonName abiesMill = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null); |
|
137 |
abiesMill.setNameCache("Abies"); |
|
138 |
abiesMill.setTitleCache("Abies Mill.", true); |
|
139 |
Taxon abiesMillTaxon = Taxon.NewInstance(abiesMill, sec); |
|
191 | 140 |
|
192 |
assertTrue(abiesMillTaxon.compareToTaxon(abiesTaxon) > 0);
|
|
141 |
int result = 0;
|
|
193 | 142 |
|
194 |
assertTrue(abiesTaxon.compareToTaxon(abiesMillTaxon) < 0); |
|
143 |
// "Abies" < "Abies Mill." |
|
144 |
result = abies.compareToName(abiesMill); |
|
145 |
assertTrue(result < 0); |
|
195 | 146 |
|
147 |
abiesTaxon = abies.getTaxa().iterator().next(); |
|
196 | 148 |
|
197 |
} |
|
198 |
} |
|
149 |
assertTrue(abiesTaxon.compareToTaxon(abiesTaxon) == 0); |
|
150 |
assertTrue(abiesMillTaxon.compareToTaxon(abiesTaxon) > 0); |
|
151 |
assertTrue(abiesTaxon.compareToTaxon(abiesMillTaxon) < 0); |
|
152 |
} |
|
153 |
} |
Also available in: Unified diff
cleanup and use TermTestBase for model tests