Extract runningInEclipse() into IdeUtils test fixture
This commit is contained in:
parent
b0d08fe2d4
commit
4b5e96578d
|
@ -38,6 +38,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
|
||||
import org.springframework.core.testfixture.ide.IdeUtils;
|
||||
import org.springframework.core.testfixture.stereotype.Component;
|
||||
import org.springframework.lang.NonNullApi;
|
||||
|
||||
|
@ -159,17 +160,15 @@ class AnnotationUtilsTests {
|
|||
assertThat(getAnnotation(bridgeMethod, Order.class)).isNull();
|
||||
assertThat(findAnnotation(bridgeMethod, Order.class)).isNotNull();
|
||||
|
||||
boolean runningInEclipse = StackWalker.getInstance().walk(stream ->
|
||||
stream.anyMatch(stackFrame -> stackFrame.getClassName().startsWith("org.eclipse.jdt")));
|
||||
// As of JDK 8, invoking getAnnotation() on a bridge method actually finds an
|
||||
// annotation on its 'bridged' method [1]; however, the Eclipse compiler will not
|
||||
// support this until Eclipse 4.9 [2]. Thus, we effectively ignore the following
|
||||
// annotation on its 'bridged' method [1]; however, the Eclipse compiler does
|
||||
// not support this [2]. Thus, we effectively ignore the following
|
||||
// assertion if the test is currently executing within the Eclipse IDE.
|
||||
//
|
||||
// [1] https://bugs.openjdk.java.net/browse/JDK-6695379
|
||||
// [2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=495396
|
||||
//
|
||||
if (!runningInEclipse) {
|
||||
if (!IdeUtils.runningInEclipse()) {
|
||||
assertThat(bridgeMethod.getAnnotation(Transactional.class)).isNotNull();
|
||||
}
|
||||
assertThat(getAnnotation(bridgeMethod, Transactional.class)).isNotNull();
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.springframework.core.annotation.MergedAnnotation.Adapt;
|
|||
import org.springframework.core.annotation.MergedAnnotations.Search;
|
||||
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
|
||||
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
|
||||
import org.springframework.core.testfixture.ide.IdeUtils;
|
||||
import org.springframework.core.testfixture.stereotype.Component;
|
||||
import org.springframework.core.testfixture.stereotype.Indexed;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
@ -891,15 +892,15 @@ class MergedAnnotationsTests {
|
|||
assertThat(MergedAnnotations.from(method).get(Order.class).getDistance()).isEqualTo(-1);
|
||||
assertThat(MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY).get(
|
||||
Order.class).getDistance()).isEqualTo(0);
|
||||
boolean runningInEclipse = StackWalker.getInstance().walk(stream ->
|
||||
stream.anyMatch(stackFrame -> stackFrame.getClassName().startsWith("org.eclipse.jdt")));
|
||||
// As of JDK 8, invoking getAnnotation() on a bridge method actually finds an
|
||||
// annotation on its 'bridged' method [1]; however, the Eclipse compiler
|
||||
// does not support this [2]. Thus, we effectively ignore the following
|
||||
// annotation on its 'bridged' method [1]; however, the Eclipse compiler does
|
||||
// not support this [2]. Thus, we effectively ignore the following
|
||||
// assertion if the test is currently executing within the Eclipse IDE.
|
||||
//
|
||||
// [1] https://bugs.openjdk.java.net/browse/JDK-6695379
|
||||
// [2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=495396
|
||||
if (!runningInEclipse) {
|
||||
//
|
||||
if (!IdeUtils.runningInEclipse()) {
|
||||
assertThat(method.getAnnotation(Transactional.class)).isNotNull();
|
||||
}
|
||||
assertThat(MergedAnnotations.from(method).get(
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.springframework.core.testfixture.ide;
|
||||
|
||||
/**
|
||||
* Test utilities related to IDEs.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
*/
|
||||
public class IdeUtils {
|
||||
|
||||
/**
|
||||
* Determine if the current code is running in the Eclipse IDE.
|
||||
*/
|
||||
public static boolean runningInEclipse() {
|
||||
return StackWalker.getInstance().walk(stream -> stream.anyMatch(
|
||||
stackFrame -> stackFrame.getClassName().startsWith("org.eclipse.jdt")));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue