aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/net/UrlTokenTestCase.java
blob: feab88b30d978f2f0fac9c8f2d6719731a6c7c1e (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
40
41
42
43
44
45
46
47
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.net;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * @author Simon Thoresen Hult
 */
public class UrlTokenTestCase {

    @Test
    public void requireThatAccessorsWork() {
        UrlToken token = new UrlToken(UrlToken.Type.FRAGMENT, 69, "foo", "bar");
        assertEquals(UrlToken.Type.FRAGMENT, token.getType());
        assertEquals(69, token.getOffset());
        assertEquals(3, token.getLength());
        assertEquals("foo", token.getOrig());
        assertEquals("bar", token.getTerm());
    }

    @Test
    public void requireThatTypeCanNotBeNull() {
        try {
            new UrlToken(null, 0, "foo", "bar");
            fail();
        } catch (NullPointerException e) {

        }
    }

    @Test
    public void requireThatOrigAndTermCanBeNull() {
        UrlToken token = new UrlToken(UrlToken.Type.SCHEME, 0, null, "foo");
        assertNull(token.getOrig());
        assertEquals("foo", token.getTerm());

        token = new UrlToken(UrlToken.Type.SCHEME, 0, "foo", null);
        assertEquals("foo", token.getOrig());
        assertNull(token.getTerm());

        token = new UrlToken(UrlToken.Type.SCHEME, 0, null, null);
        assertNull(token.getOrig());
        assertNull(token.getTerm());
    }
}