summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/matchers/NodeEventWithDescription.java
blob: 00f043695daf29871cdccf9325a5fb201a0132d5 (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 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core.matchers;

import com.yahoo.vespa.clustercontroller.core.NodeEvent;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.mockito.ArgumentMatcher;

public class NodeEventWithDescription extends ArgumentMatcher<NodeEvent> {
    private final String expected;

    private NodeEventWithDescription(String expected) {
        this.expected = expected;
    }

    @Override
    public boolean matches(Object o) {
        if (!(o instanceof NodeEvent)) {
            return false;
        }
        return expected.equals(((NodeEvent) o).getDescription());
    }

    @Override
    public void describeTo(Description description) {
        description.appendText(String.format("NodeEvent with description '%s'", expected));
    }

    @Override
    public void describeMismatch(Object item, Description description) {
        NodeEvent other = (NodeEvent)item;
        description.appendText(String.format("got description '%s'", other.getDescription()));
    }

    @Factory
    public static NodeEventWithDescription nodeEventWithDescription(String description) {
        return new NodeEventWithDescription(description);
    }
}