mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[build scripts] support Bombed annotation for junit 5 run
GitOrigin-RevId: 0d28f2028f389519742b62b7034f6876dbf6156b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
429834fdb8
commit
9e24cc369f
@@ -13,5 +13,6 @@
|
||||
<orderEntry type="module" module-name="intellij.tools.testsBootstrap" />
|
||||
<orderEntry type="library" name="JUnit4" level="project" />
|
||||
<orderEntry type="library" name="Log4J" level="project" />
|
||||
<orderEntry type="library" name="JUnit5" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.idea;
|
||||
|
||||
import com.intellij.idea.extensions.BombExplodedExtension;
|
||||
import org.intellij.lang.annotations.JdkConstants;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -12,6 +12,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
@ExtendWith(BombExplodedExtension.class)
|
||||
public @interface Bombed {
|
||||
int year();
|
||||
@JdkConstants.CalendarMonth int month();
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.idea.extensions;
|
||||
|
||||
import com.intellij.idea.Bombed;
|
||||
import com.intellij.testFramework.TestFrameworkUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
import org.junit.platform.commons.support.AnnotationSupport;
|
||||
|
||||
public class BombExplodedExtension implements BeforeEachCallback, BeforeAllCallback, ExecutionCondition {
|
||||
@Override
|
||||
public void beforeEach(ExtensionContext context) {
|
||||
explodeBomb(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeAll(ExtensionContext context) {
|
||||
explodeBomb(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
||||
return AnnotationSupport.findAnnotation(context.getElement(), Bombed.class)
|
||||
.map(bombed -> TestFrameworkUtil.bombExplodes(bombed)
|
||||
? ConditionEvaluationResult.enabled("Bomb exploded")
|
||||
: ConditionEvaluationResult.disabled("Bomb not yet exploded"))
|
||||
.orElse(ConditionEvaluationResult.enabled("No bomb defined"));
|
||||
}
|
||||
|
||||
private static void explodeBomb(ExtensionContext context) {
|
||||
AnnotationSupport.findAnnotation(context.getElement(), Bombed.class)
|
||||
.ifPresent(bombed -> {
|
||||
if (TestFrameworkUtil.bombExplodes(bombed)) {
|
||||
String description = bombed.description().isEmpty() ? "" : " (" + bombed.description() + ")";
|
||||
Assertions.fail("Bomb created by " + bombed.user() + description + " now explodes");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user