aboutsummaryrefslogtreecommitdiffstats
path: root/yolean/src/test/java/com/yahoo/yolean/chain/ChainTest.java
blob: af4b3ff4b8335550483bc5c163a3753c0ed09549 (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
48
49
50
51
52
53
54
55
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.yolean.chain;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;

/**
 * @author tonytv
 */
public class ChainTest {

    public static class Filter {

    }

    public static class OtherFilter extends Filter {

    }

    @Test
    public void empty_chain_toString() {
        Chain<Filter> c = new Chain<>("myChain");
        assertThat(c.toString(), is("chain 'myChain'{}"));
    }

    @Test
    public void singleton_chain_toString() {
        Chain<Filter> c = new Chain<>("myChain", new Filter());
        assertThat(c.toString(), is("chain 'myChain'{ Filter }"));
    }

    @Test
    public void chain_toString() {
        Chain<Filter> c = new Chain<>("myChain", new Filter(), new Filter(), new OtherFilter());
        assertThat(c.toString(), is("chain 'myChain'{ Filter -> Filter -> OtherFilter }"));
    }

    @Test
    public void non_equal_due_to_different_components() {
        assertThat(new Chain<>("a", new Filter()), is(not(new Chain<>("a", new Filter()))));
    }

    @Test
    public void non_equal_due_to_different_size_comopnents() {
        assertThat(new Chain<>("a", new Filter()), is(not(new Chain<Filter>("a"))));
    }

    @Test
    public void hashCode_equals() {
        assertThat(new Chain<>("a").hashCode(), is(new Chain<Filter>("a").hashCode()));
    }
}