|
Hibernate example source code file (CustomRunner.java)
The Hibernate CustomRunner.java source code/* * 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.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; import org.jboss.logging.Logger; import org.hibernate.dialect.Dialect; import org.hibernate.internal.util.StringHelper; import org.hibernate.testing.DialectCheck; import org.hibernate.testing.FailureExpected; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.Skip; import org.hibernate.testing.SkipForDialect; import org.junit.Ignore; import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import org.junit.runners.model.Statement; /** * The Hibernate-specific {@link org.junit.runner.Runner} implementation which layers {@link ExtendedFrameworkMethod} * support on top of the standard JUnit {@link FrameworkMethod} for extra information after checking to make sure the * test should be run. * * @author Steve Ebersole */ public class CustomRunner extends BlockJUnit4ClassRunner { private static final Logger log = Logger.getLogger( CustomRunner.class ); private TestClassMetadata testClassMetadata; public CustomRunner(Class<?> clazz) throws InitializationError, NoTestsRemainException { super( clazz ); } @Override protected void collectInitializationErrors(List<Throwable> errors) { super.collectInitializationErrors( errors ); this.testClassMetadata = new TestClassMetadata( getTestClass().getJavaClass() ); testClassMetadata.validate( errors ); } public TestClassMetadata getTestClassMetadata() { return testClassMetadata; } @Override protected Statement withBeforeClasses(Statement statement) { return new BeforeClassCallbackHandler( this, super.withBeforeClasses( statement ) ); } @Override protected Statement withAfterClasses(Statement statement) { return new AfterClassCallbackHandler( this, super.withAfterClasses( statement ) ); } @Override protected Statement methodBlock(FrameworkMethod method) { final Statement originalMethodBlock = super.methodBlock( method ); final ExtendedFrameworkMethod extendedFrameworkMethod = (ExtendedFrameworkMethod) method; return new FailureExpectedHandler( originalMethodBlock, testClassMetadata, extendedFrameworkMethod, testInstance ); } private Object testInstance; protected Object getTestInstance() throws Exception { if ( testInstance == null ) { testInstance = super.createTest(); } return testInstance; } @Override protected Object createTest() throws Exception { return getTestInstance(); } private List<FrameworkMethod> computedTestMethods; @Override protected List<FrameworkMethod> computeTestMethods() { if ( computedTestMethods == null ) { computedTestMethods = doComputation(); } return computedTestMethods; } protected List<FrameworkMethod> doComputation() { // Next, get all the test methods as understood by JUnit final List<FrameworkMethod> methods = super.computeTestMethods(); // Now process that full list of test methods and build our custom result final List<FrameworkMethod> result = new ArrayList Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate CustomRunner.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.