"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptorTests.java" between
junit5-r5.3.2.tar.gz and junit5-r5.4.0.tar.gz

About: JUnit 5 is a unit testing framework for the Java programming language.

JupiterTestDescriptorTests.java  (junit5-r5.3.2):JupiterTestDescriptorTests.java  (junit5-r5.4.0)
/* /*
* Copyright 2015-2018 the original author or authors. * Copyright 2015-2019 the original author or authors.
* *
* All rights reserved. This program and the accompanying materials are * All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which * made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at * accompanies this distribution and is available at
* *
* http://www.eclipse.org/legal/epl-v20.html * http://www.eclipse.org/legal/epl-v20.html
*/ */
package org.junit.jupiter.engine.descriptor; package org.junit.jupiter.engine.descriptor;
skipping to change at line 35 skipping to change at line 35
import java.util.Optional; import java.util.Optional;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.engine.config.JupiterConfiguration;
import org.junit.jupiter.engine.descriptor.JupiterTestDescriptorTests.StaticTest Case.StaticTestCaseLevel2; import org.junit.jupiter.engine.descriptor.JupiterTestDescriptorTests.StaticTest Case.StaticTestCaseLevel2;
import org.junit.platform.engine.ConfigurationParameters;
import org.junit.platform.engine.TestSource; import org.junit.platform.engine.TestSource;
import org.junit.platform.engine.TestTag; import org.junit.platform.engine.TestTag;
import org.junit.platform.engine.UniqueId; import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.MethodSource; import org.junit.platform.engine.support.descriptor.MethodSource;
/** /**
* Unit tests for {@link ClassTestDescriptor}, {@link NestedClassTestDescriptor} , * Unit tests for {@link ClassTestDescriptor}, {@link NestedClassTestDescriptor} ,
* and {@link TestMethodTestDescriptor}. * and {@link TestMethodTestDescriptor}.
* *
* @since 5.0 * @since 5.0
* @see org.junit.jupiter.engine.descriptor.LifecycleMethodUtilsTests * @see org.junit.jupiter.engine.descriptor.LifecycleMethodUtilsTests
* @see org.junit.jupiter.engine.InvalidLifecycleMethodConfigurationTests
*/ */
class JupiterTestDescriptorTests { class JupiterTestDescriptorTests {
private static final UniqueId uniqueId = UniqueId.root("enigma", "foo"); private static final UniqueId uniqueId = UniqueId.root("enigma", "foo");
private final ConfigurationParameters configParams = mock(ConfigurationPa rameters.class); private final JupiterConfiguration configuration = mock(JupiterConfigurat ion.class);
@Test @Test
void constructFromClass() { void constructFromClass() {
ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCase.class, configParams); ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCase.class, configuration);
assertEquals(TestCase.class, descriptor.getTestClass()); assertEquals(TestCase.class, descriptor.getTestClass());
assertThat(descriptor.getTags()).containsExactly(TestTag.create(" inherited-class-level-tag"), assertThat(descriptor.getTags()).containsExactly(TestTag.create(" inherited-class-level-tag"),
TestTag.create("classTag1"), TestTag.create("classTag2")) ; TestTag.create("classTag1"), TestTag.create("classTag2")) ;
} }
@Test @Test
void constructFromClassWithInvalidBeforeAllDeclaration() { void constructFromClassWithInvalidBeforeAllDeclaration() {
// Note: if we can instantiate the descriptor, then the invalid c onfiguration // Note: if we can instantiate the descriptor, then the invalid c onfiguration
// will not be reported during the test engine discovery phase. // will not be reported during the test engine discovery phase.
ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCaseWithInvalidBeforeAllMethod.class, ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCaseWithInvalidBeforeAllMethod.class,
configParams); configuration);
assertEquals(TestCaseWithInvalidBeforeAllMethod.class, descriptor .getTestClass()); assertEquals(TestCaseWithInvalidBeforeAllMethod.class, descriptor .getTestClass());
} }
@Test @Test
void constructFromClassWithInvalidAfterAllDeclaration() { void constructFromClassWithInvalidAfterAllDeclaration() {
// Note: if we can instantiate the descriptor, then the invalid c onfiguration // Note: if we can instantiate the descriptor, then the invalid c onfiguration
// will not be reported during the test engine discovery phase. // will not be reported during the test engine discovery phase.
ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCaseWithInvalidAfterAllMethod.class, ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCaseWithInvalidAfterAllMethod.class,
configParams); configuration);
assertEquals(TestCaseWithInvalidAfterAllMethod.class, descriptor. getTestClass()); assertEquals(TestCaseWithInvalidAfterAllMethod.class, descriptor. getTestClass());
} }
@Test @Test
void constructFromClassWithInvalidBeforeEachDeclaration() { void constructFromClassWithInvalidBeforeEachDeclaration() {
// Note: if we can instantiate the descriptor, then the invalid c onfiguration // Note: if we can instantiate the descriptor, then the invalid c onfiguration
// will not be reported during the test engine discovery phase. // will not be reported during the test engine discovery phase.
ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCaseWithInvalidBeforeEachMethod.class, ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCaseWithInvalidBeforeEachMethod.class,
configParams); configuration);
assertEquals(TestCaseWithInvalidBeforeEachMethod.class, descripto r.getTestClass()); assertEquals(TestCaseWithInvalidBeforeEachMethod.class, descripto r.getTestClass());
} }
@Test @Test
void constructFromClassWithInvalidAfterEachDeclaration() { void constructFromClassWithInvalidAfterEachDeclaration() {
// Note: if we can instantiate the descriptor, then the invalid c onfiguration // Note: if we can instantiate the descriptor, then the invalid c onfiguration
// will not be reported during the test engine discovery phase. // will not be reported during the test engine discovery phase.
ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCaseWithInvalidAfterEachMethod.class, ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , TestCaseWithInvalidAfterEachMethod.class,
configParams); configuration);
assertEquals(TestCaseWithInvalidAfterEachMethod.class, descriptor .getTestClass()); assertEquals(TestCaseWithInvalidAfterEachMethod.class, descriptor .getTestClass());
} }
@Test @Test
void constructFromMethod() throws Exception { void constructFromMethod() throws Exception {
Class<?> testClass = TestCase.class; Class<?> testClass = TestCase.class;
Method testMethod = testClass.getDeclaredMethod("test"); Method testMethod = testClass.getDeclaredMethod("test");
TestMethodTestDescriptor descriptor = new TestMethodTestDescripto TestMethodTestDescriptor descriptor = new TestMethodTestDescripto
r(uniqueId, testClass, testMethod); r(uniqueId, testClass, testMethod,
configuration);
assertEquals(uniqueId, descriptor.getUniqueId()); assertEquals(uniqueId, descriptor.getUniqueId());
assertEquals(testMethod, descriptor.getTestMethod()); assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("test()", descriptor.getDisplayName(), "display name :"); assertEquals("test()", descriptor.getDisplayName(), "display name :");
assertEquals("test()", descriptor.getLegacyReportingName(), "lega cy name:");
} }
@Test @Test
void constructFromMethodWithAnnotations() throws Exception { void constructFromMethodWithAnnotations() throws Exception {
JupiterTestDescriptor classDescriptor = new ClassTestDescriptor(u niqueId, TestCase.class, configParams); JupiterTestDescriptor classDescriptor = new ClassTestDescriptor(u niqueId, TestCase.class, configuration);
Method testMethod = TestCase.class.getDeclaredMethod("foo"); Method testMethod = TestCase.class.getDeclaredMethod("foo");
TestMethodTestDescriptor methodDescriptor = new TestMethodTestDes TestMethodTestDescriptor methodDescriptor = new TestMethodTestDes
criptor(uniqueId, TestCase.class, testMethod); criptor(uniqueId, TestCase.class, testMethod,
configuration);
classDescriptor.addChild(methodDescriptor); classDescriptor.addChild(methodDescriptor);
assertEquals(testMethod, methodDescriptor.getTestMethod()); assertEquals(testMethod, methodDescriptor.getTestMethod());
assertEquals("custom test name", methodDescriptor.getDisplayName( ), "display name:"); assertEquals("custom test name", methodDescriptor.getDisplayName( ), "display name:");
assertEquals("foo()", methodDescriptor.getLegacyReportingName(), "legacy name:");
List<String> tags = methodDescriptor.getTags().stream().map(TestT ag::getName).collect(toList()); List<String> tags = methodDescriptor.getTags().stream().map(TestT ag::getName).collect(toList());
assertThat(tags).containsExactlyInAnyOrder("inherited-class-level -tag", "classTag1", "classTag2", "methodTag1", assertThat(tags).containsExactlyInAnyOrder("inherited-class-level -tag", "classTag1", "classTag2", "methodTag1",
"methodTag2"); "methodTag2");
} }
@Test @Test
void constructFromMethodWithCustomTestAnnotation() throws Exception { void constructFromMethodWithCustomTestAnnotation() throws Exception {
Method testMethod = TestCase.class.getDeclaredMethod("customTestA nnotation"); Method testMethod = TestCase.class.getDeclaredMethod("customTestA nnotation");
TestMethodTestDescriptor descriptor = new TestMethodTestDescripto TestMethodTestDescriptor descriptor = new TestMethodTestDescripto
r(uniqueId, TestCase.class, testMethod); r(uniqueId, TestCase.class, testMethod,
configuration);
assertEquals(testMethod, descriptor.getTestMethod()); assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("custom name", descriptor.getDisplayName(), "display name:"); assertEquals("custom name", descriptor.getDisplayName(), "display name:");
assertEquals("customTestAnnotation()", descriptor.getLegacyReport ingName(), "legacy name:");
assertThat(descriptor.getTags()).containsExactly(TestTag.create(" custom-tag")); assertThat(descriptor.getTags()).containsExactly(TestTag.create(" custom-tag"));
} }
@Test @Test
void constructFromMethodWithParameters() throws Exception { void constructFromMethodWithParameters() throws Exception {
Method testMethod = TestCase.class.getDeclaredMethod("test", Stri ng.class, BigDecimal.class); Method testMethod = TestCase.class.getDeclaredMethod("test", Stri ng.class, BigDecimal.class);
TestMethodTestDescriptor descriptor = new TestMethodTestDescripto TestMethodTestDescriptor descriptor = new TestMethodTestDescripto
r(uniqueId, TestCase.class, testMethod); r(uniqueId, TestCase.class, testMethod,
configuration);
assertEquals(testMethod, descriptor.getTestMethod()); assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("test(String, BigDecimal)", descriptor.getDisplayNam e(), "display name"); assertEquals("test(String, BigDecimal)", descriptor.getDisplayNam e(), "display name");
assertEquals("test(String, BigDecimal)", descriptor.getLegacyRepo rtingName(), "legacy name");
} }
@Test @Test
void constructFromMethodWithPrimitiveArrayParameter() throws Exception { void constructFromMethodWithPrimitiveArrayParameter() throws Exception {
Method testMethod = TestCase.class.getDeclaredMethod("test", int[ ].class); Method testMethod = TestCase.class.getDeclaredMethod("test", int[ ].class);
TestMethodTestDescriptor descriptor = new TestMethodTestDescripto TestMethodTestDescriptor descriptor = new TestMethodTestDescripto
r(uniqueId, TestCase.class, testMethod); r(uniqueId, TestCase.class, testMethod,
configuration);
assertEquals(testMethod, descriptor.getTestMethod()); assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("test(int[])", descriptor.getDisplayName(), "display name"); assertEquals("test(int[])", descriptor.getDisplayName(), "display name");
assertEquals("test(int[])", descriptor.getLegacyReportingName(), "legacy name");
} }
@Test @Test
void constructFromMethodWithObjectArrayParameter() throws Exception { void constructFromMethodWithObjectArrayParameter() throws Exception {
Method testMethod = TestCase.class.getDeclaredMethod("test", Stri ng[].class); Method testMethod = TestCase.class.getDeclaredMethod("test", Stri ng[].class);
TestMethodTestDescriptor descriptor = new TestMethodTestDescripto TestMethodTestDescriptor descriptor = new TestMethodTestDescripto
r(uniqueId, TestCase.class, testMethod); r(uniqueId, TestCase.class, testMethod,
configuration);
assertEquals(testMethod, descriptor.getTestMethod()); assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("test(String[])", descriptor.getDisplayName(), "disp lay name"); assertEquals("test(String[])", descriptor.getDisplayName(), "disp lay name");
assertEquals("test(String[])", descriptor.getLegacyReportingName( ), "legacy name");
} }
@Test @Test
void constructFromMethodWithMultidimensionalPrimitiveArrayParameter() thr ows Exception { void constructFromMethodWithMultidimensionalPrimitiveArrayParameter() thr ows Exception {
Method testMethod = TestCase.class.getDeclaredMethod("test", int[ ][][][][].class); Method testMethod = TestCase.class.getDeclaredMethod("test", int[ ][][][][].class);
TestMethodTestDescriptor descriptor = new TestMethodTestDescripto TestMethodTestDescriptor descriptor = new TestMethodTestDescripto
r(uniqueId, TestCase.class, testMethod); r(uniqueId, TestCase.class, testMethod,
configuration);
assertEquals(testMethod, descriptor.getTestMethod()); assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("test(int[][][][][])", descriptor.getDisplayName(), "display name"); assertEquals("test(int[][][][][])", descriptor.getDisplayName(), "display name");
assertEquals("test(int[][][][][])", descriptor.getLegacyReporting Name(), "legacy name");
} }
@Test @Test
void constructFromMethodWithMultidimensionalObjectArrayParameter() throws Exception { void constructFromMethodWithMultidimensionalObjectArrayParameter() throws Exception {
Method testMethod = TestCase.class.getDeclaredMethod("test", Stri ng[][][][][].class); Method testMethod = TestCase.class.getDeclaredMethod("test", Stri ng[][][][][].class);
TestMethodTestDescriptor descriptor = new TestMethodTestDescripto TestMethodTestDescriptor descriptor = new TestMethodTestDescripto
r(uniqueId, TestCase.class, testMethod); r(uniqueId, TestCase.class, testMethod,
configuration);
assertEquals(testMethod, descriptor.getTestMethod()); assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("test(String[][][][][])", descriptor.getDisplayName( ), "display name"); assertEquals("test(String[][][][][])", descriptor.getDisplayName( ), "display name");
assertEquals("test(String[][][][][])", descriptor.getLegacyReport ingName(), "legacy name");
} }
@Test @Test
void constructFromInheritedMethod() throws Exception { void constructFromInheritedMethod() throws Exception {
Method testMethod = ConcreteTest.class.getMethod("theTest"); Method testMethod = ConcreteTest.class.getMethod("theTest");
TestMethodTestDescriptor descriptor = new TestMethodTestDescripto TestMethodTestDescriptor descriptor = new TestMethodTestDescripto
r(uniqueId, ConcreteTest.class, testMethod); r(uniqueId, ConcreteTest.class, testMethod,
configuration);
assertEquals(testMethod, descriptor.getTestMethod()); assertEquals(testMethod, descriptor.getTestMethod());
Optional<TestSource> sourceOptional = descriptor.getSource(); Optional<TestSource> sourceOptional = descriptor.getSource();
assertThat(sourceOptional).containsInstanceOf(MethodSource.class) ; assertThat(sourceOptional).containsInstanceOf(MethodSource.class) ;
MethodSource methodSource = (MethodSource) sourceOptional.get(); MethodSource methodSource = (MethodSource) sourceOptional.orElseT hrow();
assertEquals(ConcreteTest.class.getName(), methodSource.getClassN ame()); assertEquals(ConcreteTest.class.getName(), methodSource.getClassN ame());
assertEquals("theTest", methodSource.getMethodName()); assertEquals("theTest", methodSource.getMethodName());
} }
@Test @Test
void defaultDisplayNamesForTestClasses() { void defaultDisplayNamesForTestClasses() {
ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , getClass(), configParams); ClassTestDescriptor descriptor = new ClassTestDescriptor(uniqueId , getClass(), configuration);
assertEquals(getClass().getSimpleName(), descriptor.getDisplayNam e()); assertEquals(getClass().getSimpleName(), descriptor.getDisplayNam e());
assertEquals(getClass().getName(), descriptor.getLegacyReportingN ame());
descriptor = new NestedClassTestDescriptor(uniqueId, NestedTestCa se.class, configParams); descriptor = new NestedClassTestDescriptor(uniqueId, NestedTestCa se.class, configuration);
assertEquals(NestedTestCase.class.getSimpleName(), descriptor.get DisplayName()); assertEquals(NestedTestCase.class.getSimpleName(), descriptor.get DisplayName());
assertEquals(NestedTestCase.class.getName(), descriptor.getLegacy ReportingName());
descriptor = new ClassTestDescriptor(uniqueId, StaticTestCase.cla ss, configParams); descriptor = new ClassTestDescriptor(uniqueId, StaticTestCase.cla ss, configuration);
String staticDisplayName = getClass().getSimpleName() + "$" + Sta ticTestCase.class.getSimpleName(); String staticDisplayName = getClass().getSimpleName() + "$" + Sta ticTestCase.class.getSimpleName();
assertEquals(staticDisplayName, descriptor.getDisplayName()); assertEquals(staticDisplayName, descriptor.getDisplayName());
assertEquals(StaticTestCase.class.getName(), descriptor.getLegacy ReportingName());
descriptor = new ClassTestDescriptor(uniqueId, StaticTestCaseLeve l2.class, configParams); descriptor = new ClassTestDescriptor(uniqueId, StaticTestCaseLeve l2.class, configuration);
staticDisplayName += "$" + StaticTestCaseLevel2.class.getSimpleNa me(); staticDisplayName += "$" + StaticTestCaseLevel2.class.getSimpleNa me();
assertEquals(staticDisplayName, descriptor.getDisplayName()); assertEquals(staticDisplayName, descriptor.getDisplayName());
assertEquals(StaticTestCaseLevel2.class.getName(), descriptor.get LegacyReportingName());
} }
// ---------------------------------------------------------------------- --- // ---------------------------------------------------------------------- ---
@Test @Test
@DisplayName("custom name") @DisplayName("custom name")
@Tag(" custom-tag ") @Tag(" custom-tag ")
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@interface CustomTestAnnotation { @interface CustomTestAnnotation {
 End of changes. 37 change blocks. 
33 lines changed or deleted 53 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)