Search in sources :

Example 1 with MethodSelector

use of org.junit.platform.engine.discovery.MethodSelector in project junit5 by junit-team.

the class TestClassWithTemplate method methodResolution.

@Test
void methodResolution() throws NoSuchMethodException {
    Method test1 = MyTestClass.class.getDeclaredMethod("test1");
    MethodSelector selector = selectMethod(test1.getDeclaringClass(), test1);
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(2, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(MyTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test1()"));
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) MethodSelector(org.junit.platform.engine.discovery.MethodSelector) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) JupiterUniqueIdBuilder.uniqueIdForMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForMethod) Method(java.lang.reflect.Method) JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod) JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 2 with MethodSelector

use of org.junit.platform.engine.discovery.MethodSelector in project junit5 by junit-team.

the class TestClassWithTemplate method resolvingSelectorOfNonTestMethodResolvesNothing.

@Test
void resolvingSelectorOfNonTestMethodResolvesNothing() throws NoSuchMethodException {
    Method notATest = MyTestClass.class.getDeclaredMethod("notATest");
    MethodSelector selector = selectMethod(notATest.getDeclaringClass(), notATest);
    EngineDiscoveryRequest request = request().selectors(selector).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
}
Also used : MethodSelector(org.junit.platform.engine.discovery.MethodSelector) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) JupiterUniqueIdBuilder.uniqueIdForMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForMethod) Method(java.lang.reflect.Method) JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod) JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 3 with MethodSelector

use of org.junit.platform.engine.discovery.MethodSelector in project junit5 by junit-team.

the class DiscoveryRequestCreatorTests method convertsMethodSelectors.

@Test
void convertsMethodSelectors() {
    options.setSelectedMethods(asList("com.acme.Foo#m()", "com.example.Bar#method(java.lang.Object)"));
    LauncherDiscoveryRequest request = convert();
    List<MethodSelector> methodSelectors = request.getSelectorsByType(MethodSelector.class);
    assertThat(methodSelectors).hasSize(2);
    assertThat(methodSelectors.get(0).getClassName()).isEqualTo("com.acme.Foo");
    assertThat(methodSelectors.get(0).getMethodName()).isEqualTo("m");
    assertThat(methodSelectors.get(0).getMethodParameterTypes()).isEqualTo("");
    assertThat(methodSelectors.get(1).getClassName()).isEqualTo("com.example.Bar");
    assertThat(methodSelectors.get(1).getMethodName()).isEqualTo("method");
    assertThat(methodSelectors.get(1).getMethodParameterTypes()).isEqualTo("java.lang.Object");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) MethodSelector(org.junit.platform.engine.discovery.MethodSelector) Test(org.junit.jupiter.api.Test)

Example 4 with MethodSelector

use of org.junit.platform.engine.discovery.MethodSelector in project junit5 by junit-team.

the class TestClassWithTemplate method methodResolutionFromInheritedMethod.

@Test
void methodResolutionFromInheritedMethod() throws NoSuchMethodException {
    MethodSelector selector = selectMethod(HerTestClass.class, MyTestClass.class.getDeclaredMethod("test1"));
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(2, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(HerTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(HerTestClass.class, "test1()"));
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) MethodSelector(org.junit.platform.engine.discovery.MethodSelector) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 5 with MethodSelector

use of org.junit.platform.engine.discovery.MethodSelector in project junit5 by junit-team.

the class TestClassWithTemplate method methodResolutionInDoubleNestedTestClass.

@Test
void methodResolutionInDoubleNestedTestClass() throws NoSuchMethodException {
    MethodSelector selector = selectMethod(TestCaseWithNesting.NestedTestCase.DoubleNestedTestCase.class, TestCaseWithNesting.NestedTestCase.DoubleNestedTestCase.class.getDeclaredMethod("testC"));
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(4, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(TestCaseWithNesting.class));
    assertThat(uniqueIds).contains(uniqueIdForClass(TestCaseWithNesting.NestedTestCase.class));
    assertThat(uniqueIds).contains(uniqueIdForClass(TestCaseWithNesting.NestedTestCase.DoubleNestedTestCase.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(TestCaseWithNesting.NestedTestCase.DoubleNestedTestCase.class, "testC()"));
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) MethodSelector(org.junit.platform.engine.discovery.MethodSelector) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

Test (org.junit.jupiter.api.Test)5 MethodSelector (org.junit.platform.engine.discovery.MethodSelector)5 DynamicTest (org.junit.jupiter.api.DynamicTest)4 UniqueId (org.junit.platform.engine.UniqueId)3 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)3 Method (java.lang.reflect.Method)2 JupiterUniqueIdBuilder.uniqueIdForMethod (org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForMethod)2 JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod (org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod)2 JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod (org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod)2 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)1 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)1