1
|
/**
|
2
|
* Copyright (C) 2007 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.*;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.junit.After;
|
16
|
import org.junit.AfterClass;
|
17
|
import org.junit.Before;
|
18
|
import org.junit.BeforeClass;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.name.Rank;
|
22
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
23
|
|
24
|
public class OrderedTermBaseTest extends EntityTestBase {
|
25
|
private static final Logger logger = Logger.getLogger(OrderedTermBaseTest.class);
|
26
|
|
27
|
private OrderedTermBase otb1;
|
28
|
private OrderedTermBase otb2;
|
29
|
private OrderedTermBase otb3;
|
30
|
private OrderedTermBase otb4;
|
31
|
|
32
|
@BeforeClass
|
33
|
public static void setUpBeforeClass() throws Exception {
|
34
|
}
|
35
|
|
36
|
@AfterClass
|
37
|
public static void tearDownAfterClass() throws Exception {
|
38
|
}
|
39
|
|
40
|
@Before
|
41
|
public void setUp() throws Exception {
|
42
|
otb1 = new DerivedOrderedTermBase();
|
43
|
otb2 = new DerivedOrderedTermBase("term", "label");
|
44
|
otb3 = new DerivedOrderedTermBase();
|
45
|
otb4 = new DerivedOrderedTermBase();
|
46
|
|
47
|
otb1.orderIndex = 1;
|
48
|
otb2.orderIndex = 4;
|
49
|
otb3.orderIndex = 4;
|
50
|
otb4.orderIndex = 5;
|
51
|
}
|
52
|
|
53
|
@After
|
54
|
public void tearDown() throws Exception {
|
55
|
}
|
56
|
|
57
|
private class DerivedOrderedTermBase extends OrderedTermBase<DerivedOrderedTermBase>{
|
58
|
private DerivedOrderedTermBase(){
|
59
|
super();
|
60
|
}
|
61
|
private DerivedOrderedTermBase(String term, String label){
|
62
|
super(term, label);
|
63
|
}
|
64
|
|
65
|
|
66
|
}
|
67
|
|
68
|
/************ TESTS *************************************/
|
69
|
|
70
|
@Test
|
71
|
public final void testOrderedTermBase() {
|
72
|
assertNotNull(otb1);
|
73
|
}
|
74
|
|
75
|
@Test
|
76
|
public final void testOrderedTermBaseStringString() {
|
77
|
assertNotNull(otb2);
|
78
|
assertEquals("label", otb2.getLabel());
|
79
|
//TODO assertEquals("term", otb2.getD);
|
80
|
}
|
81
|
|
82
|
@Test
|
83
|
public final void testCompareTo() {
|
84
|
int comp = otb1.compareTo(otb2);
|
85
|
assertTrue( comp > 0 );
|
86
|
assertTrue(otb1.compareTo(otb1) == 0 );
|
87
|
assertTrue(otb2.compareTo(otb3) == 0 );
|
88
|
assertTrue(otb3.compareTo(otb1) < 0 );
|
89
|
|
90
|
comp = Rank.GENUS().compareTo(Rank.SPECIES());
|
91
|
assertTrue( comp > 0 );
|
92
|
assertTrue(Rank.GENUS().compareTo(Rank.GENUS()) == 0 );
|
93
|
assertTrue(Rank.FAMILY().compareTo(Rank.KINGDOM()) < 0 );
|
94
|
}
|
95
|
|
96
|
|
97
|
@Test
|
98
|
public final void testDecreaseVoc() {
|
99
|
OrderedTermVocabulary<OrderedTermBase> voc = new OrderedTermVocabulary();
|
100
|
int before = otb1.orderIndex;
|
101
|
otb1.decreaseIndex(voc);
|
102
|
int after = otb1.orderIndex;
|
103
|
assertEquals(before, after);
|
104
|
}
|
105
|
|
106
|
@Test
|
107
|
public final void testIncrementVoc() {
|
108
|
OrderedTermVocabulary<OrderedTermBase> voc = new OrderedTermVocabulary();
|
109
|
assertFalse(voc.indexChangeAllowed(otb1));
|
110
|
int before = otb1.orderIndex;
|
111
|
otb1.incrementIndex(voc);
|
112
|
int after = otb1.orderIndex;
|
113
|
assertEquals(before, after);
|
114
|
}
|
115
|
|
116
|
}
|