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

org.hibernate.testing.hamcrest.InitializationCheckMatcher Maven / Gradle / Ivy

/*
 * SPDX-License-Identifier: LGPL-2.1-or-later
 * Copyright Red Hat Inc. and Hibernate Authors
 */
package org.hibernate.testing.hamcrest;

import org.hibernate.Hibernate;

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

/**
 * @author Steve Ebersole
 */
public class InitializationCheckMatcher extends BaseMatcher {
	public static final InitializationCheckMatcher INITIALIZED_MATCHER = new InitializationCheckMatcher();
	public static final InitializationCheckMatcher UNINITIALIZED_MATCHER = new InitializationCheckMatcher( false );

	public static  InitializationCheckMatcher isInitialized() {
		//noinspection unchecked
		return INITIALIZED_MATCHER;
	}

	public static  Matcher isNotInitialized() {
		//noinspection unchecked
		return UNINITIALIZED_MATCHER;
	}

	private final boolean assertInitialized;

	public InitializationCheckMatcher() {
		this( true );
	}

	public InitializationCheckMatcher(boolean assertInitialized) {
		this.assertInitialized = assertInitialized;
	}

	@Override
	public boolean matches(Object item) {
		return assertInitialized == Hibernate.isInitialized( item );
	}

	@Override
	public void describeTo(Description description) {
		description.appendValue( "Hibernate#isInitialized() returns " + assertInitialized );
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy