summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/bukkit/support/Matchers.java
blob: b190c673697592e2a187c9b8329819aef71cc7c2 (plain)
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
package org.bukkit.support;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

public final class Matchers {

    private Matchers() {}

    public static <T> Matcher<T> sameHash(T value) {
        return new SameHash<T>(value);
    }

    static class SameHash<T> extends BaseMatcher<T> {
        private final int expected;

        SameHash(T object) {
            expected = object.hashCode();
        }

        public boolean matches(Object item) {
            return item.hashCode() == expected;
        }

        public void describeTo(Description description) {
            description.appendValue(expected);
        }
    }
}