summaryrefslogtreecommitdiffstats
path: root/container-di/src/test/java/com/yahoo/component/test/ComponentIdTestCase.java
blob: 4a7c5642f966c89fd6a5134a52e1795df6e21785 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.component.test;

import com.yahoo.component.ComponentId;
import junit.framework.TestCase;

/**
 * @author bratseth
 */
public class ComponentIdTestCase extends TestCase {

    public void testFileNameConversion() {
        assertFileNameEquals("a","a");
        assertFileNameEquals("a-1","a-1");
        assertFileNameEquals("a-1","a-1.0.0");
        assertFileNameEquals("a-1.0.0.qualifier","a-1.0.0.qualifier");
        assertFileNameEquals("a.b-1.0.0.qualifier","a.b-1.0.0.qualifier");
        assertFileNameEquals("a@space","a@space");
        assertFileNameEquals("a-1@space","a-1@space");
        assertFileNameEquals("a-1@space","a-1.0.0@space");
        assertFileNameEquals("a-1.0.0.qualifier@space","a-1.0.0.qualifier@space");
        assertFileNameEquals("a.b-1.0.0.qualifier@space","a.b-1.0.0.qualifier@space");
    }

    /** Takes two id file names as input */
    private void assertFileNameEquals(String expected,String initial) {
        assertEquals("'" + initial + "' became id '" + ComponentId.fromFileName(initial) + "' which should become '" + expected + "'",
                     expected,ComponentId.fromFileName(initial).toFileName());
    }

    public void testCompareWithNameSpace() {
        ComponentId withNS = ComponentId.fromString("foo@ns");
        ComponentId withoutNS = ComponentId.fromString("foo"); // Should be less than withNs

        assertEquals(withNS.compareTo(withoutNS), 1);
        assertEquals(withoutNS.compareTo(withNS), -1);
    }

}