use of org.junit.jupiter.api.function.Executable in project junit5 by junit-team.
the class AssertEqualsAssertionsTests method assertEqualsFloatWithDeltaWithUnequalValuesAndMessageSupplier.
@Test
void assertEqualsFloatWithDeltaWithUnequalValuesAndMessageSupplier() {
Executable assertion = () -> assertEquals(0.5f, 0.45f, 0.03f, () -> "message");
AssertionFailedError e = assertThrows(AssertionFailedError.class, assertion);
assertMessageStartsWith(e, "message");
assertMessageEndsWith(e, "expected: <0.5> but was: <0.45>");
assertExpectedAndActualValues(e, 0.5f, 0.45f);
}
use of org.junit.jupiter.api.function.Executable in project junit5 by junit-team.
the class AssertEqualsAssertionsTests method assertEqualsFloatWithDeltaWithUnequalValuesAndMessage.
@Test
void assertEqualsFloatWithDeltaWithUnequalValuesAndMessage() {
Executable assertion = () -> assertEquals(0.5f, 0.45f, 0.03f, "message");
AssertionFailedError e = assertThrows(AssertionFailedError.class, assertion);
assertMessageStartsWith(e, "message");
assertMessageEndsWith(e, "expected: <0.5> but was: <0.45>");
assertExpectedAndActualValues(e, 0.5f, 0.45f);
}
use of org.junit.jupiter.api.function.Executable in project junit5 by junit-team.
the class TestMethodTestDescriptor method invokeAllAfterMethodsOrCallbacks.
private <T extends Extension> void invokeAllAfterMethodsOrCallbacks(JupiterEngineExecutionContext context, BiFunction<ExtensionContext, T, Executable> generator, Class<T> type) {
ExtensionRegistry registry = context.getExtensionRegistry();
ExtensionContext extensionContext = context.getExtensionContext();
ThrowableCollector throwableCollector = context.getThrowableCollector();
registry.getReversedExtensions(type).forEach(callback -> {
Executable executable = generator.apply(extensionContext, callback);
throwableCollector.execute(executable);
});
}
use of org.junit.jupiter.api.function.Executable in project tutorials by eugenp.
the class ExceptionUnitTest method whenModifyMapDuringIteration_thenThrowExecption.
@Test
public void whenModifyMapDuringIteration_thenThrowExecption() {
Map<Integer, String> hashmap = new HashMap<>();
hashmap.put(1, "One");
hashmap.put(2, "Two");
Executable executable = () -> hashmap.forEach((key, value) -> hashmap.remove(1));
assertThrows(ConcurrentModificationException.class, executable);
}
use of org.junit.jupiter.api.function.Executable in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_docstring.
@Test
void throws_could_not_convert_exception_for_docstring() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some cukes in my belly\n" + " \"\"\"doc\n" + " converting this should throw an exception\n" + " \"\"\"\n");
stepTypeRegistry.defineDocStringType(new DocStringType(ItemQuantity.class, "doc", content -> {
throw new IllegalArgumentException(content);
}));
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have some cukes in my belly", ItemQuantity.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat(actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have some cukes in my belly] defined at '{stubbed location with details}'.")));
}
Aggregations