Search in sources :

Example 1 with Executable

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);
}
Also used : Executable(org.junit.jupiter.api.function.Executable) AssertionFailedError(org.opentest4j.AssertionFailedError) AssertionTestUtils.expectAssertionFailedError(org.junit.jupiter.api.AssertionTestUtils.expectAssertionFailedError)

Example 2 with Executable

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);
}
Also used : Executable(org.junit.jupiter.api.function.Executable) AssertionFailedError(org.opentest4j.AssertionFailedError) AssertionTestUtils.expectAssertionFailedError(org.junit.jupiter.api.AssertionTestUtils.expectAssertionFailedError)

Example 3 with Executable

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);
    });
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Executable(org.junit.jupiter.api.function.Executable) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) ThrowableCollector(org.junit.jupiter.engine.execution.ThrowableCollector)

Example 4 with 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);
}
Also used : HashMap(java.util.HashMap) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 5 with 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}'.")));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Step(io.cucumber.core.gherkin.Step) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) DataTableType(io.cucumber.datatable.DataTableType) Located(io.cucumber.core.backend.Located) StepDefinition(io.cucumber.core.backend.StepDefinition) StepExpression(io.cucumber.core.stepexpression.StepExpression) Arrays.asList(java.util.Arrays.asList) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENGLISH(java.util.Locale.ENGLISH) EventBus(io.cucumber.core.eventbus.EventBus) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) StepExpressionFactory(io.cucumber.core.stepexpression.StepExpressionFactory) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) InvocationTargetException(java.lang.reflect.InvocationTargetException) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Test(org.junit.jupiter.api.Test) List(java.util.List) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Argument(io.cucumber.core.stepexpression.Argument) DocStringType(io.cucumber.docstring.DocStringType) Clock(java.time.Clock) Collections(java.util.Collections) CucumberException(io.cucumber.core.exception.CucumberException) ParameterType(io.cucumber.cucumberexpressions.ParameterType) Argument(io.cucumber.core.stepexpression.Argument) Step(io.cucumber.core.gherkin.Step) Feature(io.cucumber.core.gherkin.Feature) DocStringType(io.cucumber.docstring.DocStringType) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Aggregations

Executable (org.junit.jupiter.api.function.Executable)476 Test (org.junit.jupiter.api.Test)434 lombok.val (lombok.val)112 ByteBuf (io.netty.buffer.ByteBuf)83 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)42 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)36 CucumberException (io.cucumber.core.exception.CucumberException)20 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)19 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)15 Feature (io.cucumber.core.gherkin.Feature)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 StepDefinition (io.cucumber.core.backend.StepDefinition)14 Step (io.cucumber.core.gherkin.Step)14 Argument (io.cucumber.core.stepexpression.Argument)14 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 LocalChannel (io.netty.channel.local.LocalChannel)12 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)11 StepExpression (io.cucumber.core.stepexpression.StepExpression)11 SSLEngine (javax.net.ssl.SSLEngine)11 Bootstrap (io.netty.bootstrap.Bootstrap)10