Search in sources :

Example 1 with NullIntegerParameterResolver

use of org.junit.jupiter.engine.execution.injection.sample.NullIntegerParameterResolver in project junit5 by junit-team.

the class ParameterResolverTests method executeTestsForNullValuedMethodInjectionCases.

@Test
void executeTestsForNullValuedMethodInjectionCases() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(NullMethodInjectionTestCase.class);
    assertEquals(2, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    Predicate<String> expectations = s -> s.contains("NullIntegerParameterResolver") && s.contains("resolved a null value for parameter") && s.contains("but a primitive of type [int] is required");
    assertRecordedExecutionEventsContainsExactly(eventRecorder.getFailedTestFinishedEvents(), event(test("injectPrimitive"), finishedWithFailure(allOf(isA(ParameterResolutionException.class), message(expectations)))));
// @formatter:on
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) BeforeEach(org.junit.jupiter.api.BeforeEach) CustomTypeParameterResolver(org.junit.jupiter.engine.execution.injection.sample.CustomTypeParameterResolver) ExecutionEventConditions.assertRecordedExecutionEventsContainsExactly(org.junit.platform.engine.test.event.ExecutionEventConditions.assertRecordedExecutionEventsContainsExactly) Assertions.allOf(org.assertj.core.api.Assertions.allOf) ExecutionEventConditions.test(org.junit.platform.engine.test.event.ExecutionEventConditions.test) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CustomType(org.junit.jupiter.engine.execution.injection.sample.CustomType) NumberParameterResolver(org.junit.jupiter.engine.execution.injection.sample.NumberParameterResolver) Disabled(org.junit.jupiter.api.Disabled) TestExecutionResultConditions.isA(org.junit.platform.engine.test.event.TestExecutionResultConditions.isA) Nested(org.junit.jupiter.api.Nested) JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CustomAnnotationParameterResolver(org.junit.jupiter.engine.execution.injection.sample.CustomAnnotationParameterResolver) BeforeAll(org.junit.jupiter.api.BeforeAll) AbstractJupiterTestEngineTests(org.junit.jupiter.engine.AbstractJupiterTestEngineTests) PrimitiveArrayParameterResolver(org.junit.jupiter.engine.execution.injection.sample.PrimitiveArrayParameterResolver) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JAVA_8(org.junit.jupiter.api.condition.JRE.JAVA_8) DisabledOnJre(org.junit.jupiter.api.condition.DisabledOnJre) Method(java.lang.reflect.Method) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) ExecutionEventConditions.event(org.junit.platform.engine.test.event.ExecutionEventConditions.event) MapOfStringsParameterResolver(org.junit.jupiter.engine.execution.injection.sample.MapOfStringsParameterResolver) Predicate(java.util.function.Predicate) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) ExecutionEventConditions.finishedWithFailure(org.junit.platform.engine.test.event.ExecutionEventConditions.finishedWithFailure) PrimitiveIntegerParameterResolver(org.junit.jupiter.engine.execution.injection.sample.PrimitiveIntegerParameterResolver) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) TestExecutionResultConditions.message(org.junit.platform.engine.test.event.TestExecutionResultConditions.message) TestInfo(org.junit.jupiter.api.TestInfo) NullIntegerParameterResolver(org.junit.jupiter.engine.execution.injection.sample.NullIntegerParameterResolver) DisplayName(org.junit.jupiter.api.DisplayName) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CustomAnnotation(org.junit.jupiter.engine.execution.injection.sample.CustomAnnotation) ParameterResolver(org.junit.jupiter.api.extension.ParameterResolver) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Aggregations

Method (java.lang.reflect.Method)1 Map (java.util.Map)1 Predicate (java.util.function.Predicate)1 Assertions.allOf (org.assertj.core.api.Assertions.allOf)1 AfterAll (org.junit.jupiter.api.AfterAll)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Disabled (org.junit.jupiter.api.Disabled)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Nested (org.junit.jupiter.api.Nested)1 Test (org.junit.jupiter.api.Test)1 TestInfo (org.junit.jupiter.api.TestInfo)1 DisabledOnJre (org.junit.jupiter.api.condition.DisabledOnJre)1 JAVA_8 (org.junit.jupiter.api.condition.JRE.JAVA_8)1