Upgrade to JUnit Jupiter 5.0 M5

Issue: SPR-15728
This commit is contained in:
Sam Brannen
2017-07-04 14:47:10 +02:00
parent 9c93521512
commit 75a71accea
6 changed files with 101 additions and 100 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -20,10 +20,11 @@ import java.lang.reflect.Method;
import java.util.Optional;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.junit.jupiter.api.extension.TestExtensionContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.TestContextManager;
@@ -52,7 +53,7 @@ class DisabledIfConditionTestCase {
@Test
void missingDisabledIf() {
assertResult(condition.evaluate(buildExtensionContext("missingDisabledIf")), false,
assertResult(condition.evaluateExecutionCondition(buildExtensionContext("missingDisabledIf")), false,
endsWith("missingDisabledIf() is enabled since @DisabledIf is not present"));
}
@@ -70,7 +71,7 @@ class DisabledIfConditionTestCase {
void invalidExpressionEvaluationType() {
String methodName = "nonBooleanOrStringExpression";
IllegalStateException exception = assertThrows(IllegalStateException.class,
() -> condition.evaluate(buildExtensionContext(methodName)));
() -> condition.evaluateExecutionCondition(buildExtensionContext(methodName)));
Method method = ReflectionUtils.findMethod(getClass(), methodName);
@@ -82,7 +83,7 @@ class DisabledIfConditionTestCase {
void unsupportedStringEvaluationValue() {
String methodName = "stringExpressionThatIsNeitherTrueNorFalse";
IllegalStateException exception = assertThrows(IllegalStateException.class,
() -> condition.evaluate(buildExtensionContext(methodName)));
() -> condition.evaluateExecutionCondition(buildExtensionContext(methodName)));
Method method = ReflectionUtils.findMethod(getClass(), methodName);
@@ -92,30 +93,30 @@ class DisabledIfConditionTestCase {
@Test
void disabledWithCustomReason() {
assertResult(condition.evaluate(buildExtensionContext("customReason")), true, is(equalTo("Because... 42!")));
assertResult(condition.evaluateExecutionCondition(buildExtensionContext("customReason")), true, is(equalTo("Because... 42!")));
}
@Test
void disabledWithDefaultReason() {
assertResult(condition.evaluate(buildExtensionContext("defaultReason")), true,
assertResult(condition.evaluateExecutionCondition(buildExtensionContext("defaultReason")), true,
endsWith("defaultReason() is disabled because @DisabledIf(\"#{1 + 1 eq 2}\") evaluated to true"));
}
@Test
void notDisabledWithDefaultReason() {
assertResult(condition.evaluate(buildExtensionContext("neverDisabledWithDefaultReason")), false, endsWith(
assertResult(condition.evaluateExecutionCondition(buildExtensionContext("neverDisabledWithDefaultReason")), false, endsWith(
"neverDisabledWithDefaultReason() is enabled because @DisabledIf(\"false\") did not evaluate to true"));
}
// -------------------------------------------------------------------------
private TestExtensionContext buildExtensionContext(String methodName) {
private ExtensionContext buildExtensionContext(String methodName) {
Class<?> testClass = SpringTestCase.class;
Method method = ReflectionUtils.findMethod(getClass(), methodName);
Store store = mock(Store.class);
when(store.getOrComputeIfAbsent(any(), any(), any())).thenReturn(new TestContextManager(testClass));
TestExtensionContext extensionContext = mock(TestExtensionContext.class);
ExtensionContext extensionContext = mock(ExtensionContext.class);
when(extensionContext.getTestClass()).thenReturn(Optional.of(testClass));
when(extensionContext.getElement()).thenReturn(Optional.of(method));
when(extensionContext.getStore(any())).thenReturn(store);
@@ -124,7 +125,7 @@ class DisabledIfConditionTestCase {
private void assertExpressionIsBlank(String methodName) {
IllegalStateException exception = assertThrows(IllegalStateException.class,
() -> condition.evaluate(buildExtensionContext(methodName)));
() -> condition.evaluateExecutionCondition(buildExtensionContext(methodName)));
assertThat(exception.getMessage(), containsString("must not be blank"));
}