Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Hibernate, Relational Persistence for Idiomatic Java
   *
   * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
   * indicated by the @author tags or express copyright attribution
   * statements applied by the authors.  All third-party contributions are
   * distributed under license by Red Hat Inc.
   *
   * This copyrighted material is made available to anyone wishing to use, modify,
  * copy, or redistribute it subject to the terms and conditions of the GNU
  * Lesser General Public License, as published by the Free Software Foundation.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
  * for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
  * along with this distribution; if not, write to:
  * Free Software Foundation, Inc.
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
  */
 package org.hibernate.testing.junit4;
 
 import java.util.List;
 import java.util.Map;
 
 
Centralized utility functionality

Author(s):
Steve Ebersole
 
 public final class Helper {
 	public static final String VALIDATE_FAILURE_EXPECTED = "hibernate.test.validatefailureexpected";
 
 	private Helper() {
 	}

Standard string content checking.

Parameters:
string The string to check
Returns:
Are its content empty or the reference null?
 
 	public static boolean isNotEmpty(String string) {
 		return string != null && string.length() > 0;
 	}

Extract a nice test name representation for display

Parameters:
frameworkMethod The test method.
Returns:
The display representation
 
 	public static String extractTestName(FrameworkMethod frameworkMethod) {
 		return frameworkMethod.getMethod().getDeclaringClass().getName() + '#' + frameworkMethod.getName();
 	}

Extract a nice method name representation for display

Parameters:
method The method.
Returns:
The display representation
 
 	public static String extractMethodName(Method method) {
 		return method.getDeclaringClass().getName() + "#" + method.getName();
 	}
 
 	public static <T extends Annotation> T locateAnnotation(
 			Class<T> annotationClass,
 			FrameworkMethod frameworkMethod,
 			TestClass testClass) {
 		T annotation = frameworkMethod.getAnnotationannotationClass );
 		if ( annotation == null ) {
 			annotation = testClass.getJavaClass().getAnnotationannotationClass );
 		}
 		return annotation;
 	}

Parameters:
singularAnnotationClass Singular annotation class (e.g. org.hibernate.testing.SkipForDialect).
pluralAnnotationClass Plural annotation class (e.g. org.hibernate.testing.SkipForDialects). Assuming that the only declared method is an array of singular annotations.
frameworkMethod Test method.
testClass Test class.
<S> Singular annotation type.
<P> Plural annotation type.
Returns:
Collection of all singular annotations or an empty list.
	@SuppressWarnings("unchecked")
	public static <S extends Annotation, P extends AnnotationList<S> collectAnnotations(Class<S> singularAnnotationClass,
																						  Class<P> pluralAnnotationClass,
																						  FrameworkMethod frameworkMethod,
																						  TestClass testClass) {
		final List<S> collection = new LinkedList<S>();
		final S singularAnn = Helper.locateAnnotationsingularAnnotationClassframeworkMethodtestClass );
		if ( singularAnn != null ) {
			collection.addsingularAnn );
		}
		final P pluralAnn = Helper.locateAnnotationpluralAnnotationClassframeworkMethodtestClass );
		if ( pluralAnn != null ) {
			try {
				collection.addAll( Arrays.asList( (S[]) pluralAnnotationClass.getDeclaredMethods()[0].invoke(pluralAnn) ) );
			}
			catch ( Exception e ) {
				throw new RuntimeExceptione );
			}
		}
		return collection;
	}
	public static String extractMessage(FailureExpected failureExpected) {
		StringBuilder buffer = new StringBuilder();
		buffer.append'(' ).appendfailureExpected.jiraKey() ).append')' );
		if ( isNotEmptyfailureExpected.message() ) ) {
			buffer.append" : " ).appendfailureExpected.message() );
		}
		return buffer.toString();
	}
	public static String extractIgnoreMessage(FailureExpected failureExpectedFrameworkMethod frameworkMethod) {
		return new StringBuilder"Ignoring test [" )
				.append( Helper.extractTestNameframeworkMethod ) )
				.append"] due to @FailureExpected - " )
				.appendextractMessagefailureExpected ) )
	}

	public static void createH2Schema(String schemaNameConfiguration cfg) {
		createH2SchemaschemaNamecfg.getProperties() );
	}

Create additional H2 schema.

Parameters:
schemaName New schema name.
settings Current settings.
	public static void createH2Schema(String schemaNameMap settings) {
		settings.put(
				settings.get. ) + ";INIT=CREATE SCHEMA IF NOT EXISTS " + schemaName
		);
	}
New to GrepCode? Check out our FAQ X