All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.test.ByteSizeEqualsMatcher Maven / Gradle / Ivy

There is a newer version: 8.15.1
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the "Elastic License
 * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
 * Public License v 1"; you may not use this file except in compliance with, at
 * your election, the "Elastic License 2.0", the "GNU Affero General Public
 * License v3.0 only", or the "Server Side Public License, v 1".
 */

package org.elasticsearch.test;

import org.elasticsearch.common.unit.ByteSizeValue;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;

/**
 * Equality matcher for {@link ByteSizeValue} that has a nice description of failures.
 */
public class ByteSizeEqualsMatcher extends TypeSafeMatcher {
    public static ByteSizeEqualsMatcher byteSizeEquals(ByteSizeValue expected) {
        return new ByteSizeEqualsMatcher(expected);
    }

    private final ByteSizeValue expected;

    private ByteSizeEqualsMatcher(ByteSizeValue expected) {
        this.expected = expected;
    }

    @Override
    protected boolean matchesSafely(ByteSizeValue byteSizeValue) {
        return expected.equals(byteSizeValue);
    }

    @Override
    public void describeTo(Description description) {
        description.appendValue(expected.toString()).appendText(" (").appendValue(expected.getBytes()).appendText(" bytes)");
    }

    @Override
    protected void describeMismatchSafely(ByteSizeValue item, Description mismatchDescription) {
        mismatchDescription.appendValue(item.toString()).appendText(" (").appendValue(item.getBytes()).appendText(" bytes)");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy