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

org.marvelution.test.Matchers Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2012-present Marvelution B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.marvelution.test;

import org.marvelution.jira.plugins.jenkins.model.ErrorMessages;

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

/**
 * Common project specific Matchers
 *
 * @author Mark Rekveld
 * @since 1.6.0
 */
public class Matchers {

	/**
	 * Returns a {@link Matcher} to match is an {@link ErrorMessages.ErrorMessage} if for the specified {@code field}
	 */
	public static Matcher errorForField(final String field) {
		return new BaseMatcher() {
			@Override
			public boolean matches(Object item) {
				if (item == null) {
					return false;
				} else if (!(item instanceof ErrorMessages.ErrorMessage)) {
					return false;
				}
				ErrorMessages.ErrorMessage error = (ErrorMessages.ErrorMessage) item;
				return field.equals(error.field);
			}

			@Override
			public void describeTo(Description description) {
				description.appendText("error for field ").appendValue(field);
			}
		};
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy