|
| 1 | +/* |
| 2 | + * Copyright 2015-2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.jpa.util; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.extension.ConditionEvaluationResult; |
| 19 | +import org.junit.jupiter.api.extension.ExecutionCondition; |
| 20 | +import org.junit.jupiter.api.extension.ExtensionContext; |
| 21 | +import org.springframework.util.ClassUtils; |
| 22 | + |
| 23 | +/** |
| 24 | + * JUnit 5 utilities to support conditional test cases based upon Hibernate classpath settings. |
| 25 | + * |
| 26 | + * @author Greg Turnquist |
| 27 | + * @since 3.1 |
| 28 | + */ |
| 29 | +abstract class HibernateSupport { |
| 30 | + |
| 31 | + /** |
| 32 | + * {@literal org.hibernate.dialect.PostgreSQL91Dialect} is deprecated in Hibernate 6.1 and fully removed in Hibernate |
| 33 | + * 6.2, making it a perfect detector between the two. |
| 34 | + */ |
| 35 | + private static final boolean HIBERNATE_61_ON_CLASSPATH = ClassUtils |
| 36 | + .isPresent("org.hibernate.dialect.PostgreSQL91Dialect", HibernateSupport.class.getClassLoader()); |
| 37 | + |
| 38 | + private static final boolean HIBERNATE_62_ON_CLASSPATH = !HIBERNATE_61_ON_CLASSPATH; |
| 39 | + |
| 40 | + static class DisabledWhenHibernate61OnClasspath implements ExecutionCondition { |
| 41 | + |
| 42 | + @Override |
| 43 | + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) { |
| 44 | + |
| 45 | + return HibernateSupport.HIBERNATE_61_ON_CLASSPATH |
| 46 | + ? ConditionEvaluationResult.disabled("Disabled because Hibernate 6.1 is on the classpath") |
| 47 | + : ConditionEvaluationResult.enabled("NOT disabled because Hibernate 6.2 is on the classpath"); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + static class DisabledWhenHibernate62OnClasspath implements ExecutionCondition { |
| 52 | + |
| 53 | + @Override |
| 54 | + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) { |
| 55 | + |
| 56 | + return HibernateSupport.HIBERNATE_62_ON_CLASSPATH |
| 57 | + ? ConditionEvaluationResult.disabled("Disabled because Hibernate 6.2 is on the classpath") |
| 58 | + : ConditionEvaluationResult.enabled("NOT disabled because Hibernate 6.1 is on the classpath"); |
| 59 | + } |
| 60 | + |
| 61 | + } |
| 62 | +} |
0 commit comments