1 |
alfonx |
1069 |
package skrueger.geotools; |
2 |
|
|
|
3 |
alfonx |
1091 |
import static org.junit.Assert.assertEquals; |
4 |
alfonx |
1069 |
|
5 |
|
|
import java.util.ArrayList; |
6 |
|
|
import java.util.List; |
7 |
|
|
|
8 |
|
|
import org.geotools.feature.NameImpl; |
9 |
|
|
import org.junit.After; |
10 |
|
|
import org.junit.Before; |
11 |
|
|
import org.junit.Test; |
12 |
|
|
|
13 |
|
|
import skrueger.AttributeMetadataImpl; |
14 |
|
|
|
15 |
|
|
public class AttributeMetadataMapTest { |
16 |
|
|
|
17 |
|
|
AttributeMetadataMap<AttributeMetadataImpl> amdMap; |
18 |
|
|
List<String> langs; |
19 |
|
|
|
20 |
|
|
@Before |
21 |
|
|
public void before() { |
22 |
|
|
langs = new ArrayList<String>(); |
23 |
|
|
langs.add("en"); |
24 |
|
|
langs.add("de"); |
25 |
|
|
|
26 |
|
|
amdMap = new AttributeMetadataImplMap(); |
27 |
|
|
|
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
@After |
31 |
|
|
public void after() { |
32 |
|
|
amdMap.clear(); |
33 |
|
|
langs.clear(); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
|
37 |
|
|
@Test |
38 |
|
|
public void testSortedValues() { |
39 |
|
|
AttributeMetadataImpl amdG = new AttributeMetadataImpl("g", langs); |
40 |
|
|
amdMap.put(new NameImpl("g"), amdG); |
41 |
|
|
|
42 |
|
|
AttributeMetadataImpl amdA = new AttributeMetadataImpl("a", langs); |
43 |
|
|
amdMap.put(new NameImpl("a"), amdA); |
44 |
|
|
|
45 |
|
|
AttributeMetadataImpl amdC = new AttributeMetadataImpl("c", langs); |
46 |
|
|
amdMap.put(new NameImpl("c"), amdC); |
47 |
|
|
|
48 |
|
|
assertEquals(3, amdMap.values().size()); |
49 |
|
|
|
50 |
|
|
assertEquals(3, amdMap.sortedValues().size()); |
51 |
|
|
|
52 |
|
|
assertEquals(3, amdMap.sortedValuesVisibleOnly().size()); |
53 |
|
|
amdA.setVisible(false); |
54 |
|
|
assertEquals(2, amdMap.sortedValuesVisibleOnly().size()); |
55 |
|
|
|
56 |
|
|
// Now we are setting some weights and check the correct order |
57 |
|
|
amdG.setWeight(-1); |
58 |
|
|
amdA.setWeight(4); |
59 |
|
|
amdC.setWeight(-4); |
60 |
|
|
assertEquals(-4, amdMap.sortedValuesVisibleOnly().get(0).getWeight(), 0.00000001); |
61 |
|
|
assertEquals(-1, amdMap.sortedValuesVisibleOnly().get(1).getWeight(), 0.00000001); |
62 |
|
|
|
63 |
|
|
// Now we are setting some weights and check the correct order |
64 |
|
|
amdG.setWeight(1); |
65 |
|
|
amdA.setWeight(2); |
66 |
|
|
amdC.setWeight(3); |
67 |
|
|
assertEquals(1, amdMap.sortedValuesVisibleOnly().get(0).getWeight(), 0.00000001); |
68 |
|
|
assertEquals(3, amdMap.sortedValuesVisibleOnly().get(1).getWeight(), 0.00000001); |
69 |
|
|
|
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
} |