aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/matchers/NodeEventForBucketSpace.java
blob: 9951bf50f5c6f92cabd3ef09df6478f1cd6b1e91 (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
// Copyright Yahoo. 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.BaseMatcher;
import org.hamcrest.Description;

import java.util.Optional;

public class NodeEventForBucketSpace extends BaseMatcher<NodeEvent> {
    private final Optional<String> bucketSpace;

    private NodeEventForBucketSpace(Optional<String> bucketSpace) {
        this.bucketSpace = bucketSpace;
    }

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

    @Override
    public void describeTo(Description description) {
        description.appendText(String.format("NodeEvent for bucket space '%s'", bucketSpace.orElse("null")));
    }

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

    public static NodeEventForBucketSpace nodeEventForBucketSpace(String bucketSpace) {
        return new NodeEventForBucketSpace(Optional.of(bucketSpace));
    }

    public static NodeEventForBucketSpace nodeEventForBaseline() {
        return new NodeEventForBucketSpace(Optional.empty());
    }
}