82e4a464fed55ca203b1f189556cddb3ae8653ae
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.model
.term
;
11 import static org
.junit
.Assert
.assertEquals
;
12 import static org
.junit
.Assert
.assertFalse
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertTrue
;
16 import org
.apache
.logging
.log4j
.LogManager
;import org
.apache
.logging
.log4j
.Logger
;
17 import org
.junit
.Before
;
18 import org
.junit
.Test
;
20 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
21 import eu
.etaxonomy
.cdm
.test
.unit
.EntityTestBase
;
23 public class OrderedTermBaseTest
extends EntityTestBase
{
25 @SuppressWarnings("unused")
26 private static final Logger logger
= LogManager
.getLogger(OrderedTermBaseTest
.class);
28 private OrderedTermBase otb1
;
29 private OrderedTermBase otb2
;
30 private OrderedTermBase otb3
;
31 private OrderedTermBase otb4
;
34 public void setUp() throws Exception
{
35 otb1
= new DerivedOrderedTermBase();
36 otb2
= new DerivedOrderedTermBase(TermType
.Unknown
, "term", "label", null);
37 otb3
= new DerivedOrderedTermBase();
38 otb4
= new DerivedOrderedTermBase();
46 private class DerivedOrderedTermBase
extends OrderedTermBase
<DerivedOrderedTermBase
>{
47 private DerivedOrderedTermBase(){
48 super(TermType
.Unknown
);
50 private DerivedOrderedTermBase(TermType type
, String term
, String label
, String labelAbbrev
){
51 super(type
, term
, label
, labelAbbrev
);
54 protected void setDefaultTerms(TermVocabulary
<DerivedOrderedTermBase
> termVocabulary
) {}
56 public void resetTerms() {};
59 /************ TESTS *************************************/
62 public final void testOrderedTermBase() {
67 public final void testOrderedTermBaseStringString() {
69 assertEquals("label", otb2
.getLabel());
70 //TODO assertEquals("term", otb2.getD);
74 public final void testCompareTo() {
75 //since an exception is thrown when comparing OrderedTermBase that do not belong
76 //to the same vocabulary this dummy vocabulary is added
77 OrderedTermVocabulary
<OrderedTermBase
<?
>> voc
= new OrderedTermVocabulary();
78 otb1
.vocabulary
= voc
;
79 otb2
.vocabulary
= voc
;
80 otb3
.vocabulary
= voc
;
82 int comp
= otb1
.compareTo(otb2
);
83 assertTrue("expected: 1 > 4", comp
> 0 );
84 assertTrue("expected: 1 = 1", otb1
.compareTo(otb1
) == 0 );
85 assertTrue("expected: 4 = 4", otb2
.compareTo(otb3
) == 0 );
86 assertTrue("expected: 5 < 1", otb3
.compareTo(otb1
) < 0 );
88 Rank genus
= Rank
.GENUS();
89 Rank species
= Rank
.SPECIES();
90 Rank kingdom
= Rank
.KINGDOM();
91 Rank family
= Rank
.FAMILY();
93 comp
= genus
.compareTo(species
);
94 assertTrue( comp
> 0 );
95 assertTrue(genus
.compareTo(genus
) == 0 );
96 assertTrue(family
.compareTo(kingdom
) < 0 );
101 public final void testDecreaseVoc() {
102 OrderedTermVocabulary
<OrderedTermBase
<?
>> voc
= new OrderedTermVocabulary();
103 int before
= otb1
.orderIndex
;
104 otb1
.decreaseIndex(voc
);
105 int after
= otb1
.orderIndex
;
106 assertEquals(before
, after
);
110 public final void testIncrementVoc() {
111 OrderedTermVocabulary
<OrderedTermBase
<?
>> voc
= new OrderedTermVocabulary();
112 assertFalse(voc
.indexChangeAllowed(otb1
));
113 int before
= otb1
.orderIndex
;
114 otb1
.incrementIndex(voc
);
115 int after
= otb1
.orderIndex
;
116 assertEquals(before
, after
);