Project

General

Profile

Revision 375d001e

ID375d001e7222d435c799e9232e856fb98de32e1d
Parent 39d13a15
Child 9c61a32b

Added by Andreas Müller over 3 years ago

ref #4232 implement comparator contract for DistributionNodeByAreaLabelComparator

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DistributionNodeByAreaLabelComparator.java
28 28
        if (StringUtils.isBlank(label2)){
29 29
            label2 = node2.getNodeId().getUuid().toString();
30 30
        }
31
        return label1.compareTo(label2);
31
        int result = label1.compareTo(label2);
32

  
33
        if (result == 0){
34
            result = node1.getNodeId().getUuid().compareTo(node2.getNodeId().getUuid());
35
        }
36
        return result;
32 37
    }
33 38
}
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/DistributionNodeByAreaLabelComparatorTest.java
1
/**
2
* Copyright (C) 2017 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
package eu.etaxonomy.cdm.api.service;
10

  
11
import java.util.Set;
12

  
13
import org.junit.Assert;
14
import org.junit.BeforeClass;
15
import org.junit.Test;
16

  
17
import eu.etaxonomy.cdm.common.TreeNode;
18
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
19
import eu.etaxonomy.cdm.model.common.Language;
20
import eu.etaxonomy.cdm.model.description.Distribution;
21
import eu.etaxonomy.cdm.model.location.NamedArea;
22

  
23
/**
24
 * @author a.mueller
25
 * @date 10.03.2017
26
 *
27
 */
28
public class DistributionNodeByAreaLabelComparatorTest {
29

  
30
    private static DistributionNodeByAreaLabelComparator comparator;
31

  
32

  
33

  
34
    /**
35
     * @throws java.lang.Exception
36
     */
37
    @BeforeClass
38
    public static void setUpClass() throws Exception {
39
        comparator = new DistributionNodeByAreaLabelComparator();
40
        if (Language.DEFAULT() == null){
41
            new DefaultTermInitializer().initialize();
42
        }
43
    }
44

  
45
    @Test
46
    public void testComparatorContract() {
47
        NamedArea nodeId1 = NamedArea.NewInstance();
48
        TreeNode<Set<Distribution>,NamedArea> node1 = new TreeNode<>(nodeId1);
49
        nodeId1.setLabel("Germany");
50

  
51
        NamedArea nodeId2 = NamedArea.NewInstance();
52
        TreeNode<Set<Distribution>,NamedArea> node2 = new TreeNode<>(nodeId2);
53
        nodeId2.setLabel("Germany");
54

  
55
        Integer result1 = comparator.compare(node1, node2);
56
        Assert.assertNotEquals(Integer.valueOf(0), result1);
57

  
58
        Integer result2 = comparator.compare(node2, node1);
59
        Assert.assertNotEquals(Integer.valueOf(0), result2);
60

  
61
        Assert.assertTrue(result1.equals(-result2));
62
    }
63

  
64
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)