├── documentation ├── src │ ├── docs │ │ ├── static │ │ │ ├── .nojekyll │ │ │ └── README.md │ │ └── asciidoc │ │ │ ├── release-notes-5.0.0-ALPHA.adoc │ │ │ └── overview.adoc │ └── test │ │ ├── resources │ │ └── log4j2-test.xml │ │ └── java │ │ ├── example │ │ ├── DisabledClassDemo.java │ │ ├── TaggingDemo.java │ │ ├── Fast.java │ │ ├── FirstJUnit5Tests.java │ │ ├── JUnit4SuiteDemo.java │ │ ├── DisabledTestsDemo.java │ │ ├── DisplayNameDemo.java │ │ ├── timing │ │ │ └── TimingExtensionTests.java │ │ ├── exception │ │ │ ├── IgnoreIOExceptionTests.java │ │ │ └── IgnoreIOExceptionExtension.java │ │ ├── JUnit4ClassDemo.java │ │ ├── TestReporterDemo.java │ │ ├── DocumentationTestSuite.java │ │ ├── TestInfoDemo.java │ │ ├── AssumptionsDemo.java │ │ └── StandardTests.java │ │ └── extensions │ │ ├── ExpectToFail.java │ │ └── ExpectToFailExtension.java └── README.md ├── junit-commons ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── junit │ └── gen5 │ └── commons │ ├── meta │ └── package-info.java │ ├── package-info.java │ ├── util │ ├── package-info.java │ ├── PreconditionViolationException.java │ └── CollectionUtils.java │ └── JUnitException.java ├── clover.license.enc ├── junit-launcher ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── junit │ └── gen5 │ └── launcher │ ├── package-info.java │ ├── listeners │ └── package-info.java │ ├── main │ ├── package-info.java │ ├── ServiceLoaderTestEngineRegistry.java │ └── LauncherFactory.java │ ├── PostDiscoveryFilter.java │ ├── TestId.java │ └── EngineIdFilter.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── junit4-engine ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── org.junit.gen5.engine.TestEngine │ │ └── java │ │ └── org │ │ └── junit │ │ └── gen5 │ │ └── engine │ │ └── junit4 │ │ ├── package-info.java │ │ ├── descriptor │ │ ├── package-info.java │ │ └── RunnerRequest.java │ │ ├── discovery │ │ ├── package-info.java │ │ ├── ClassSelectorResolver.java │ │ ├── IsPotentialJUnit4TestMethod.java │ │ ├── DiscoverySelectorResolver.java │ │ ├── PackageNameSelectorResolver.java │ │ ├── ClasspathSelectorResolver.java │ │ ├── IsPotentialJUnit4TestClass.java │ │ ├── TestClassRequest.java │ │ ├── OrFilter.java │ │ ├── RunnerTestDescriptorAwareFilter.java │ │ ├── MethodSelectorResolver.java │ │ └── UniqueIdReader.java │ │ └── execution │ │ └── package-info.java └── build.gradle ├── junit5-engine ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── org.junit.gen5.engine.TestEngine │ │ └── java │ │ └── org │ │ └── junit │ │ └── gen5 │ │ └── engine │ │ └── junit5 │ │ ├── package-info.java │ │ ├── extension │ │ ├── package-info.java │ │ └── TestReporterParameterResolver.java │ │ ├── descriptor │ │ ├── package-info.java │ │ └── NestedClassTestDescriptor.java │ │ ├── discovery │ │ ├── package-info.java │ │ ├── JUnit5Class.java │ │ ├── JUnit5NestedClass.java │ │ ├── JUnit5Method.java │ │ ├── IsScannableTestClass.java │ │ ├── IsPotentialTestContainer.java │ │ ├── JUnit5EngineDescriptor.java │ │ ├── IsNestedTestClass.java │ │ ├── IsTestMethod.java │ │ └── JUnit5Testable.java │ │ └── execution │ │ ├── package-info.java │ │ ├── TestInstanceProvider.java │ │ ├── ConditionEvaluationException.java │ │ └── NamespaceAwareStore.java └── build.gradle ├── junit4-runner ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── junit │ └── gen5 │ └── junit4 │ └── runner │ ├── package-info.java │ ├── Classes.java │ ├── Packages.java │ ├── ExcludeTags.java │ ├── RequireTags.java │ ├── UniqueIds.java │ ├── RequireEngine.java │ └── FilterClassName.java ├── junit-gradle ├── src │ └── main │ │ └── resources │ │ └── META-INF │ │ └── gradle-plugins │ │ └── org.junit.gen5.gradle.properties └── build.gradle ├── junit5-api ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── junit │ └── gen5 │ └── api │ ├── package-info.java │ ├── extension │ ├── package-info.java │ ├── ContainerExtensionContext.java │ ├── MethodInvocationContext.java │ ├── Extension.java │ ├── TestExtensionContext.java │ ├── ExtensionConfigurationException.java │ ├── ParameterResolutionException.java │ ├── ExtensionRegistrar.java │ ├── ExtensionPoint.java │ ├── InstancePostProcessor.java │ ├── BeforeEachExtensionPoint.java │ ├── AfterAllExtensionPoint.java │ ├── AfterEachExtensionPoint.java │ ├── BeforeAllExtensionPoint.java │ └── Extensions.java │ ├── Nested.java │ ├── DisplayName.java │ ├── Disabled.java │ ├── TestReporter.java │ ├── Tags.java │ ├── TestInfo.java │ ├── Tag.java │ └── Test.java ├── .github └── PULL_REQUEST_TEMPLATE.md ├── junit-engine-api ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── junit │ └── gen5 │ └── engine │ ├── package-info.java │ ├── reporting │ └── package-info.java │ ├── support │ ├── filter │ │ ├── package-info.java │ │ └── ExclusionReasonConsumingFilter.java │ ├── descriptor │ │ ├── package-info.java │ │ └── EngineDescriptor.java │ └── hierarchical │ │ ├── package-info.java │ │ ├── EngineExecutionContext.java │ │ ├── Leaf.java │ │ ├── Container.java │ │ ├── SingleTestExecutor.java │ │ ├── HierarchicalTestEngine.java │ │ └── BlacklistedExceptions.java │ ├── discovery │ ├── package-info.java │ ├── ClassFilter.java │ ├── UniqueIdSelector.java │ ├── PackageSelector.java │ ├── ClassNameFilter.java │ ├── ClassSelector.java │ └── ClasspathSelector.java │ ├── DiscoverySelector.java │ ├── TestSource.java │ ├── TestEngine.java │ ├── Filter.java │ ├── EngineDiscoveryRequest.java │ ├── TestTag.java │ └── ExecutionRequest.java ├── surefire-junit5 ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── org.apache.maven.surefire.providerapi.SurefireProvider │ │ └── java │ │ └── org │ │ └── junit │ │ └── gen5 │ │ └── surefire │ │ ├── package-info.java │ │ └── TestPlanScannerFilter.java └── build.gradle ├── junit-console ├── src │ └── main │ │ └── java │ │ └── org │ │ └── junit │ │ └── gen5 │ │ └── console │ │ ├── package-info.java │ │ ├── options │ │ ├── package-info.java │ │ └── CommandLineOptionsParser.java │ │ └── tasks │ │ ├── package-info.java │ │ ├── DisplayHelpTask.java │ │ ├── ConsoleTask.java │ │ ├── CustomContextClassLoaderExecutor.java │ │ └── ConsoleTaskExecutor.java └── build.gradle ├── .travis.yml ├── gradle.properties ├── .gitignore ├── src ├── spotless │ └── eclipse-public-license-1.0.java ├── test │ └── resources │ │ └── log4j2-test.xml └── checkstyle │ └── checkstyle.xml ├── settings.gradle └── junit-tests └── src └── test ├── resources └── log4j2-test.xml └── java └── org └── junit └── gen5 ├── engine ├── junit5 │ ├── descriptor │ │ └── subpackage │ │ │ ├── ClassWithoutTestCases.java │ │ │ ├── Class1WithTestCases.java │ │ │ ├── Class2WithTestCases.java │ │ │ └── ClassWithStaticInnerTestCases.java │ ├── execution │ │ └── injection │ │ │ └── sample │ │ │ ├── CustomType.java │ │ │ ├── CustomAnnotation.java │ │ │ ├── CustomTypeParameterResolver.java │ │ │ └── CustomAnnotationParameterResolver.java │ ├── stubs │ │ └── TestEngineStub.java │ └── AbstractJUnit5TestEngineTests.java ├── support │ └── hierarchical │ │ ├── DummyEngineExecutionContext.java │ │ └── DummyEngineDescriptor.java ├── junit4 │ └── samples │ │ ├── PlainOldJavaClassWithoutAnyTest.java │ │ ├── junit4 │ │ ├── PlainJUnit4TestCaseWithSingleInheritedTestWhichFails.java │ │ ├── Categories.java │ │ ├── MalformedJUnit4TestCase.java │ │ ├── PlainJUnit4TestCaseWithSingleTestWhichFails.java │ │ ├── JUnit4SuiteWithExceptionThrowingRunner.java │ │ ├── JUnit4SuiteWithIgnoredJUnit4TestCase.java │ │ ├── TestCaseRunWithJUnit5.java │ │ ├── JUnit4TestCaseWithExceptionThrowingRunner.java │ │ ├── IgnoredJUnit4TestCase.java │ │ ├── JUnit4SuiteOfSuiteWithIgnoredJUnit4TestCase.java │ │ ├── JUnit4TestCaseWithRunnerWithCustomUniqueIds.java │ │ ├── JUnit4SuiteWithJUnit4TestCaseWithErrorInBeforeClass.java │ │ ├── JUnit4SuiteWithTwoTestCases.java │ │ ├── PlainJUnit4TestCaseWithSingleTestWhichIsIgnored.java │ │ ├── JUnit4SuiteOfSuiteWithJUnit4TestCaseWithErrorInBeforeClass.java │ │ ├── JUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored.java │ │ ├── JUnit4SuiteWithJUnit4TestCaseWithAssumptionFailureInBeforeClass.java │ │ ├── SingleFailingTheoryTestCase.java │ │ ├── JUnit4SuiteOfSuiteWithJUnit4TestCaseWithAssumptionFailureInBeforeClass.java │ │ ├── EnclosedJUnit4TestCase.java │ │ ├── JUnit4TestCaseWithErrorInBeforeClass.java │ │ ├── JUnit4SuiteWithJUnit3SuiteWithSingleTestCase.java │ │ ├── PlainJUnit4TestCaseWithTwoTestMethods.java │ │ ├── JUnit4TestCaseWithAssumptionFailureInBeforeClass.java │ │ ├── JUnit4TestCaseWithErrorInAfterClass.java │ │ ├── JUnit4TestCaseWithOverloadedMethod.java │ │ └── ParameterizedTestCase.java │ │ └── junit3 │ │ ├── PlainJUnit3TestCaseWithSingleTestWhichFails.java │ │ └── JUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails.java ├── TestDescriptorTests.java ├── TestTagTests.java ├── discovery │ └── ClassFilterTests.java └── TestDescriptorStub.java ├── launcher ├── main │ └── LauncherFactoryForTestingPurposesOnly.java ├── TestIdentifierTests.java └── DiscoveryFilterMock.java ├── commons ├── logging │ └── RecordCollectingLogger.java └── util │ └── ExceptionUtilsTests.java ├── AllJUnit5Tests.java └── console └── tasks ├── IncrementingClock.java └── XmlReportAssertions.java /documentation/src/docs/static/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /junit-commons/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | } 3 | -------------------------------------------------------------------------------- /clover.license.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/452/junit5/master/clover.license.enc -------------------------------------------------------------------------------- /junit-launcher/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile(project(':junit-engine-api')) 3 | } 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/452/junit5/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit4-engine/src/main/resources/META-INF/services/org.junit.gen5.engine.TestEngine: -------------------------------------------------------------------------------- 1 | org.junit.gen5.engine.junit4.JUnit4TestEngine -------------------------------------------------------------------------------- /junit5-engine/src/main/resources/META-INF/services/org.junit.gen5.engine.TestEngine: -------------------------------------------------------------------------------- 1 | org.junit.gen5.engine.junit5.JUnit5TestEngine -------------------------------------------------------------------------------- /junit5-engine/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile(project(':junit-engine-api')) 3 | compile(project(':junit5-api')) 4 | } 5 | -------------------------------------------------------------------------------- /junit4-runner/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile(project(':junit-launcher')) 3 | compile("junit:junit:${junit4Version}") 4 | } 5 | -------------------------------------------------------------------------------- /junit-gradle/src/main/resources/META-INF/gradle-plugins/org.junit.gen5.gradle.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.junit.gen5.gradle.JUnit5Plugin -------------------------------------------------------------------------------- /junit4-engine/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile(project(':junit-engine-api')) 3 | compile("junit:junit:${junit4Version}") 4 | } 5 | -------------------------------------------------------------------------------- /junit5-api/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile("org.opentest4j:opentest4j:${ota4jVersion}") 3 | compile(project(':junit-commons')) 4 | } 5 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | - 4 | 5 | --- 6 | 7 | I hereby agree to the terms of the JUnit Contributor License Agreement. 8 | -------------------------------------------------------------------------------- /junit-engine-api/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile(project(':junit-commons')) 3 | compile("org.opentest4j:opentest4j:${ota4jVersion}") 4 | } 5 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * JUnit 5 API for writing tests. 3 | */ 4 | 5 | package org.junit.gen5.api; 6 | -------------------------------------------------------------------------------- /surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider: -------------------------------------------------------------------------------- 1 | org.junit.gen5.surefire.JUnitGen5Provider 2 | -------------------------------------------------------------------------------- /documentation/src/docs/static/README.md: -------------------------------------------------------------------------------- 1 | # JUnit 5 User Guide 2 | 3 | This branch contains the website sources available at: 4 | http://junit-team.github.io/junit5/ 5 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Public API for JUnit test engines. 3 | */ 4 | 5 | package org.junit.gen5.engine; 6 | -------------------------------------------------------------------------------- /surefire-junit5/src/main/java/org/junit/gen5/surefire/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Maven Surefire plug-in for JUnit 5. 3 | */ 4 | 5 | package org.junit.gen5.surefire; 6 | -------------------------------------------------------------------------------- /junit-console/src/main/java/org/junit/gen5/console/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Support for running JUnit from the console. 3 | */ 4 | 5 | package org.junit.gen5.console; 6 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * JUnit 5 API for writing extensions. 3 | */ 4 | 5 | package org.junit.gen5.api.extension; 6 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Core package for the JUnit 4 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit4; 6 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Core package for the JUnit 5 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit5; 6 | -------------------------------------------------------------------------------- /junit-console/src/main/java/org/junit/gen5/console/options/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Configuration options for JUnit's console runner. 3 | */ 4 | 5 | package org.junit.gen5.console.options; 6 | -------------------------------------------------------------------------------- /junit-console/src/main/java/org/junit/gen5/console/tasks/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal execution tasks for JUnit's console runner. 3 | */ 4 | 5 | package org.junit.gen5.console.tasks; 6 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/extension/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Test extensions specific to the JUnit 5 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit5.extension; 6 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/descriptor/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Test descriptors used within the JUnit 4 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit4.descriptor; 6 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/descriptor/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Test descriptors used within the JUnit 5 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit5.descriptor; 6 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal classes for test discovery within the JUnit 4 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit4.discovery; 6 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/execution/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal classes for test execution within the JUnit 4 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit4.execution; 6 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal classes for test discovery within the JUnit 5 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit5.discovery; 6 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/execution/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal classes for test execution within the JUnit 5 test engine. 3 | */ 4 | 5 | package org.junit.gen5.engine.junit5.execution; 6 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/reporting/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes used by test engines to report additional data to execution 3 | * listeners. 4 | */ 5 | 6 | package org.junit.gen5.engine.reporting; 7 | -------------------------------------------------------------------------------- /junit-launcher/src/main/java/org/junit/gen5/launcher/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Public API for configuring and launching test plans. 3 | * 4 | *

This API is typically used by IDEs and build tools. 5 | */ 6 | 7 | package org.junit.gen5.launcher; 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | sudo: required 4 | 5 | jdk: 6 | - oraclejdk8 7 | 8 | install: true 9 | 10 | script: 11 | - sudo apt-get update && sudo apt-get install oracle-java8-installer 12 | - java -version 13 | - ./gradlew check 14 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version = 5.0.0-SNAPSHOT 2 | group = org.junit 3 | 4 | assertJVersion = 3.2.0 5 | junit4Version = 4.12 6 | log4JVersion = 2.5 7 | mockitoVersion = 1.10.19 8 | ota4jVersion = 1.0.0-ALPHA 9 | degraphVersion = 0.1.3 10 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/filter/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * {@link org.junit.gen5.engine.Filter}-related support classes intended to be 3 | * used by test engine implementations. 4 | */ 5 | 6 | package org.junit.gen5.engine.support.filter; 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Dec 24 12:48:01 CET 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /junit4-runner/src/main/java/org/junit/gen5/junit4/runner/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * {@code Runner} and annotations for configuring and executing tests that 3 | * use the JUnit 5 programming and extension models in a JUnit 4 environment. 4 | */ 5 | 6 | package org.junit.gen5.junit4.runner; 7 | -------------------------------------------------------------------------------- /surefire-junit5/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile('org.apache.maven.surefire:surefire-api:2.19') 3 | compile('org.apache.maven.surefire:common-java5:2.19') 4 | compile(project(':junit-launcher')) 5 | runtime(project(':junit5-engine')) 6 | runtime(project(':junit4-engine')) 7 | } 8 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/descriptor/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * {@link org.junit.gen5.engine.TestDescriptor}-related support classes 3 | * intended to be used by test engine implementations. 4 | */ 5 | 6 | package org.junit.gen5.engine.support.descriptor; 7 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/hierarchical/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Base hierarchical implementation of execution part of 3 | * {@link org.junit.gen5.engine.TestEngine} to be used by test engine 4 | * implementations. 5 | */ 6 | 7 | package org.junit.gen5.engine.support.hierarchical; 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build/ 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Eclipse 9 | .classpath 10 | .settings/ 11 | .project 12 | bin/ 13 | 14 | # IntelliJ 15 | *.iml 16 | *.ipr 17 | *.iws 18 | *.uml 19 | .idea/ 20 | 21 | # Misc 22 | *.log 23 | *.graphml 24 | coverage.db* 25 | clover.license 26 | -------------------------------------------------------------------------------- /documentation/src/docs/asciidoc/release-notes-5.0.0-ALPHA.adoc: -------------------------------------------------------------------------------- 1 | === Release Notes 5.0.0-ALPHA 2 | 3 | *Date of Release:* February 1, 2016 4 | 5 | *Scope:* First public release of JUnit 5 6 | 7 | ==== Summary of Changes 8 | 9 | Since this is the first public release, the set of changes is the set of features as described in this user guide. 10 | -------------------------------------------------------------------------------- /junit-launcher/src/main/java/org/junit/gen5/launcher/listeners/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Common {@link org.junit.gen5.launcher.TestExecutionListener 3 | * TestExecutionListener} implementations and related support classes for 4 | * the JUnit {@link org.junit.gen5.launcher.Launcher Launcher}. 5 | */ 6 | 7 | package org.junit.gen5.launcher.listeners; 8 | -------------------------------------------------------------------------------- /junit-gradle/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | 3 | jar { 4 | manifest { 5 | attributes 'Main-Class': 'org.junit.gen5.console.ConsoleRunner' 6 | } 7 | } 8 | 9 | dependencies { 10 | compile localGroovy() 11 | compile gradleApi() 12 | testCompile(group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4') { 13 | transitive = false 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/discovery/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Concrete {@linkplain org.junit.gen5.engine.DiscoverySelector selectors} and 3 | * {@linkplain org.junit.gen5.engine.DiscoveryFilter filters} to be used in 4 | * {@linkplain org.junit.gen5.engine.EngineDiscoveryRequest discovery requests}. 5 | */ 6 | 7 | package org.junit.gen5.engine.discovery; 8 | -------------------------------------------------------------------------------- /src/spotless/eclipse-public-license-1.0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | -------------------------------------------------------------------------------- /junit-commons/src/main/java/org/junit/gen5/commons/meta/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal meta-annotations. 3 | * 4 | *

DISCLAIMER

5 | * 6 | *

These classes are intended solely for usage within the JUnit framework 7 | * itself. Any usage by external parties is not supported. 8 | * Use at your own risk! 9 | */ 10 | 11 | package org.junit.gen5.commons.meta; 12 | -------------------------------------------------------------------------------- /junit-commons/src/main/java/org/junit/gen5/commons/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal common library of JUnit. 3 | * 4 | *

DISCLAIMER

5 | * 6 | *

These utilities are intended solely for usage within the JUnit framework 7 | * itself. Any usage by external parties is not supported. 8 | * Use at your own risk! 9 | */ 10 | 11 | package org.junit.gen5.commons; 12 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "junit5" 2 | 3 | include "documentation" 4 | include "junit-commons" 5 | include "junit-console" 6 | include "junit-engine-api" 7 | include "junit-gradle" 8 | include "junit-launcher" 9 | include "junit-tests" 10 | include "junit4-engine" 11 | include "junit4-runner" 12 | include "junit5-api" 13 | include "junit5-engine" 14 | 15 | include "surefire-junit5" 16 | -------------------------------------------------------------------------------- /junit-commons/src/main/java/org/junit/gen5/commons/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Internal common utilities for JUnit. 3 | * 4 | *

DISCLAIMER

5 | * 6 | *

These utilities are intended solely for usage within the JUnit framework 7 | * itself. Any usage by external parties is not supported. 8 | * Use at your own risk! 9 | */ 10 | 11 | package org.junit.gen5.commons.util; 12 | -------------------------------------------------------------------------------- /junit-console/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'application' 2 | 3 | dependencies { 4 | compile(project(':junit-launcher')) 5 | compile('net.sf.jopt-simple:jopt-simple:4.9') 6 | 7 | // Added as runtime dependencies for ease of use in manually managed projects 8 | // see: https://github.com/junit-team/junit5/issues/146 9 | runtime(project(':junit4-engine')) 10 | runtime(project(':junit5-engine')) 11 | } 12 | 13 | mainClassName = "org.junit.gen5.console.ConsoleRunner" 14 | -------------------------------------------------------------------------------- /src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /documentation/src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /junit-launcher/src/main/java/org/junit/gen5/launcher/main/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The {@link org.junit.gen5.launcher.main.DefaultLauncher DefaultLauncher} 3 | * class is the main starting point for running all JUnit tests. 4 | * 5 | *

The {@link org.junit.gen5.launcher.main.TestDiscoveryRequestBuilder 6 | * TestDiscoveryRequestBuilder} serves as a small DSL for creating 7 | * {@link org.junit.gen5.launcher.TestDiscoveryRequest TestDiscoveryRequests}. 8 | */ 9 | 10 | package org.junit.gen5.launcher.main; 11 | -------------------------------------------------------------------------------- /junit-tests/src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/descriptor/subpackage/ClassWithoutTestCases.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.descriptor.subpackage; 12 | 13 | public class ClassWithoutTestCases { 14 | } 15 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/support/hierarchical/DummyEngineExecutionContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.hierarchical; 12 | 13 | class DummyEngineExecutionContext implements EngineExecutionContext { 14 | } 15 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/PlainOldJavaClassWithoutAnyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples; 12 | 13 | public class PlainOldJavaClassWithoutAnyTest { 14 | 15 | public void doSomething() { 16 | // no-op 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/descriptor/subpackage/Class1WithTestCases.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.descriptor.subpackage; 12 | 13 | import org.junit.gen5.api.Test; 14 | 15 | public class Class1WithTestCases { 16 | 17 | @Test 18 | void test1() { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/descriptor/subpackage/Class2WithTestCases.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.descriptor.subpackage; 12 | 13 | import org.junit.gen5.api.Test; 14 | 15 | public class Class2WithTestCases { 16 | 17 | @Test 18 | void test2() { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/PlainJUnit4TestCaseWithSingleInheritedTestWhichFails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | public class PlainJUnit4TestCaseWithSingleInheritedTestWhichFails extends PlainJUnit4TestCaseWithSingleTestWhichFails { 14 | } 15 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/DisabledClassDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import org.junit.gen5.api.Disabled; 15 | import org.junit.gen5.api.Test; 16 | 17 | @Disabled 18 | class DisabledClassDemo { 19 | @Test 20 | void testWillBeSkipped() { 21 | } 22 | } 23 | // end::user_guide[] 24 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/TaggingDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import org.junit.gen5.api.*; 15 | 16 | @Tag("fast") 17 | @Tag("model") 18 | class TaggingDemo { 19 | 20 | @Test 21 | @Tag("taxes") 22 | void testingTaxCalculation() { 23 | } 24 | 25 | } 26 | // end::user_guide[] 27 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/Fast.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import java.lang.annotation.*; 15 | 16 | import org.junit.gen5.api.*; 17 | 18 | @Target({ ElementType.TYPE, ElementType.METHOD }) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Tag("fast") 21 | public @interface Fast { 22 | } 23 | // end::user_guide[] 24 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/FirstJUnit5Tests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import static org.junit.gen5.api.Assertions.assertEquals; 15 | 16 | import org.junit.gen5.api.Test; 17 | 18 | class FirstJUnit5Tests { 19 | 20 | @Test 21 | void myFirstTest() { 22 | assertEquals(2, 1 + 1); 23 | } 24 | 25 | } 26 | // end::user_guide[] 27 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/JUnit4SuiteDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import org.junit.gen5.junit4.runner.JUnit5; 15 | import org.junit.gen5.junit4.runner.Packages; 16 | import org.junit.runner.RunWith; 17 | 18 | @RunWith(JUnit5.class) 19 | @Packages({ "example" }) 20 | public class JUnit4SuiteDemo { 21 | } 22 | // end::user_guide[] 23 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/DisabledTestsDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import org.junit.gen5.api.Disabled; 15 | import org.junit.gen5.api.Test; 16 | 17 | class DisabledTestsDemo { 18 | 19 | @Disabled 20 | @Test 21 | void testWillBeSkipped() { 22 | } 23 | 24 | @Test 25 | void testWillBeExecuted() { 26 | } 27 | } 28 | // end::user_guide[] 29 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/DisplayNameDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import org.junit.gen5.api.DisplayName; 15 | import org.junit.gen5.api.Test; 16 | 17 | @DisplayName("A special test case") 18 | class DisplayNameDemo { 19 | 20 | @Test 21 | @DisplayName("A nice name, isn't it?") 22 | void testWithANiceName() { 23 | } 24 | } 25 | // end::user_guide[] 26 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/Categories.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | public class Categories { 14 | 15 | public interface Plain { 16 | } 17 | 18 | public interface Failing { 19 | } 20 | 21 | public interface Skipped { 22 | } 23 | 24 | public interface SkippedWithReason extends Skipped { 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/MalformedJUnit4TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import org.junit.Test; 16 | 17 | public class MalformedJUnit4TestCase { 18 | 19 | @Test 20 | /* not public */ void nonPublicTest() { 21 | fail("this should never be called"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/execution/TestInstanceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.execution; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | @FunctionalInterface 18 | @API(Internal) 19 | public interface TestInstanceProvider { 20 | 21 | Object getTestInstance() throws Exception; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit3/PlainJUnit3TestCaseWithSingleTestWhichFails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit3; 12 | 13 | import junit.framework.TestCase; 14 | 15 | import org.junit.Assert; 16 | 17 | public class PlainJUnit3TestCaseWithSingleTestWhichFails extends TestCase { 18 | 19 | public void test() { 20 | Assert.fail("this test should fail"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/PlainJUnit4TestCaseWithSingleTestWhichFails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import org.junit.Test; 16 | 17 | public class PlainJUnit4TestCaseWithSingleTestWhichFails { 18 | 19 | @Test 20 | public void failingTest() { 21 | fail("this test should fail"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/execution/injection/sample/CustomType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.execution.injection.sample; 12 | 13 | import java.util.Date; 14 | 15 | /** 16 | * @since 5.0 17 | */ 18 | public class CustomType { 19 | 20 | private final Date date = new Date(); 21 | 22 | @Override 23 | public String toString() { 24 | return "CustomType: " + this.date; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteWithExceptionThrowingRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.gen5.engine.junit4.samples.junit4.ExceptionThrowingRunner.ChildCount; 14 | import org.junit.runner.RunWith; 15 | 16 | @RunWith(ExceptionThrowingRunner.class) 17 | @ChildCount(1) 18 | public class JUnit4SuiteWithExceptionThrowingRunner { 19 | } 20 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteWithIgnoredJUnit4TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | import org.junit.runners.Suite.SuiteClasses; 16 | 17 | @RunWith(Suite.class) 18 | @SuiteClasses(IgnoredJUnit4TestCase.class) 19 | public class JUnit4SuiteWithIgnoredJUnit4TestCase { 20 | } 21 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/TestCaseRunWithJUnit5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.gen5.junit4.runner.Classes; 14 | import org.junit.gen5.junit4.runner.JUnit5; 15 | import org.junit.runner.RunWith; 16 | 17 | @RunWith(JUnit5.class) 18 | @Classes(PlainJUnit4TestCaseWithSingleTestWhichFails.class) 19 | public class TestCaseRunWithJUnit5 { 20 | } 21 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4TestCaseWithExceptionThrowingRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.gen5.engine.junit4.samples.junit4.ExceptionThrowingRunner.ChildCount; 14 | import org.junit.runner.RunWith; 15 | 16 | @RunWith(ExceptionThrowingRunner.class) 17 | @ChildCount(0) 18 | public class JUnit4TestCaseWithExceptionThrowingRunner { 19 | } 20 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/IgnoredJUnit4TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import org.junit.Ignore; 16 | import org.junit.Test; 17 | 18 | @Ignore("complete class is ignored") 19 | public class IgnoredJUnit4TestCase { 20 | 21 | @Test 22 | public void test() { 23 | fail("this test is not even discovered"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteOfSuiteWithIgnoredJUnit4TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | import org.junit.runners.Suite.SuiteClasses; 16 | 17 | @RunWith(Suite.class) 18 | @SuiteClasses(JUnit4SuiteWithIgnoredJUnit4TestCase.class) 19 | public class JUnit4SuiteOfSuiteWithIgnoredJUnit4TestCase { 20 | } 21 | -------------------------------------------------------------------------------- /junit-console/src/main/java/org/junit/gen5/console/options/CommandLineOptionsParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.console.options; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.io.Writer; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | @API(Internal) 20 | public interface CommandLineOptionsParser { 21 | 22 | CommandLineOptions parse(String... arguments); 23 | 24 | void printHelp(Writer writer); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/DiscoverySelector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * A selector defines location(s) a {@link TestEngine} should lookup tests at. 19 | * 20 | * @since 5.0 21 | * @see EngineDiscoveryRequest 22 | */ 23 | @API(Experimental) 24 | public interface DiscoverySelector { 25 | } 26 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4TestCaseWithRunnerWithCustomUniqueIds.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.Assert; 14 | import org.junit.Test; 15 | import org.junit.runner.RunWith; 16 | 17 | @RunWith(RunnerWithCustomUniqueIds.class) 18 | public class JUnit4TestCaseWithRunnerWithCustomUniqueIds { 19 | 20 | @Test 21 | public void test() { 22 | Assert.fail(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/descriptor/RunnerRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.descriptor; 12 | 13 | import org.junit.runner.Request; 14 | import org.junit.runner.Runner; 15 | 16 | class RunnerRequest extends Request { 17 | 18 | private final Runner runner; 19 | 20 | RunnerRequest(Runner runner) { 21 | this.runner = runner; 22 | } 23 | 24 | @Override 25 | public Runner getRunner() { 26 | return runner; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteWithJUnit4TestCaseWithErrorInBeforeClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | import org.junit.runners.Suite.SuiteClasses; 16 | 17 | @RunWith(Suite.class) 18 | @SuiteClasses(JUnit4TestCaseWithErrorInBeforeClass.class) 19 | public class JUnit4SuiteWithJUnit4TestCaseWithErrorInBeforeClass { 20 | } 21 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteWithTwoTestCases.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | import org.junit.runners.Suite.SuiteClasses; 16 | 17 | @RunWith(Suite.class) 18 | @SuiteClasses({ PlainJUnit4TestCaseWithTwoTestMethods.class, PlainJUnit4TestCaseWithSingleTestWhichFails.class }) 19 | public class JUnit4SuiteWithTwoTestCases { 20 | } 21 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/launcher/main/LauncherFactoryForTestingPurposesOnly.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.launcher.main; 12 | 13 | import static java.util.Arrays.asList; 14 | 15 | import org.junit.gen5.engine.TestEngine; 16 | 17 | /** 18 | * @since 5.0 19 | */ 20 | public class LauncherFactoryForTestingPurposesOnly { 21 | 22 | public static DefaultLauncher createLauncher(TestEngine... engines) { 23 | return new DefaultLauncher(asList(engines)); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/PlainJUnit4TestCaseWithSingleTestWhichIsIgnored.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.Assert; 14 | import org.junit.Ignore; 15 | import org.junit.Test; 16 | 17 | public class PlainJUnit4TestCaseWithSingleTestWhichIsIgnored { 18 | 19 | @Test 20 | @Ignore("ignored test") 21 | public void ignoredTest() { 22 | Assert.fail("this should not be called"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /documentation/src/test/java/extensions/ExpectToFail.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package extensions; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | import org.junit.gen5.api.extension.ExtendWith; 19 | 20 | @Target({ ElementType.TYPE, ElementType.METHOD }) 21 | @Retention(RetentionPolicy.RUNTIME) 22 | @ExtendWith(ExpectToFailExtension.class) 23 | public @interface ExpectToFail { 24 | } 25 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteOfSuiteWithJUnit4TestCaseWithErrorInBeforeClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | import org.junit.runners.Suite.SuiteClasses; 16 | 17 | @RunWith(Suite.class) 18 | @SuiteClasses(JUnit4SuiteWithJUnit4TestCaseWithErrorInBeforeClass.class) 19 | public class JUnit4SuiteOfSuiteWithJUnit4TestCaseWithErrorInBeforeClass { 20 | } 21 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | import org.junit.runners.Suite.SuiteClasses; 16 | 17 | @RunWith(Suite.class) 18 | @SuiteClasses(PlainJUnit4TestCaseWithSingleTestWhichIsIgnored.class) 19 | public class JUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored { 20 | } 21 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteWithJUnit4TestCaseWithAssumptionFailureInBeforeClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | import org.junit.runners.Suite.SuiteClasses; 16 | 17 | @RunWith(Suite.class) 18 | @SuiteClasses(JUnit4TestCaseWithAssumptionFailureInBeforeClass.class) 19 | public class JUnit4SuiteWithJUnit4TestCaseWithAssumptionFailureInBeforeClass { 20 | } 21 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/discovery/ClassFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.engine.DiscoveryFilter; 17 | 18 | @API(Experimental) 19 | public interface ClassFilter extends DiscoveryFilter> { 20 | 21 | static ClassFilter byNamePattern(String pattern) { 22 | return new ClassNameFilter(pattern); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/execution/injection/sample/CustomAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.execution.injection.sample; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * @since 5.0 20 | */ 21 | @Target(ElementType.PARAMETER) 22 | @Retention(RetentionPolicy.RUNTIME) 23 | public @interface CustomAnnotation { 24 | } 25 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/TestSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.io.Serializable; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | @API(Experimental) 20 | public interface TestSource extends Serializable { 21 | 22 | boolean isJavaClass(); 23 | 24 | boolean isJavaMethod(); 25 | 26 | boolean isDirectory(); 27 | 28 | boolean isFile(); 29 | 30 | boolean isFilePosition(); 31 | } 32 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/SingleFailingTheoryTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.Assert; 14 | import org.junit.experimental.theories.Theories; 15 | import org.junit.experimental.theories.Theory; 16 | import org.junit.runner.RunWith; 17 | 18 | @RunWith(Theories.class) 19 | public class SingleFailingTheoryTestCase { 20 | 21 | @Theory 22 | public void theory() { 23 | Assert.fail("this theory should fail"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/ContainerExtensionContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * {@code ContainerExtensionContext} encapsulates the context in which 19 | * the current container is being executed. 20 | * 21 | * @since 5.0 22 | */ 23 | @API(Experimental) 24 | public interface ContainerExtensionContext extends ExtensionContext { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteOfSuiteWithJUnit4TestCaseWithAssumptionFailureInBeforeClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | import org.junit.runners.Suite.SuiteClasses; 16 | 17 | @RunWith(Suite.class) 18 | @SuiteClasses(JUnit4SuiteWithJUnit4TestCaseWithAssumptionFailureInBeforeClass.class) 19 | public class JUnit4SuiteOfSuiteWithJUnit4TestCaseWithAssumptionFailureInBeforeClass { 20 | } 21 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/ClassSelectorResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import org.junit.gen5.engine.discovery.ClassSelector; 14 | 15 | class ClassSelectorResolver extends DiscoverySelectorResolver { 16 | 17 | ClassSelectorResolver() { 18 | super(ClassSelector.class); 19 | } 20 | 21 | @Override 22 | void resolve(ClassSelector selector, TestClassCollector collector) { 23 | collector.addCompletely(selector.getTestClass()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/TestEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * @since 5.0 19 | */ 20 | @API(Experimental) 21 | public interface TestEngine { 22 | 23 | default String getId() { 24 | return getClass().getCanonicalName(); 25 | } 26 | 27 | TestDescriptor discover(EngineDiscoveryRequest discoveryRequest); 28 | 29 | void execute(ExecutionRequest request); 30 | } 31 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/EnclosedJUnit4TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import org.junit.Test; 16 | import org.junit.experimental.runners.Enclosed; 17 | import org.junit.runner.RunWith; 18 | 19 | @RunWith(Enclosed.class) 20 | public class EnclosedJUnit4TestCase { 21 | 22 | public static class NestedClass { 23 | 24 | @Test 25 | public void failingTest() { 26 | fail("this test should fail"); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4TestCaseWithErrorInBeforeClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import org.junit.BeforeClass; 16 | import org.junit.Test; 17 | 18 | public class JUnit4TestCaseWithErrorInBeforeClass { 19 | 20 | @BeforeClass 21 | public static void failingBeforeClass() { 22 | fail("something went wrong"); 23 | } 24 | 25 | @Test 26 | public void test() { 27 | fail("this should never be called"); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/descriptor/subpackage/ClassWithStaticInnerTestCases.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.descriptor.subpackage; 12 | 13 | import org.junit.gen5.api.Test; 14 | 15 | /** 16 | * @since 5.0 17 | */ 18 | public class ClassWithStaticInnerTestCases { 19 | 20 | static class ShouldBeDiscovered { 21 | 22 | @Test 23 | void test1() { 24 | } 25 | } 26 | 27 | @SuppressWarnings("unused") 28 | private static class ShouldNotBeDiscovered { 29 | 30 | @Test 31 | void test2() { 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/JUnit5Class.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | class JUnit5Class extends JUnit5Testable { 14 | 15 | private final Class javaClass; 16 | 17 | JUnit5Class(String uniqueId, Class javaClass) { 18 | super(uniqueId); 19 | this.javaClass = javaClass; 20 | } 21 | 22 | Class getJavaClass() { 23 | return this.javaClass; 24 | } 25 | 26 | @Override 27 | void accept(Visitor visitor) { 28 | visitor.visitClass(getUniqueId(), this.javaClass); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/timing/TimingExtensionTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example.timing; 12 | 13 | import org.junit.gen5.api.Test; 14 | import org.junit.gen5.api.extension.ExtendWith; 15 | 16 | /** 17 | * Tests that demonstrate the example {@link TimingExtension}. 18 | * 19 | * @since 5.0 20 | */ 21 | @ExtendWith(TimingExtension.class) 22 | class TimingExtensionTests { 23 | 24 | @Test 25 | void sleep20ms() throws Exception { 26 | Thread.sleep(20); 27 | } 28 | 29 | @Test 30 | void sleep50ms() throws Exception { 31 | Thread.sleep(50); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit3/JUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit3; 12 | 13 | import junit.framework.TestCase; 14 | import junit.framework.TestSuite; 15 | 16 | public class JUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails extends TestCase { 17 | 18 | public static junit.framework.Test suite() { 19 | TestSuite suite = new TestSuite(); 20 | suite.addTestSuite(PlainJUnit3TestCaseWithSingleTestWhichFails.class); 21 | return suite; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/hierarchical/EngineExecutionContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.hierarchical; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * Marker interface for an execution context used by a concrete implementation 19 | * of {@link HierarchicalTestEngine} and its collaborators. 20 | * 21 | * @since 5.0 22 | * @see HierarchicalTestEngine 23 | */ 24 | @API(Experimental) 25 | public interface EngineExecutionContext { 26 | } 27 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/exception/IgnoreIOExceptionTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example.exception; 12 | 13 | import java.io.IOException; 14 | 15 | import extensions.ExpectToFail; 16 | 17 | import org.junit.gen5.api.Test; 18 | import org.junit.gen5.api.extension.ExtendWith; 19 | 20 | @ExtendWith(IgnoreIOExceptionExtension.class) 21 | class IgnoreIOExceptionTests { 22 | 23 | @Test 24 | void shouldSucceed() throws IOException { 25 | throw new IOException("any"); 26 | } 27 | 28 | @Test 29 | @ExpectToFail 30 | void shouldFail() { 31 | throw new RuntimeException("any"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4SuiteWithJUnit3SuiteWithSingleTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import org.junit.gen5.engine.junit4.samples.junit3.JUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails; 14 | import org.junit.runner.RunWith; 15 | import org.junit.runners.Suite; 16 | import org.junit.runners.Suite.SuiteClasses; 17 | 18 | @RunWith(Suite.class) 19 | @SuiteClasses(JUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails.class) 20 | public class JUnit4SuiteWithJUnit3SuiteWithSingleTestCase { 21 | } 22 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/MethodInvocationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.lang.reflect.Method; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | /** 20 | * {@code MethodInvocationContext} encapsulates the context in which 21 | * a method is to be invoked. 22 | * 23 | * @since 5.0 24 | */ 25 | @API(Experimental) 26 | public interface MethodInvocationContext { 27 | 28 | Object getInstance(); 29 | 30 | Method getMethod(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/IsPotentialJUnit4TestMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import java.lang.reflect.Method; 14 | import java.util.function.Predicate; 15 | 16 | import org.junit.Test; 17 | 18 | /** 19 | * @since 5.0 20 | */ 21 | class IsPotentialJUnit4TestMethod implements Predicate { 22 | 23 | @Override 24 | public boolean test(Method method) { 25 | // Don't use AnnotationUtils.hasAnnotation since JUnit 4 does not support 26 | // meta-annotations 27 | return method.isAnnotationPresent(Test.class); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/Extension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * Marker interface for all extensions. 19 | * 20 | *

An {@code Extension} can be registered declaratively via 21 | * {@link ExtendWith @ExtendWith} or programmatically via an 22 | * {@link ExtensionRegistrar}. 23 | * 24 | * @since 5.0 25 | * @see ExtensionPoint 26 | * @see ExtensionRegistrar 27 | */ 28 | @API(Experimental) 29 | public interface Extension { 30 | } 31 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/TestExtensionContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.lang.reflect.Method; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | /** 20 | * {@code TestExtensionContext} encapsulates the context in which 21 | * the current test is being executed. 22 | * 23 | * @since 5.0 24 | */ 25 | @API(Experimental) 26 | public interface TestExtensionContext extends ExtensionContext { 27 | 28 | Object getTestInstance(); 29 | 30 | Method getTestMethod(); 31 | } 32 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/TestDescriptorTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.gen5.api.Assertions.*; 14 | 15 | import org.junit.gen5.api.Test; 16 | 17 | public class TestDescriptorTests { 18 | 19 | @Test 20 | public void isRootWithoutParent() { 21 | TestDescriptor root = new TestDescriptorStub("id"); 22 | 23 | assertTrue(root.isRoot()); 24 | } 25 | 26 | @Test 27 | public void isRootWithParent() { 28 | TestDescriptor child = new TestDescriptorStub("child"); 29 | child.setParent(new TestDescriptorStub("root")); 30 | 31 | assertFalse(child.isRoot()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/PlainJUnit4TestCaseWithTwoTestMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.*; 14 | import static org.junit.runners.MethodSorters.NAME_ASCENDING; 15 | 16 | import org.junit.FixMethodOrder; 17 | import org.junit.Test; 18 | 19 | @FixMethodOrder(NAME_ASCENDING) 20 | public class PlainJUnit4TestCaseWithTwoTestMethods { 21 | 22 | @Test 23 | public void failingTest() { 24 | fail("this test should fail"); 25 | } 26 | 27 | @Test 28 | public void successfulTest() { 29 | assertEquals(3, 1 + 2); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /documentation/README.md: -------------------------------------------------------------------------------- 1 | # JUnit 5 User Guide 2 | 3 | This subproject contains the AsciiDoc sources for the future JUnit 5 User Guide. 4 | 5 | ## Structure 6 | 7 | - `src/docs/asciidoc`: AsciiDoc files 8 | - `src/docs/static`: Static files for the `gh-pages` branch 9 | - `src/test/java`: Test source code that can be included in the AsciiDoc files 10 | - `src/main/java`: Example source code that can be included in the AsciiDoc files 11 | 12 | ## Usage 13 | 14 | ### Generate AsciiDoc 15 | 16 | ``` 17 | gradle asciidoctor 18 | ``` 19 | 20 | This task generates HTML files into `build/asciidoc/html5`. 21 | 22 | ### Publish it to GitHub Pages 23 | 24 | ``` 25 | gradle publishGhPages 26 | ``` 27 | 28 | This task requires setting the Gradle property `githubToken`, e.g. in `~/.gradle/gradle.properties`, to a GitHub [personal access token](https://github.com/settings/tokens) that includes the `public_repo` scope. 29 | 30 | When successful the uploaded files are available at: 31 | 32 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/JUnit5NestedClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | class JUnit5NestedClass extends JUnit5Class { 14 | 15 | private final Class containerClass; 16 | 17 | JUnit5NestedClass(String uniqueId, Class javaClass, Class containerClass) { 18 | super(uniqueId, javaClass); 19 | this.containerClass = containerClass; 20 | } 21 | 22 | @Override 23 | void accept(Visitor visitor) { 24 | visitor.visitNestedClass(getUniqueId(), getJavaClass(), this.containerClass); 25 | } 26 | 27 | Class getContainerClass() { 28 | return this.containerClass; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4TestCaseWithAssumptionFailureInBeforeClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import org.junit.AssumptionViolatedException; 16 | import org.junit.BeforeClass; 17 | import org.junit.Test; 18 | 19 | public class JUnit4TestCaseWithAssumptionFailureInBeforeClass { 20 | 21 | @BeforeClass 22 | public static void failingBeforeClass() { 23 | throw new AssumptionViolatedException("assumption violated"); 24 | } 25 | 26 | @Test 27 | public void test() { 28 | fail("this should never be called"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/JUnit4ClassDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import static org.junit.gen5.api.Assertions.fail; 15 | 16 | import extensions.ExpectToFail; 17 | 18 | import org.junit.gen5.api.Test; 19 | import org.junit.gen5.junit4.runner.JUnit5; 20 | import org.junit.runner.RunWith; 21 | 22 | @RunWith(JUnit5.class) 23 | public class JUnit4ClassDemo { 24 | 25 | @Test 26 | void aSucceedingTest() { 27 | /* no-op */ 28 | } 29 | 30 | // end::user_guide[] 31 | @ExpectToFail 32 | // tag::user_guide[] 33 | @Test 34 | void aFailingTest() { 35 | fail("Failing for failing's sake."); 36 | } 37 | 38 | } 39 | // end::user_guide[] 40 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/TestReporterDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import java.util.HashMap; 15 | 16 | import org.junit.gen5.api.Test; 17 | import org.junit.gen5.api.TestReporter; 18 | 19 | class TestReporterDemo { 20 | 21 | @Test 22 | void reportSingleValue(TestReporter testReporter) { 23 | testReporter.publishEntry("a key", "a value"); 24 | } 25 | 26 | @Test 27 | void reportSeveralValues(TestReporter testReporter) { 28 | HashMap values = new HashMap<>(); 29 | values.put("user name", "dk38"); 30 | values.put("award year", "1974"); 31 | 32 | testReporter.publishEntry(values); 33 | } 34 | 35 | } 36 | // end::user_guide[] 37 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/commons/logging/RecordCollectingLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.commons.logging; 12 | 13 | import java.util.LinkedList; 14 | import java.util.List; 15 | import java.util.logging.LogRecord; 16 | import java.util.logging.Logger; 17 | 18 | public class RecordCollectingLogger extends Logger { 19 | 20 | private final List logRecords = new LinkedList<>(); 21 | 22 | public RecordCollectingLogger() { 23 | super("RecordCollectingLogger", null); 24 | } 25 | 26 | @Override 27 | public void log(LogRecord record) { 28 | logRecords.add(record); 29 | } 30 | 31 | public List getLogRecords() { 32 | return logRecords; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/DiscoverySelectorResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import org.junit.gen5.engine.DiscoverySelector; 14 | 15 | abstract class DiscoverySelectorResolver { 16 | 17 | protected final IsPotentialJUnit4TestClass classTester = new IsPotentialJUnit4TestClass(); 18 | private final Class selectorClass; 19 | 20 | DiscoverySelectorResolver(Class selectorClass) { 21 | this.selectorClass = selectorClass; 22 | } 23 | 24 | Class getSelectorClass() { 25 | return selectorClass; 26 | } 27 | 28 | abstract void resolve(T selector, TestClassCollector collector); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/hierarchical/Leaf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.hierarchical; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * A leaf within the execution hierarchy. 19 | * 20 | * @param the type of {@code EngineExecutionContext} used by the {@code HierarchicalTestEngine} 21 | * @since 5.0 22 | * @see HierarchicalTestEngine 23 | * @see Node 24 | * @see Container 25 | */ 26 | @API(Experimental) 27 | public interface Leaf extends Node { 28 | 29 | C execute(C context) throws Exception; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/PackageNameSelectorResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import static org.junit.gen5.commons.util.ReflectionUtils.findAllClassesInPackage; 14 | 15 | import org.junit.gen5.engine.discovery.PackageSelector; 16 | 17 | class PackageNameSelectorResolver extends DiscoverySelectorResolver { 18 | 19 | PackageNameSelectorResolver() { 20 | super(PackageSelector.class); 21 | } 22 | 23 | @Override 24 | void resolve(PackageSelector selector, TestClassCollector collector) { 25 | findAllClassesInPackage(selector.getPackageName(), classTester).forEach(collector::addCompletely); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/exception/IgnoreIOExceptionExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example.exception; 12 | 13 | import java.io.IOException; 14 | 15 | import org.junit.gen5.api.extension.ExceptionHandlerExtensionPoint; 16 | import org.junit.gen5.api.extension.TestExtensionContext; 17 | 18 | // @formatter:off 19 | // tag::user_guide[] 20 | public class IgnoreIOExceptionExtension implements ExceptionHandlerExtensionPoint { 21 | 22 | @Override 23 | public void handleException(TestExtensionContext context, Throwable throwable) 24 | throws Throwable { 25 | 26 | if (throwable instanceof IOException) { 27 | return; 28 | } 29 | throw throwable; 30 | } 31 | } 32 | // end::user_guide[] 33 | // @formatter:on 34 | -------------------------------------------------------------------------------- /junit-commons/src/main/java/org/junit/gen5/commons/JUnitException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.commons; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * Base class for all {@link RuntimeException RuntimeExceptions} thrown 19 | * by JUnit. 20 | * 21 | * @since 5.0 22 | */ 23 | @API(Internal) 24 | public class JUnitException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = -1751494513161886551L; 27 | 28 | public JUnitException(String message) { 29 | super(message); 30 | } 31 | 32 | public JUnitException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit-console/src/main/java/org/junit/gen5/console/tasks/DisplayHelpTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.console.tasks; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.io.PrintWriter; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | import org.junit.gen5.console.options.CommandLineOptionsParser; 19 | 20 | @API(Internal) 21 | public class DisplayHelpTask implements ConsoleTask { 22 | 23 | private final CommandLineOptionsParser parser; 24 | 25 | public DisplayHelpTask(CommandLineOptionsParser parser) { 26 | this.parser = parser; 27 | } 28 | 29 | @Override 30 | public int execute(PrintWriter out) { 31 | parser.printHelp(out); 32 | return SUCCESS; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/ClasspathSelectorResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import static org.junit.gen5.commons.util.ReflectionUtils.findAllClassesInClasspathRoot; 14 | 15 | import org.junit.gen5.engine.discovery.ClasspathSelector; 16 | 17 | class ClasspathSelectorResolver extends DiscoverySelectorResolver { 18 | 19 | ClasspathSelectorResolver() { 20 | super(ClasspathSelector.class); 21 | } 22 | 23 | @Override 24 | void resolve(ClasspathSelector selector, TestClassCollector collector) { 25 | findAllClassesInClasspathRoot(selector.getClasspathRoot(), classTester).forEach(collector::addCompletely); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/TestTagTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.gen5.api.Assertions.assertNotEquals; 15 | 16 | import org.junit.gen5.api.Test; 17 | 18 | class TestTagTests { 19 | 20 | @Test 21 | void tagEqualsOtherTagsWithSameName() { 22 | assertEquals(new TestTag("fast"), new TestTag("fast")); 23 | assertEquals(new TestTag("fast").hashCode(), new TestTag("fast").hashCode()); 24 | assertNotEquals(null, new TestTag("fast")); 25 | assertNotEquals(new TestTag("fast"), null); 26 | } 27 | 28 | @Test 29 | void toStringPrintsName() { 30 | assertEquals("fast", new TestTag("fast").toString()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/ExtensionConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.JUnitException; 16 | import org.junit.gen5.commons.meta.API; 17 | 18 | /** 19 | * Thrown if an error is encountered regarding the configuration of an 20 | * extension. 21 | * 22 | * @since 5.0 23 | */ 24 | @API(Experimental) 25 | public class ExtensionConfigurationException extends JUnitException { 26 | 27 | private static final long serialVersionUID = -2902318452924798975L; 28 | 29 | public ExtensionConfigurationException(String message) { 30 | super(message); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/discovery/ClassFilterTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.discovery; 12 | 13 | import static org.junit.gen5.api.Assertions.*; 14 | 15 | import java.util.Collection; 16 | 17 | import org.junit.gen5.api.Test; 18 | import org.junit.gen5.engine.discovery.ClassFilter; 19 | 20 | class ClassFilterTests { 21 | @Test 22 | void classNameMatches() { 23 | String regex = "^java\\.lang\\..*"; 24 | 25 | ClassFilter filter = ClassFilter.byNamePattern(regex); 26 | 27 | assertEquals("Filter class names with regular expression: " + regex, filter.toString()); 28 | assertTrue(filter.filter(String.class).included()); 29 | assertFalse(filter.filter(Collection.class).included()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/IsPotentialJUnit4TestClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import static org.junit.gen5.commons.util.ReflectionUtils.isAbstract; 14 | import static org.junit.gen5.commons.util.ReflectionUtils.isPublic; 15 | 16 | import java.util.function.Predicate; 17 | 18 | /** 19 | * @since 5.0 20 | */ 21 | class IsPotentialJUnit4TestClass implements Predicate> { 22 | 23 | @Override 24 | public boolean test(Class candidate) { 25 | // Do not collapse into single return. 26 | if (isAbstract(candidate)) 27 | return false; 28 | if (!isPublic(candidate)) 29 | return false; 30 | return !candidate.isMemberClass(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/Nested.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | import org.junit.gen5.commons.meta.API; 22 | 23 | /** 24 | * {@code @Nested} is used to signal that the annotated class is a nested, 25 | * non-static test class. 26 | * 27 | * @since 5.0 28 | */ 29 | @Target(ElementType.TYPE) 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Documented 32 | @API(Experimental) 33 | public @interface Nested { 34 | } 35 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/DocumentationTestSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | import org.junit.gen5.junit4.runner.JUnit5; 14 | import org.junit.gen5.junit4.runner.Packages; 15 | import org.junit.runner.RunWith; 16 | 17 | /** 18 | *

Logging Configuration

19 | * 20 | *

In order for our log4j2 configuration to be used in an IDE, you must 21 | * set the following system property before running any tests — for 22 | * example, in Run Configurations in Eclipse. 23 | * 24 | *

25 |  * -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
26 |  * 
27 | * 28 | * @since 5.0 29 | */ 30 | @RunWith(JUnit5.class) 31 | @Packages("example") 32 | public class DocumentationTestSuite { 33 | } 34 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/Filter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.util.function.Predicate; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | /** 20 | * Filters particular tests during/after test discovery. 21 | * 22 | *

Clients should not implement this interface directly but rather one of 23 | * its subinterfaces. 24 | * 25 | * @since 5.0 26 | * @see DiscoveryFilter 27 | */ 28 | @FunctionalInterface 29 | @API(Internal) 30 | public interface Filter { 31 | 32 | FilterResult filter(T object); 33 | 34 | default Predicate toPredicate() { 35 | return object -> filter(object).included(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /junit-launcher/src/main/java/org/junit/gen5/launcher/PostDiscoveryFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.launcher; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.engine.Filter; 17 | import org.junit.gen5.engine.TestDescriptor; 18 | import org.junit.gen5.engine.TestEngine; 19 | 20 | /** 21 | * A {@code PostDiscoveryFilter} filters particular tests after test discovery. 22 | * These filters must not be applied by the {@link TestEngine} during test 23 | * discovery. 24 | * 25 | * @since 5.0 26 | * @see TestDiscoveryRequest 27 | * @see TestEngine 28 | */ 29 | @API(Experimental) 30 | public interface PostDiscoveryFilter extends Filter { 31 | } 32 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/commons/util/ExceptionUtilsTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.commons.util; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import org.junit.gen5.api.Test; 16 | import org.junit.gen5.commons.JUnitException; 17 | 18 | class ExceptionUtilsTests { 19 | 20 | @Test 21 | void readStackTrace() { 22 | try { 23 | throw new JUnitException("expected"); 24 | } 25 | catch (JUnitException e) { 26 | String stackTrace = ExceptionUtils.readStackTrace(e); 27 | // @formatter:off 28 | assertThat(stackTrace) 29 | .startsWith(JUnitException.class.getName() + ": expected") 30 | .contains("at " + ExceptionUtilsTests.class.getName()); 31 | // @formatter:on 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4TestCaseWithErrorInAfterClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.fail; 14 | import static org.junit.runners.MethodSorters.NAME_ASCENDING; 15 | 16 | import org.junit.AfterClass; 17 | import org.junit.FixMethodOrder; 18 | import org.junit.Test; 19 | 20 | @FixMethodOrder(NAME_ASCENDING) 21 | public class JUnit4TestCaseWithErrorInAfterClass { 22 | 23 | @AfterClass 24 | public static void failingAfterClass() { 25 | fail("error in @AfterClass"); 26 | } 27 | 28 | @Test 29 | public void failingTest() { 30 | fail("expected to fail"); 31 | } 32 | 33 | @Test 34 | public void succeedingTest() { 35 | // no-op 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/discovery/UniqueIdSelector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.engine.DiscoverySelector; 17 | 18 | /** 19 | * @since 5.0 20 | */ 21 | @API(Experimental) 22 | public class UniqueIdSelector implements DiscoverySelector { 23 | 24 | public static UniqueIdSelector forUniqueId(String uniqueId) { 25 | return new UniqueIdSelector(uniqueId); 26 | } 27 | 28 | private final String uniqueId; 29 | 30 | private UniqueIdSelector(String uniqueId) { 31 | this.uniqueId = uniqueId; 32 | } 33 | 34 | public String getUniqueId() { 35 | return uniqueId; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/EngineDiscoveryRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | /** 20 | * An {@code EngineDiscoveryRequest} gives {@link TestEngine}s 21 | * access to the information necessary to discover {@link TestDescriptor}s. 22 | * 23 | * @since 5.0 24 | */ 25 | @API(Experimental) 26 | public interface EngineDiscoveryRequest { 27 | 28 | List getSelectors(); 29 | 30 | List getSelectorsByType(Class selectorType); 31 | 32 | > List getDiscoveryFiltersByType(Class filterType); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/discovery/PackageSelector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.engine.DiscoverySelector; 17 | 18 | /** 19 | * @since 5.0 20 | */ 21 | @API(Experimental) 22 | public class PackageSelector implements DiscoverySelector { 23 | 24 | public static PackageSelector forPackageName(String packageName) { 25 | return new PackageSelector(packageName); 26 | } 27 | 28 | private final String packageName; 29 | 30 | private PackageSelector(String packageName) { 31 | this.packageName = packageName; 32 | } 33 | 34 | public String getPackageName() { 35 | return packageName; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit-console/src/main/java/org/junit/gen5/console/tasks/ConsoleTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.console.tasks; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.io.PrintWriter; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | /** 20 | * A task to be executed from the console. 21 | */ 22 | @API(Internal) 23 | public interface ConsoleTask { 24 | 25 | /** 26 | * Exit code indicating successful execution 27 | */ 28 | int SUCCESS = 0; 29 | 30 | /** 31 | * Execute this task and return an exit code. 32 | * 33 | * @param out writer for console output 34 | * @return exit code indicating success ({@code 0}) or failure ({@code != 0}) 35 | * @see ConsoleTask#SUCCESS 36 | */ 37 | int execute(PrintWriter out) throws Exception; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/JUnit4TestCaseWithOverloadedMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import org.junit.experimental.theories.DataPoint; 16 | import org.junit.experimental.theories.Theories; 17 | import org.junit.experimental.theories.Theory; 18 | import org.junit.runner.RunWith; 19 | 20 | @RunWith(Theories.class) 21 | public class JUnit4TestCaseWithOverloadedMethod { 22 | 23 | @DataPoint 24 | public static int MAGIC_NUMBER = 42; 25 | 26 | @Theory 27 | public void theory(int i) { 28 | fail("failing theory with single parameter"); 29 | } 30 | 31 | @Theory 32 | public void theory(int i, int j) { 33 | fail("failing theory with two parameters"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/TestClassRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import static java.util.Collections.emptyList; 14 | 15 | import java.util.List; 16 | 17 | class TestClassRequest { 18 | 19 | private final Class testClass; 20 | private final List filters; 21 | 22 | TestClassRequest(Class testClass) { 23 | this(testClass, emptyList()); 24 | } 25 | 26 | TestClassRequest(Class testClass, List filters) { 27 | this.testClass = testClass; 28 | this.filters = filters; 29 | } 30 | 31 | Class getTestClass() { 32 | return testClass; 33 | } 34 | 35 | List getFilters() { 36 | return filters; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/launcher/TestIdentifierTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.launcher; 12 | 13 | import static org.junit.gen5.api.Assertions.assertEquals; 14 | 15 | import org.junit.gen5.api.Test; 16 | import org.junit.gen5.engine.TestDescriptor; 17 | import org.junit.gen5.engine.TestDescriptorStub; 18 | 19 | class TestIdentifierTests { 20 | 21 | @Test 22 | public void inheritsIdAndNamesFromDescriptor() { 23 | TestDescriptor testDescriptor = new TestDescriptorStub("uniqueId", "name", "displayName"); 24 | 25 | TestIdentifier testIdentifier = TestIdentifier.from(testDescriptor); 26 | 27 | assertEquals(new TestId("uniqueId"), testIdentifier.getUniqueId()); 28 | assertEquals("displayName", testIdentifier.getDisplayName()); 29 | assertEquals("name", testIdentifier.getName()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit4/samples/junit4/ParameterizedTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.samples.junit4; 12 | 13 | import static java.util.Arrays.asList; 14 | import static org.junit.Assert.assertEquals; 15 | 16 | import org.junit.Test; 17 | import org.junit.runner.RunWith; 18 | import org.junit.runners.Parameterized; 19 | import org.junit.runners.Parameterized.Parameter; 20 | import org.junit.runners.Parameterized.Parameters; 21 | 22 | @RunWith(Parameterized.class) 23 | public class ParameterizedTestCase { 24 | 25 | @Parameters(name = "{0}") 26 | public static Iterable primes() { 27 | return asList("foo", "bar"); 28 | } 29 | 30 | @Parameter 31 | public String value; 32 | 33 | @Test 34 | public void test() { 35 | assertEquals("foo", value); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/stubs/TestEngineStub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.stubs; 12 | 13 | import org.junit.gen5.engine.EngineDiscoveryRequest; 14 | import org.junit.gen5.engine.ExecutionRequest; 15 | import org.junit.gen5.engine.TestDescriptor; 16 | import org.junit.gen5.engine.TestEngine; 17 | 18 | /** 19 | * @since 5.0 20 | */ 21 | public class TestEngineStub implements TestEngine { 22 | 23 | public static final String TEST_ENGINE_DUMMY_ID = "TestEngineDummyID"; 24 | 25 | @Override 26 | public String getId() { 27 | return TEST_ENGINE_DUMMY_ID; 28 | } 29 | 30 | @Override 31 | public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest) { 32 | return null; 33 | } 34 | 35 | @Override 36 | public void execute(ExecutionRequest request) { 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit-commons/src/main/java/org/junit/gen5/commons/util/PreconditionViolationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.commons.util; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import org.junit.gen5.commons.JUnitException; 16 | import org.junit.gen5.commons.meta.API; 17 | 18 | /** 19 | * Thrown if a precondition is violated. 20 | * 21 | * @since 5.0 22 | * @see Preconditions 23 | */ 24 | @API(Internal) 25 | public class PreconditionViolationException extends JUnitException { 26 | 27 | private static final long serialVersionUID = 5652830566059484475L; 28 | 29 | public PreconditionViolationException(String message) { 30 | super(message); 31 | } 32 | 33 | public PreconditionViolationException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/JUnit5Method.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | import java.lang.reflect.Method; 14 | 15 | class JUnit5Method extends JUnit5Testable { 16 | 17 | private final Class containerClass; 18 | 19 | private final Method javaMethod; 20 | 21 | JUnit5Method(String uniqueId, Method javaElement, Class containerClass) { 22 | super(uniqueId); 23 | this.javaMethod = javaElement; 24 | this.containerClass = containerClass; 25 | } 26 | 27 | @Override 28 | void accept(Visitor visitor) { 29 | visitor.visitMethod(getUniqueId(), this.javaMethod, this.containerClass); 30 | } 31 | 32 | public Method getJavaMethod() { 33 | return javaMethod; 34 | } 35 | 36 | public Class getContainerClass() { 37 | return containerClass; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/hierarchical/Container.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.hierarchical; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * A container within the execution hierarchy. 19 | * 20 | * @param the type of {@code EngineExecutionContext} used by the {@code HierarchicalTestEngine} 21 | * @since 5.0 22 | * @see HierarchicalTestEngine 23 | * @see Node 24 | * @see Leaf 25 | */ 26 | @API(Experimental) 27 | public interface Container extends Node { 28 | 29 | default C beforeAll(C context) throws Exception { 30 | return context; 31 | } 32 | 33 | default C afterAll(C context) throws Exception { 34 | return context; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/TestInfoDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // tag::user_guide[] 14 | import static org.junit.gen5.api.Assertions.assertEquals; 15 | import static org.junit.gen5.api.Assertions.assertTrue; 16 | 17 | import org.junit.gen5.api.BeforeEach; 18 | import org.junit.gen5.api.DisplayName; 19 | import org.junit.gen5.api.Test; 20 | import org.junit.gen5.api.TestInfo; 21 | 22 | class TestInfoDemo { 23 | 24 | @BeforeEach 25 | void init(TestInfo testInfo) { 26 | String displayName = testInfo.getDisplayName(); 27 | assertTrue(displayName.equals("TEST 1") || displayName.equals("test2")); 28 | } 29 | 30 | @Test 31 | @DisplayName("TEST 1") 32 | void test1(TestInfo testInfo) { 33 | assertEquals("TEST 1", testInfo.getDisplayName()); 34 | } 35 | 36 | @Test 37 | void test2() { 38 | } 39 | 40 | } 41 | // end::user_guide[] 42 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/launcher/DiscoveryFilterMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.launcher; 12 | 13 | import java.util.function.Function; 14 | import java.util.function.Supplier; 15 | 16 | import org.junit.gen5.engine.DiscoveryFilter; 17 | import org.junit.gen5.engine.FilterResult; 18 | 19 | public class DiscoveryFilterMock implements DiscoveryFilter { 20 | private final Function function; 21 | private final Supplier toString; 22 | 23 | public DiscoveryFilterMock(Function function, Supplier toString) { 24 | this.function = function; 25 | this.toString = toString; 26 | } 27 | 28 | @Override 29 | public FilterResult filter(Object object) { 30 | return function.apply(object); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return toString.get(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/ParameterResolutionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.JUnitException; 16 | import org.junit.gen5.commons.meta.API; 17 | 18 | /** 19 | * Thrown if an error is encountered in the configuration or execution of a 20 | * {@link MethodParameterResolver}. 21 | * 22 | * @since 5.0 23 | * @see MethodParameterResolver 24 | */ 25 | @API(Experimental) 26 | public class ParameterResolutionException extends JUnitException { 27 | 28 | private static final long serialVersionUID = 5137237798019406636L; 29 | 30 | public ParameterResolutionException(String message) { 31 | super(message); 32 | } 33 | 34 | public ParameterResolutionException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/execution/ConditionEvaluationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.execution; 12 | 13 | import org.junit.gen5.api.extension.ContainerExecutionCondition; 14 | import org.junit.gen5.api.extension.TestExecutionCondition; 15 | import org.junit.gen5.commons.JUnitException; 16 | 17 | /** 18 | * Thrown if an error is encountered while evaluating a {@link ContainerExecutionCondition} 19 | * or {@link TestExecutionCondition}. 20 | * 21 | * @since 5.0 22 | * @see ConditionEvaluator 23 | */ 24 | class ConditionEvaluationException extends JUnitException { 25 | 26 | private static final long serialVersionUID = 7541146267089707036L; 27 | 28 | public ConditionEvaluationException(String message) { 29 | super(message); 30 | } 31 | 32 | public ConditionEvaluationException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/ExtensionRegistrar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * Interface to be implemented by {@linkplain Extension extensions} that 19 | * wish to programmatically register {@link ExtensionPoint} implementations 20 | * in the {@link ExtensionPointRegistry} — for example, if a 21 | * {@link ExtensionPointRegistry.Position Position} other than 22 | * {@link ExtensionPointRegistry.Position#DEFAULT DEFAULT} is desired. 23 | * 24 | *

An {@code ExtensionRegistrar} can be registered via {@link ExtendWith @ExtendWith}. 25 | * 26 | * @since 5.0 27 | */ 28 | @API(Experimental) 29 | public interface ExtensionRegistrar extends Extension { 30 | 31 | void registerExtensions(ExtensionPointRegistry registry); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /junit4-runner/src/main/java/org/junit/gen5/junit4/runner/Classes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.junit4.runner; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @Classes} specifies the test classes to be run when a class 26 | * annotated with {@code @RunWith(JUnit5.class)} is run. 27 | * 28 | * @since 5.0 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.TYPE) 32 | @Inherited 33 | @Documented 34 | @API(Maintained) 35 | public @interface Classes { 36 | 37 | /** 38 | * One or more test classes. 39 | */ 40 | Class[]value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit4-runner/src/main/java/org/junit/gen5/junit4/runner/Packages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.junit4.runner; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @Packages} specifies the names of packages to be run when a class 26 | * annotated with {@code @RunWith(JUnit5.class)} is run. 27 | * 28 | * @since 5.0 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.TYPE) 32 | @Inherited 33 | @Documented 34 | @API(Maintained) 35 | public @interface Packages { 36 | 37 | /** 38 | * One or more package names. 39 | */ 40 | String[]value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/OrFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import static java.util.stream.Collectors.joining; 14 | 15 | import java.util.Collection; 16 | 17 | import org.junit.gen5.commons.util.Preconditions; 18 | import org.junit.runner.Description; 19 | import org.junit.runner.manipulation.Filter; 20 | 21 | class OrFilter extends Filter { 22 | 23 | private final Collection filters; 24 | 25 | OrFilter(Collection filters) { 26 | this.filters = Preconditions.notEmpty(filters, "filters must not be empty"); 27 | } 28 | 29 | @Override 30 | public boolean shouldRun(Description description) { 31 | return filters.stream().anyMatch(filter -> filter.shouldRun(description)); 32 | } 33 | 34 | @Override 35 | public String describe() { 36 | return filters.stream().map(Filter::describe).collect(joining(" OR ")); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit4-runner/src/main/java/org/junit/gen5/junit4/runner/ExcludeTags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.junit4.runner; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @ExcludeTags} specifies tags to be filtered out when a class 26 | * annotated with {@code @RunWith(JUnit5.class)} is run. 27 | * 28 | * @since 5.0 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.TYPE) 32 | @Inherited 33 | @Documented 34 | @API(Maintained) 35 | public @interface ExcludeTags { 36 | 37 | /** 38 | * One or more tags to exclude. 39 | */ 40 | String[]value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit4-runner/src/main/java/org/junit/gen5/junit4/runner/RequireTags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.junit4.runner; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @RequireTags} specifies tags to be considered when a class 26 | * annotated with {@code @RunWith(JUnit5.class)} is run. 27 | * 28 | * @since 5.0 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.TYPE) 32 | @Inherited 33 | @Documented 34 | @API(Maintained) 35 | public @interface RequireTags { 36 | 37 | /** 38 | * One or more tags to be required. 39 | */ 40 | String[]value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/descriptor/EngineDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.descriptor; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * @since 5.0 19 | */ 20 | @API(Experimental) 21 | public class EngineDescriptor extends AbstractTestDescriptor { 22 | 23 | private final String displayName; 24 | 25 | public EngineDescriptor(String uniqueId, String displayName) { 26 | super(uniqueId); 27 | this.displayName = displayName; 28 | } 29 | 30 | @Override 31 | public String getName() { 32 | return displayName; 33 | } 34 | 35 | @Override 36 | public String getDisplayName() { 37 | return displayName; 38 | } 39 | 40 | @Override 41 | public final boolean isTest() { 42 | return false; 43 | } 44 | 45 | @Override 46 | public boolean isContainer() { 47 | return true; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/discovery/ClassNameFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.discovery; 12 | 13 | import static org.junit.gen5.engine.FilterResult.includedIf; 14 | 15 | import java.util.regex.Pattern; 16 | 17 | import org.junit.gen5.engine.FilterResult; 18 | 19 | /** 20 | * @since 5.0 21 | */ 22 | class ClassNameFilter implements ClassFilter { 23 | 24 | private final Pattern pattern; 25 | 26 | ClassNameFilter(String pattern) { 27 | this.pattern = Pattern.compile(pattern); 28 | } 29 | 30 | @Override 31 | public FilterResult filter(Class testClass) { 32 | return includedIf(pattern.matcher(testClass.getName()).matches(), // 33 | () -> "Test class matches name pattern: " + pattern, // 34 | () -> "Test class does not match name pattern: " + pattern); 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Filter class names with regular expression: " + pattern; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/ExtensionPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * Super interface for all extension points. 19 | * 20 | *

An {@code ExtensionPoint} can be registered declaratively via 21 | * {@link ExtendWith @ExtendWith} or programmatically via an 22 | * {@link ExtensionRegistrar}. 23 | * 24 | * @since 5.0 25 | * @see ContainerExecutionCondition 26 | * @see TestExecutionCondition 27 | * @see InstancePostProcessor 28 | * @see ExceptionHandlerExtensionPoint 29 | * @see MethodParameterResolver 30 | * @see BeforeEachExtensionPoint 31 | * @see AfterEachExtensionPoint 32 | * @see BeforeAllExtensionPoint 33 | * @see AfterAllExtensionPoint 34 | * @see ExtensionRegistrar 35 | */ 36 | @API(Experimental) 37 | public interface ExtensionPoint extends Extension { 38 | } 39 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/IsScannableTestClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.util.function.Predicate; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | import org.junit.gen5.commons.util.ReflectionUtils; 19 | 20 | /** 21 | * Test if a class is a JUnit 5 test class which should be included in package and classpath scanning. 22 | * 23 | * @since 5.0 24 | */ 25 | @API(Internal) 26 | public class IsScannableTestClass implements Predicate> { 27 | 28 | private static final IsTestClassWithTests isTestClassWithTests = new IsTestClassWithTests(); 29 | 30 | @Override 31 | public boolean test(Class candidate) { 32 | //please do not collapse into single return 33 | if (ReflectionUtils.isPrivate(candidate)) 34 | return false; 35 | return isTestClassWithTests.test(candidate); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /documentation/src/docs/asciidoc/overview.adoc: -------------------------------------------------------------------------------- 1 | [[overview]] 2 | == Overview 3 | 4 | The goal of this document is to provide comprehensive reference documentation for both 5 | programmers writing tests and extension authors. 6 | 7 | === Supported Java Versions 8 | 9 | JUnit 5 only supports Java 8 and above. However, you can still test classes compiled with 10 | lower versions. 11 | 12 | 13 | == Installation 14 | 15 | Snapshot artifacts are deployed to Sonatype's {snapshot-repo}[snapshots repository]. 16 | 17 | [[dependency-metadata]] 18 | === Dependency Metadata 19 | 20 | * *Group ID*: `org.junit` 21 | * *Version*: `{junit-version}` 22 | * *Artifact IDs*: 23 | ** `junit-commons` 24 | ** `junit-console` 25 | ** `junit-engine-api` 26 | ** `junit-gradle` 27 | ** `junit-launcher` 28 | ** `junit4-engine` 29 | ** `junit4-runner` 30 | ** `junit5-api` 31 | ** `junit5-engine` 32 | ** `surefire-junit5` 33 | 34 | See also: {snapshot-repo}/org/junit/ 35 | 36 | === JUnit 5 Sample Projects 37 | 38 | The {junit5-samples-repo}[`junit5-samples`] repository hosts a collection of sample 39 | projects based on JUnit 5. You'll find the respective `build.gradle` and `pom.xml` in 40 | the projects below. 41 | 42 | * For Gradle, check out the `{junit5-gradle-consumer}` project. 43 | * For Maven, check out the `{junit5-maven-consumer}` project. 44 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/RunnerTestDescriptorAwareFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import org.junit.gen5.engine.junit4.descriptor.RunnerTestDescriptor; 14 | import org.junit.runner.Description; 15 | import org.junit.runner.manipulation.Filter; 16 | 17 | abstract class RunnerTestDescriptorAwareFilter extends Filter { 18 | 19 | abstract void initialize(RunnerTestDescriptor runnerTestDescriptor); 20 | 21 | static RunnerTestDescriptorAwareFilter adapter(Filter filter) { 22 | return new RunnerTestDescriptorAwareFilter() { 23 | @Override 24 | void initialize(RunnerTestDescriptor runnerTestDescriptor) { 25 | // do nothing 26 | } 27 | 28 | @Override 29 | public boolean shouldRun(Description description) { 30 | return filter.shouldRun(description); 31 | } 32 | 33 | @Override 34 | public String describe() { 35 | return filter.describe(); 36 | } 37 | }; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/TestDescriptorStub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import org.junit.gen5.engine.support.descriptor.AbstractTestDescriptor; 14 | 15 | public final class TestDescriptorStub extends AbstractTestDescriptor { 16 | 17 | private final String name; 18 | private final String displayName; 19 | 20 | public TestDescriptorStub(String uniqueId) { 21 | this(uniqueId, uniqueId, uniqueId); 22 | } 23 | 24 | public TestDescriptorStub(String uniqueId, String name, String displayName) { 25 | super(uniqueId); 26 | this.name = name; 27 | this.displayName = displayName; 28 | } 29 | 30 | @Override 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | @Override 36 | public String getDisplayName() { 37 | return displayName; 38 | } 39 | 40 | @Override 41 | public boolean isTest() { 42 | return getChildren().isEmpty(); 43 | } 44 | 45 | @Override 46 | public boolean isContainer() { 47 | return !isTest(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/execution/injection/sample/CustomTypeParameterResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.execution.injection.sample; 12 | 13 | import java.lang.reflect.Parameter; 14 | 15 | import org.junit.gen5.api.extension.ExtensionContext; 16 | import org.junit.gen5.api.extension.MethodInvocationContext; 17 | import org.junit.gen5.api.extension.MethodParameterResolver; 18 | 19 | /** 20 | * @since 5.0 21 | */ 22 | public class CustomTypeParameterResolver implements MethodParameterResolver { 23 | 24 | @Override 25 | public boolean supports(Parameter parameter, MethodInvocationContext methodInvocationContext, 26 | ExtensionContext extensionContext) { 27 | 28 | return parameter.getType().equals(CustomType.class); 29 | } 30 | 31 | @Override 32 | public Object resolve(Parameter parameter, MethodInvocationContext methodInvocationContext, 33 | ExtensionContext extensionContext) { 34 | 35 | return new CustomType(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /junit4-runner/src/main/java/org/junit/gen5/junit4/runner/UniqueIds.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.junit4.runner; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @UniqueIds} specifies the unique IDs of test classes or methods to be 26 | * run when a class annotated with {@code @RunWith(JUnit5.class)} is run. 27 | * 28 | * @since 5.0 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.TYPE) 32 | @Inherited 33 | @Documented 34 | @API(Maintained) 35 | public @interface UniqueIds { 36 | 37 | /** 38 | * One or more unique IDs of test classes or test methods. 39 | */ 40 | String[]value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit-launcher/src/main/java/org/junit/gen5/launcher/main/ServiceLoaderTestEngineRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.launcher.main; 12 | 13 | import static java.util.stream.Collectors.toList; 14 | import static java.util.stream.StreamSupport.stream; 15 | 16 | import java.util.ServiceLoader; 17 | import java.util.logging.Logger; 18 | 19 | import org.junit.gen5.commons.util.ReflectionUtils; 20 | import org.junit.gen5.engine.TestEngine; 21 | 22 | /** 23 | * @since 5.0 24 | */ 25 | class ServiceLoaderTestEngineRegistry { 26 | 27 | private static final Logger LOG = Logger.getLogger(ServiceLoaderTestEngineRegistry.class.getName()); 28 | 29 | public Iterable loadTestEngines() { 30 | Iterable testEngines = ServiceLoader.load(TestEngine.class, 31 | ReflectionUtils.getDefaultClassLoader()); 32 | LOG.info(() -> "Discovered TestEngines with IDs " 33 | + stream(testEngines.spliterator(), false).map(TestEngine::getId).collect(toList())); 34 | return testEngines; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/AllJUnit5Tests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5; 12 | 13 | import org.junit.gen5.engine.junit5.JUnit5TestEngine; 14 | import org.junit.gen5.junit4.runner.FilterClassName; 15 | import org.junit.gen5.junit4.runner.JUnit5; 16 | import org.junit.gen5.junit4.runner.Packages; 17 | import org.junit.gen5.junit4.runner.RequireEngine; 18 | import org.junit.runner.RunWith; 19 | 20 | /** 21 | *

Logging Configuration

22 | * 23 | *

In order for our log4j2 configuration to be used in an IDE, you must 24 | * set the following system property before running any tests — for 25 | * example, in Run Configurations in Eclipse. 26 | * 27 | *

28 |  * -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
29 |  * 
30 | * 31 | * @since 5.0 32 | */ 33 | @RunWith(JUnit5.class) 34 | @Packages("org.junit.gen5") 35 | @FilterClassName(".*Tests?") 36 | @RequireEngine(JUnit5TestEngine.ENGINE_ID) 37 | public class AllJUnit5Tests { 38 | } 39 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/TestTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.io.Serializable; 16 | import java.util.Objects; 17 | 18 | import org.junit.gen5.commons.meta.API; 19 | 20 | @API(Experimental) 21 | public final class TestTag implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | private final String name; 26 | 27 | public TestTag(String name) { 28 | this.name = name; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | @Override 36 | public boolean equals(Object obj) { 37 | if (obj instanceof TestTag) { 38 | TestTag that = (TestTag) obj; 39 | return Objects.equals(this.name, that.name); 40 | } 41 | return false; 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return name.hashCode(); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return name; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/DisplayName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | import org.junit.gen5.commons.meta.API; 22 | 23 | /** 24 | * {@code @DisplayName} is used to declare a custom display name for the 25 | * annotated test class or test method. 26 | * 27 | *

Display names are typically used for test reporting in IDEs and build 28 | * tools and may contain spaces, special characters, and even emoji. 29 | * 30 | * @since 5.0 31 | * @see Test 32 | * @see TestInfo 33 | */ 34 | @Target({ ElementType.TYPE, ElementType.METHOD }) 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Documented 37 | @API(Experimental) 38 | public @interface DisplayName { 39 | 40 | String value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/IsPotentialTestContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | import static org.junit.gen5.commons.util.ReflectionUtils.isAbstract; 15 | import static org.junit.gen5.commons.util.ReflectionUtils.isStatic; 16 | 17 | import java.util.function.Predicate; 18 | 19 | import org.junit.gen5.commons.meta.API; 20 | 21 | /** 22 | * Test if a class is a potential top-level JUnit 5 test container, even if 23 | * it does not contain tests. 24 | * 25 | * @since 5.0 26 | */ 27 | @API(Internal) 28 | public class IsPotentialTestContainer implements Predicate> { 29 | 30 | @Override 31 | public boolean test(Class candidate) { 32 | //please do not collapse into single return 33 | if (isAbstract(candidate)) 34 | return false; 35 | if (candidate.isLocalClass()) 36 | return false; 37 | return (isStatic(candidate) || !candidate.isMemberClass()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/Disabled.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Stable; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | import org.junit.gen5.commons.meta.API; 22 | 23 | /** 24 | * {@code @Disabled} is used to signal that the annotated test class or 25 | * test method is currently disabled and should not be executed. 26 | * 27 | *

When applied at the class level, all test methods within that class 28 | * are automatically disabled as well. 29 | * 30 | * @since 5.0 31 | */ 32 | @Target({ ElementType.TYPE, ElementType.METHOD }) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Documented 35 | @API(Stable) 36 | public @interface Disabled { 37 | 38 | /** 39 | * The reason this test is disabled. 40 | */ 41 | String value() default ""; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/JUnit5EngineDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.engine.junit5.execution.JUnit5EngineExecutionContext; 17 | import org.junit.gen5.engine.junit5.extension.ExtensionRegistry; 18 | import org.junit.gen5.engine.support.descriptor.EngineDescriptor; 19 | import org.junit.gen5.engine.support.hierarchical.Container; 20 | 21 | /** 22 | * @since 5.0 23 | */ 24 | @API(Internal) 25 | public class JUnit5EngineDescriptor extends EngineDescriptor implements Container { 26 | 27 | public JUnit5EngineDescriptor(String uniqueId) { 28 | super(uniqueId, "JUnit 5"); 29 | } 30 | 31 | @Override 32 | public JUnit5EngineExecutionContext beforeAll(JUnit5EngineExecutionContext context) { 33 | return context.extend().withExtensionRegistry(new ExtensionRegistry()).build(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /junit4-runner/src/main/java/org/junit/gen5/junit4/runner/RequireEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.junit4.runner; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @RequireEngine} specifies the engine ID (e.g., {@code "junit5"}) of 26 | * the sole {@link org.junit.gen5.engine.TestEngine TestEngine} to be used 27 | * when a class annotated with {@code @RunWith(JUnit5.class)} is run. 28 | * 29 | * @since 5.0 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target(ElementType.TYPE) 33 | @Inherited 34 | @Documented 35 | @API(Maintained) 36 | public @interface RequireEngine { 37 | 38 | /** 39 | * The Engine ID to be required 40 | */ 41 | String value(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/console/tasks/IncrementingClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.console.tasks; 12 | 13 | import java.time.Clock; 14 | import java.time.Duration; 15 | import java.time.Instant; 16 | import java.time.ZoneId; 17 | 18 | final class IncrementingClock extends Clock { 19 | 20 | private final Duration duration; 21 | private final ZoneId zone; 22 | 23 | private int counter; 24 | 25 | public IncrementingClock(int start, Duration duration) { 26 | this(start, duration, ZoneId.systemDefault()); 27 | } 28 | 29 | public IncrementingClock(int start, Duration duration, ZoneId zone) { 30 | this.counter = start; 31 | this.duration = duration; 32 | this.zone = zone; 33 | } 34 | 35 | @Override 36 | public Instant instant() { 37 | return Instant.EPOCH.plus(duration.multipliedBy(counter++)); 38 | } 39 | 40 | @Override 41 | public Clock withZone(ZoneId zone) { 42 | return new IncrementingClock(counter, duration, zone); 43 | } 44 | 45 | @Override 46 | public ZoneId getZone() { 47 | return zone; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/MethodSelectorResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import static org.junit.gen5.engine.junit4.discovery.RunnerTestDescriptorAwareFilter.adapter; 14 | import static org.junit.runner.manipulation.Filter.matchMethodDescription; 15 | 16 | import java.lang.reflect.Method; 17 | 18 | import org.junit.gen5.engine.discovery.MethodSelector; 19 | import org.junit.runner.Description; 20 | 21 | class MethodSelectorResolver extends DiscoverySelectorResolver { 22 | 23 | MethodSelectorResolver() { 24 | super(MethodSelector.class); 25 | } 26 | 27 | @Override 28 | void resolve(MethodSelector selector, TestClassCollector collector) { 29 | Class testClass = selector.getTestClass(); 30 | Method testMethod = selector.getTestMethod(); 31 | Description methodDescription = Description.createTestDescription(testClass, testMethod.getName()); 32 | collector.addFiltered(testClass, adapter(matchMethodDescription(methodDescription))); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/TestReporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.util.*; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | /** 20 | * Parameters of type {@code TestReporter} can be injected into methods of 21 | * test classes annotated with {@link BeforeEach @BeforeEach}, 22 | * {@link AfterEach @AfterEach}, and {@link Test @Test}. 23 | * 24 | *

Within such methods this instance of type {@code TestReporter} can be 25 | * used to publish report entries. 26 | * 27 | * @since 5.0 28 | */ 29 | @FunctionalInterface 30 | @API(Experimental) 31 | public interface TestReporter { 32 | 33 | /** 34 | * Publish the supplied values as a report entry. 35 | * 36 | * @param values the map to be published for this entry 37 | */ 38 | void publishEntry(Map values); 39 | 40 | default void publishEntry(String key, String value) { 41 | this.publishEntry(Collections.singletonMap(key, value)); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/InstancePostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * {@code InstancePostProcessor} defines the API for {@link Extension 19 | * Extensions} that wish to post-process test instances. 20 | * 21 | *

Common use cases include injecting dependencies into the test 22 | * instance, invoking custom initialization methods on the test instance, 23 | * etc. 24 | * 25 | *

Implementations must provide a no-args constructor. 26 | * 27 | * @since 5.0 28 | */ 29 | @API(Experimental) 30 | public interface InstancePostProcessor extends ExtensionPoint { 31 | 32 | /** 33 | * Callback for post-processing the test instance in the supplied 34 | * {@link TestExtensionContext}. 35 | * 36 | * @param context the current test extension context 37 | */ 38 | void postProcessTestInstance(TestExtensionContext context) throws Exception; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/AssumptionsDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | // @formatter:off 14 | // tag::user_guide[] 15 | import static org.junit.gen5.api.Assertions.assertEquals; 16 | import static org.junit.gen5.api.Assumptions.*; 17 | 18 | import org.junit.gen5.api.Test; 19 | 20 | public class AssumptionsDemo { 21 | 22 | @Test 23 | void testOnlyOnCiServer() { 24 | assumeTrue("CI".equals(System.getenv("ENV"))); 25 | // remainder of test 26 | } 27 | 28 | @Test 29 | void testOnlyOnDeveloperWorkstation() { 30 | assumeTrue("DEV".equals(System.getenv("ENV")), 31 | () -> "Aborting test: not on developer workstation"); 32 | // remainder of test 33 | } 34 | 35 | @Test 36 | void testInAllEnvironments() { 37 | assumingThat("CI".equals(System.getenv("ENV")), 38 | () -> { 39 | // perform these assertions only on the CI server 40 | assertEquals(2, 2); 41 | }); 42 | 43 | // perform these assertions in all environments 44 | assertEquals("a string", "a string"); 45 | } 46 | 47 | } 48 | // end::user_guide[] 49 | // @formatter:on 50 | -------------------------------------------------------------------------------- /documentation/src/test/java/example/StandardTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package example; 12 | 13 | import extensions.ExpectToFail; 14 | 15 | import org.junit.gen5.api.AfterAll; 16 | import org.junit.gen5.api.AfterEach; 17 | import org.junit.gen5.api.Assertions; 18 | import org.junit.gen5.api.BeforeAll; 19 | import org.junit.gen5.api.BeforeEach; 20 | import org.junit.gen5.api.Disabled; 21 | import org.junit.gen5.api.Test; 22 | 23 | // tag::user_guide[] 24 | class StandardTests { 25 | 26 | @BeforeAll 27 | static void initAll() { 28 | } 29 | 30 | @BeforeEach 31 | void init() { 32 | } 33 | 34 | @Test 35 | void succeedingTest() { 36 | } 37 | 38 | // end::user_guide[] 39 | @ExpectToFail 40 | // tag::user_guide[] 41 | @Test 42 | void failingTest() { 43 | Assertions.fail("a failing test"); 44 | } 45 | 46 | @Test 47 | @Disabled("for demonstration purposes") 48 | void skippedTest() { 49 | // not executed 50 | } 51 | 52 | @AfterEach 53 | void tearDown() { 54 | } 55 | 56 | @AfterAll 57 | static void tearDownAll() { 58 | } 59 | 60 | } 61 | // end::user_guide[] 62 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/hierarchical/SingleTestExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.hierarchical; 12 | 13 | import static org.junit.gen5.engine.TestExecutionResult.aborted; 14 | import static org.junit.gen5.engine.TestExecutionResult.failed; 15 | import static org.junit.gen5.engine.TestExecutionResult.successful; 16 | import static org.junit.gen5.engine.support.hierarchical.BlacklistedExceptions.rethrowIfBlacklisted; 17 | 18 | import org.junit.gen5.engine.TestExecutionResult; 19 | import org.opentest4j.TestAbortedException; 20 | 21 | /** 22 | * @since 5.0 23 | */ 24 | class SingleTestExecutor { 25 | interface Executable { 26 | 27 | void execute() throws Throwable; 28 | 29 | } 30 | 31 | TestExecutionResult executeSafely(Executable executable) { 32 | try { 33 | executable.execute(); 34 | return successful(); 35 | } 36 | catch (TestAbortedException e) { 37 | return aborted(e); 38 | } 39 | catch (Throwable t) { 40 | rethrowIfBlacklisted(t); 41 | return failed(t); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /junit4-runner/src/main/java/org/junit/gen5/junit4/runner/FilterClassName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.junit4.runner; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @FilterClassName} specifies a regular expression that is used 26 | * to match against fully qualified class names 27 | * when a test class annotated with {@code @RunWith(JUnit5.class)} is executed. 28 | * 29 | * @since 5.0 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target(ElementType.TYPE) 33 | @Inherited 34 | @Documented 35 | @API(Maintained) 36 | public @interface FilterClassName { 37 | 38 | /** 39 | * Regular expression used to match against fully qualified class names. 40 | */ 41 | String value(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/Tags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | import org.junit.gen5.commons.meta.API; 22 | 23 | /** 24 | * {@code @Tags} is a container for one or more {@code @Tag} declarations. 25 | * 26 | *

Note, however, that use of the {@code @Tags} container is completely 27 | * optional since {@code @Tag} is a {@linkplain java.lang.annotation.Repeatable 28 | * repeatable} annotation. 29 | * 30 | * @since 5.0 31 | * @see Tag 32 | * @see java.lang.annotation.Repeatable 33 | */ 34 | @Target({ ElementType.TYPE, ElementType.METHOD }) 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Documented 37 | @API(Maintained) 38 | public @interface Tags { 39 | 40 | /** 41 | * An array of one or more {@link Tag Tags}. 42 | */ 43 | Tag[]value(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /surefire-junit5/src/main/java/org/junit/gen5/surefire/TestPlanScannerFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.surefire; 12 | 13 | import static org.junit.gen5.engine.discovery.ClassSelector.forClass; 14 | import static org.junit.gen5.launcher.main.TestDiscoveryRequestBuilder.request; 15 | 16 | import org.apache.maven.surefire.util.ScannerFilter; 17 | import org.junit.gen5.launcher.Launcher; 18 | import org.junit.gen5.launcher.TestDiscoveryRequest; 19 | import org.junit.gen5.launcher.TestIdentifier; 20 | import org.junit.gen5.launcher.TestPlan; 21 | 22 | final class TestPlanScannerFilter implements ScannerFilter { 23 | 24 | private final Launcher launcher; 25 | 26 | public TestPlanScannerFilter(Launcher launcher) { 27 | this.launcher = launcher; 28 | } 29 | 30 | @SuppressWarnings("rawtypes") 31 | @Override 32 | public boolean accept(Class testClass) { 33 | TestDiscoveryRequest discoveryRequest = request().select(forClass(testClass)).build(); 34 | TestPlan testPlan = launcher.discover(discoveryRequest); 35 | return testPlan.countTestIdentifiers(TestIdentifier::isTest) > 0; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/filter/ExclusionReasonConsumingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.filter; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.util.Optional; 16 | import java.util.function.BiConsumer; 17 | 18 | import org.junit.gen5.commons.meta.API; 19 | import org.junit.gen5.engine.Filter; 20 | import org.junit.gen5.engine.FilterResult; 21 | 22 | @API(Internal) 23 | public class ExclusionReasonConsumingFilter implements Filter { 24 | 25 | private final Filter filter; 26 | private final BiConsumer> reasonConsumer; 27 | 28 | public ExclusionReasonConsumingFilter(Filter filter, BiConsumer> reasonConsumer) { 29 | this.filter = filter; 30 | this.reasonConsumer = reasonConsumer; 31 | } 32 | 33 | @Override 34 | public FilterResult filter(T object) { 35 | FilterResult result = filter.filter(object); 36 | if (result.excluded()) { 37 | reasonConsumer.accept(object, result.getReason()); 38 | } 39 | return result; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/execution/injection/sample/CustomAnnotationParameterResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.execution.injection.sample; 12 | 13 | import java.lang.reflect.Parameter; 14 | 15 | import org.junit.gen5.api.extension.ExtensionContext; 16 | import org.junit.gen5.api.extension.MethodInvocationContext; 17 | import org.junit.gen5.api.extension.MethodParameterResolver; 18 | import org.junit.gen5.commons.util.ReflectionUtils; 19 | 20 | /** 21 | * @since 5.0 22 | */ 23 | public class CustomAnnotationParameterResolver implements MethodParameterResolver { 24 | 25 | @Override 26 | public boolean supports(Parameter parameter, MethodInvocationContext methodInvocationContext, 27 | ExtensionContext extensionContext) { 28 | 29 | return parameter.isAnnotationPresent(CustomAnnotation.class); 30 | } 31 | 32 | @Override 33 | public Object resolve(Parameter parameter, MethodInvocationContext methodInvocationContext, 34 | ExtensionContext extensionContext) { 35 | 36 | return ReflectionUtils.newInstance(parameter.getType()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/IsNestedTestClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | import static org.junit.gen5.commons.util.AnnotationUtils.isAnnotated; 15 | import static org.junit.gen5.commons.util.ReflectionUtils.isPrivate; 16 | import static org.junit.gen5.commons.util.ReflectionUtils.isStatic; 17 | 18 | import java.util.function.Predicate; 19 | 20 | import org.junit.gen5.api.Nested; 21 | import org.junit.gen5.commons.meta.API; 22 | 23 | /** 24 | * Test if a class is a JUnit 5 nested, inner test class. 25 | * 26 | * @since 5.0 27 | */ 28 | @API(Internal) 29 | public class IsNestedTestClass implements Predicate> { 30 | 31 | @Override 32 | public boolean test(Class candidate) { 33 | //please do not collapse into single return 34 | if (isStatic(candidate)) 35 | return false; 36 | if (isPrivate(candidate)) 37 | return false; 38 | if (!candidate.isMemberClass()) 39 | return false; 40 | return isAnnotated(candidate, Nested.class); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /documentation/src/test/java/extensions/ExpectToFailExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package extensions; 12 | 13 | import static org.junit.gen5.api.Assertions.assertNotNull; 14 | 15 | import org.junit.gen5.api.extension.AfterEachExtensionPoint; 16 | import org.junit.gen5.api.extension.ExceptionHandlerExtensionPoint; 17 | import org.junit.gen5.api.extension.ExtensionContext.Namespace; 18 | import org.junit.gen5.api.extension.ExtensionContext.Store; 19 | import org.junit.gen5.api.extension.TestExtensionContext; 20 | 21 | public class ExpectToFailExtension implements ExceptionHandlerExtensionPoint, AfterEachExtensionPoint { 22 | 23 | @Override 24 | public void handleException(TestExtensionContext context, Throwable throwable) throws Throwable { 25 | getExceptionStore(context).put("exception", throwable); 26 | } 27 | 28 | @Override 29 | public void afterEach(TestExtensionContext context) throws Exception { 30 | assertNotNull(getExceptionStore(context).get("exception"), "Test should have failed"); 31 | } 32 | 33 | private Store getExceptionStore(TestExtensionContext context) { 34 | return context.getStore(Namespace.of(context)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/discovery/ClassSelector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.commons.util.PreconditionViolationException; 17 | import org.junit.gen5.commons.util.ReflectionUtils; 18 | import org.junit.gen5.engine.DiscoverySelector; 19 | 20 | /** 21 | * @since 5.0 22 | */ 23 | @API(Experimental) 24 | public class ClassSelector implements DiscoverySelector { 25 | 26 | public static ClassSelector forClass(Class testClass) { 27 | return new ClassSelector(testClass); 28 | } 29 | 30 | public static ClassSelector forClassName(String className) { 31 | return forClass(ReflectionUtils.loadClass(className).orElseThrow( 32 | () -> new PreconditionViolationException("Could not resolve class with name: " + className))); 33 | } 34 | 35 | private final Class testClass; 36 | 37 | private ClassSelector(Class testClass) { 38 | this.testClass = testClass; 39 | } 40 | 41 | public Class getTestClass() { 42 | return testClass; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/hierarchical/HierarchicalTestEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.hierarchical; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.engine.ExecutionRequest; 17 | import org.junit.gen5.engine.TestEngine; 18 | 19 | /** 20 | * Abstract base class for all {@link TestEngine} implementations that wish 21 | * to organize test suites hierarchically based on the {@link Node}, 22 | * {@link Container}, and {@link Leaf} abstractions. 23 | * 24 | * @param the type of {@code EngineExecutionContext} used by this engine 25 | * @since 5.0 26 | * @see Node 27 | * @see Container 28 | * @see Leaf 29 | */ 30 | @API(Experimental) 31 | public abstract class HierarchicalTestEngine implements TestEngine { 32 | 33 | @Override 34 | public final void execute(ExecutionRequest request) { 35 | new HierarchicalTestExecutor<>(request, createExecutionContext(request)).execute(); 36 | } 37 | 38 | protected abstract C createExecutionContext(ExecutionRequest request); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/BeforeEachExtensionPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * {@code BeforeEachExtensionPoint} defines the API for {@link Extension 19 | * Extensions} that wish to provide additional behavior to tests before 20 | * each test method has been invoked. 21 | * 22 | *

Concrete implementations often implement {@link AfterEachExtensionPoint} as well. 23 | * 24 | *

Implementations must provide a no-args constructor. 25 | * 26 | * @since 5.0 27 | * @see org.junit.gen5.api.BeforeEach 28 | * @see AfterEachExtensionPoint 29 | * @see BeforeAllExtensionPoint 30 | * @see AfterAllExtensionPoint 31 | */ 32 | @FunctionalInterface 33 | @API(Experimental) 34 | public interface BeforeEachExtensionPoint extends ExtensionPoint { 35 | 36 | /** 37 | * Callback that is invoked before each test method has been invoked. 38 | * 39 | * @param context the current test extension context 40 | */ 41 | void beforeEach(TestExtensionContext context) throws Exception; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/AfterAllExtensionPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * {@code AfterAllExtensionPoint} defines the API for {@link Extension 19 | * Extensions} that wish to provide additional behavior to tests after 20 | * all test methods have been invoked. 21 | * 22 | *

Concrete implementations often implement {@link BeforeAllExtensionPoint} as well. 23 | * 24 | *

Implementations must provide a no-args constructor. 25 | * 26 | * @since 5.0 27 | * @see org.junit.gen5.api.AfterAll 28 | * @see BeforeAllExtensionPoint 29 | * @see BeforeEachExtensionPoint 30 | * @see AfterEachExtensionPoint 31 | */ 32 | @FunctionalInterface 33 | @API(Experimental) 34 | public interface AfterAllExtensionPoint extends ExtensionPoint { 35 | 36 | /** 37 | * Callback that is invoked after all test methods have been invoked. 38 | * 39 | * @param context the current container extension context 40 | */ 41 | void afterAll(ContainerExtensionContext context) throws Exception; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/AfterEachExtensionPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * {@code AfterEachExtensionPoint} defines the API for {@link Extension 19 | * Extensions} that wish to provide additional behavior to tests 20 | * after each test method has been invoked. 21 | * 22 | *

Concrete implementations often implement {@link BeforeEachExtensionPoint} 23 | * as well. 24 | * 25 | *

Implementations must provide a no-args constructor. 26 | * 27 | * @since 5.0 28 | * @see org.junit.gen5.api.AfterEach 29 | * @see BeforeEachExtensionPoint 30 | * @see BeforeAllExtensionPoint 31 | * @see AfterAllExtensionPoint 32 | */ 33 | @FunctionalInterface 34 | @API(Experimental) 35 | public interface AfterEachExtensionPoint extends ExtensionPoint { 36 | 37 | /** 38 | * Callback that is invoked after each test 39 | * method has been invoked. 40 | * 41 | * @param context the current test extension context 42 | */ 43 | void afterEach(TestExtensionContext context) throws Exception; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/IsTestMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | import static org.junit.gen5.commons.util.AnnotationUtils.isAnnotated; 15 | import static org.junit.gen5.commons.util.ReflectionUtils.isAbstract; 16 | import static org.junit.gen5.commons.util.ReflectionUtils.isPrivate; 17 | import static org.junit.gen5.commons.util.ReflectionUtils.isStatic; 18 | 19 | import java.lang.reflect.Method; 20 | import java.util.function.Predicate; 21 | 22 | import org.junit.gen5.api.Test; 23 | import org.junit.gen5.commons.meta.API; 24 | 25 | /** 26 | * Test if a method is a JUnit 5 test method. 27 | * 28 | * @since 5.0 29 | */ 30 | @API(Internal) 31 | public class IsTestMethod implements Predicate { 32 | 33 | @Override 34 | public boolean test(Method candidate) { 35 | //please do not collapse into single return 36 | if (isStatic(candidate)) 37 | return false; 38 | if (isPrivate(candidate)) 39 | return false; 40 | if (isAbstract(candidate)) 41 | return false; 42 | return isAnnotated(candidate, Test.class); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /junit-launcher/src/main/java/org/junit/gen5/launcher/TestId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.launcher; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.io.Serializable; 16 | import java.util.Objects; 17 | 18 | import org.junit.gen5.commons.meta.API; 19 | import org.junit.gen5.commons.util.Preconditions; 20 | 21 | /** 22 | * Immutable value object representing a unique test ID. 23 | * 24 | * @since 5.0 25 | */ 26 | @API(Experimental) 27 | public final class TestId implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | private final String uniqueId; 32 | 33 | public TestId(String uniqueId) { 34 | this.uniqueId = Preconditions.notBlank(uniqueId, "uniqueId must not be null or empty"); 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (obj instanceof TestId) { 40 | TestId that = (TestId) obj; 41 | return Objects.equals(this.uniqueId, that.uniqueId); 42 | } 43 | return false; 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | return this.uniqueId.hashCode(); 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return this.uniqueId; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/BeforeAllExtensionPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * {@code BeforeAllExtensionPoint} defines the API for {@link Extension 19 | * Extensions} that wish to provide additional behavior to tests before 20 | * all test methods have been invoked. 21 | * 22 | *

Concrete implementations often implement {@link AfterAllExtensionPoint} as well. 23 | * 24 | *

Implementations must provide a no-args constructor. 25 | * 26 | * @since 5.0 27 | * @see org.junit.gen5.api.BeforeAll 28 | * @see AfterAllExtensionPoint 29 | * @see BeforeEachExtensionPoint 30 | * @see AfterEachExtensionPoint 31 | */ 32 | @FunctionalInterface 33 | @API(Experimental) 34 | public interface BeforeAllExtensionPoint extends ExtensionPoint { 35 | 36 | /** 37 | * Callback that is invoked before all {@code @BeforeAll} 38 | * methods have been invoked. 39 | * 40 | * @param context the current container extension context 41 | */ 42 | void beforeAll(ContainerExtensionContext context) throws Exception; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/ExecutionRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import org.junit.gen5.commons.meta.API; 20 | 21 | @API(Experimental) 22 | public class ExecutionRequest { 23 | 24 | private final TestDescriptor rootTestDescriptor; 25 | 26 | private final EngineExecutionListener engineExecutionListener; 27 | 28 | private final Map attributes = new HashMap<>(); 29 | 30 | @API(Internal) 31 | public ExecutionRequest(TestDescriptor rootTestDescriptor, EngineExecutionListener engineExecutionListener) { 32 | this.rootTestDescriptor = rootTestDescriptor; 33 | this.engineExecutionListener = engineExecutionListener; 34 | } 35 | 36 | public TestDescriptor getRootTestDescriptor() { 37 | return rootTestDescriptor; 38 | } 39 | 40 | public EngineExecutionListener getEngineExecutionListener() { 41 | return engineExecutionListener; 42 | } 43 | 44 | public Map getAttributes() { 45 | return this.attributes; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /junit-launcher/src/main/java/org/junit/gen5/launcher/main/LauncherFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.launcher.main; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.launcher.Launcher; 17 | 18 | /** 19 | * Factory for creating {@link Launcher} instances by invoking {@link #create()}. 20 | * 21 | *

Test engines are registered at runtime using the 22 | * {@link java.util.ServiceLoader ServiceLoader} facility. For that purpose, a 23 | * text file named {@code META-INF/services/org.junit.gen5.engine.TestEngine} 24 | * has to be added to the engine's JAR file in which the fully qualified name 25 | * of the implementation class of the {@link org.junit.gen5.engine.TestEngine} 26 | * interface is stated. 27 | * 28 | * @since 5.0 29 | * @see Launcher 30 | */ 31 | @API(Experimental) 32 | public class LauncherFactory { 33 | 34 | /** 35 | * Factory method for creating a new instance of {@link Launcher} using dynamically 36 | * registered test engines. 37 | */ 38 | public static Launcher create() { 39 | return new DefaultLauncher(new ServiceLoaderTestEngineRegistry().loadTestEngines()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/extension/TestReporterParameterResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.extension; 12 | 13 | import java.lang.reflect.Parameter; 14 | 15 | import org.junit.gen5.api.TestReporter; 16 | import org.junit.gen5.api.extension.ExtensionContext; 17 | import org.junit.gen5.api.extension.MethodInvocationContext; 18 | import org.junit.gen5.api.extension.MethodParameterResolver; 19 | import org.junit.gen5.commons.util.*; 20 | 21 | /** 22 | * {@link MethodParameterResolver} that injects a {@link TestReporter}. 23 | * 24 | * @since 5.0 25 | */ 26 | class TestReporterParameterResolver implements MethodParameterResolver { 27 | 28 | @Override 29 | public boolean supports(Parameter parameter, MethodInvocationContext methodInvocationContext, 30 | ExtensionContext extensionContext) { 31 | Preconditions.notNull(parameter, "supplied parameter must not be null"); 32 | 33 | return (parameter.getType() == TestReporter.class); 34 | } 35 | 36 | @Override 37 | public TestReporter resolve(Parameter parameter, MethodInvocationContext methodInvocationContext, 38 | ExtensionContext extensionContext) { 39 | return extensionContext::publishReportEntry; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/discovery/ClasspathSelector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.discovery; 12 | 13 | import static java.util.Collections.singleton; 14 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 15 | 16 | import java.io.File; 17 | import java.util.List; 18 | import java.util.Set; 19 | import java.util.stream.Collectors; 20 | 21 | import org.junit.gen5.commons.meta.API; 22 | import org.junit.gen5.engine.DiscoverySelector; 23 | 24 | /** 25 | * @since 5.0 26 | */ 27 | @API(Experimental) 28 | public class ClasspathSelector implements DiscoverySelector { 29 | 30 | public static List forPath(String path) { 31 | return forPaths(singleton(new File(path))); 32 | } 33 | 34 | public static List forPaths(Set paths) { 35 | // @formatter:off 36 | return paths.stream() 37 | .filter(File::exists) 38 | .map(ClasspathSelector::new) 39 | .collect(Collectors.toList()); 40 | // @formatter:on 41 | } 42 | 43 | private final File classpathRoot; 44 | 45 | private ClasspathSelector(File classpathRoot) { 46 | this.classpathRoot = classpathRoot; 47 | } 48 | 49 | public File getClasspathRoot() { 50 | return classpathRoot; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/extension/Extensions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api.extension; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @Extensions} is a container for one or more {@code @ExtendWith} 26 | * declarations. 27 | * 28 | *

Note, however, that use of the {@code @Extensions} container is completely 29 | * optional since {@code @ExtendWith} is a {@linkplain java.lang.annotation.Repeatable 30 | * repeatable} annotation. 31 | * 32 | * @since 5.0 33 | * @see ExtendWith 34 | * @see java.lang.annotation.Repeatable 35 | */ 36 | @Target({ ElementType.TYPE, ElementType.METHOD }) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | @Inherited 40 | @API(Experimental) 41 | public @interface Extensions { 42 | 43 | /** 44 | * An array of one or more {@link ExtendWith @ExtendWith} declarations. 45 | */ 46 | ExtendWith[]value(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /junit-console/src/main/java/org/junit/gen5/console/tasks/CustomContextClassLoaderExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.console.tasks; 12 | 13 | import java.util.Optional; 14 | import java.util.concurrent.Callable; 15 | 16 | class CustomContextClassLoaderExecutor { 17 | 18 | private final Optional customClassLoader; 19 | 20 | CustomContextClassLoaderExecutor(Optional customClassLoader) { 21 | this.customClassLoader = customClassLoader; 22 | } 23 | 24 | T invoke(Callable callable) throws Exception { 25 | if (customClassLoader.isPresent()) { 26 | // Only get/set context class loader when necessary to prevent problems with 27 | // security managers 28 | return replaceThreadContextClassLoaderAndInvoke(customClassLoader.get(), callable); 29 | } 30 | return callable.call(); 31 | } 32 | 33 | private T replaceThreadContextClassLoaderAndInvoke(ClassLoader customClassLoader, Callable callable) 34 | throws Exception { 35 | ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); 36 | try { 37 | Thread.currentThread().setContextClassLoader(customClassLoader); 38 | return callable.call(); 39 | } 40 | finally { 41 | Thread.currentThread().setContextClassLoader(originalClassLoader); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/UniqueIdReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit4.discovery; 12 | 13 | import static java.lang.String.format; 14 | import static org.junit.gen5.commons.util.ReflectionUtils.readFieldValue; 15 | 16 | import java.io.Serializable; 17 | import java.util.Optional; 18 | import java.util.function.Function; 19 | import java.util.logging.Logger; 20 | 21 | import org.junit.runner.Description; 22 | 23 | class UniqueIdReader implements Function { 24 | 25 | private final Logger logger; 26 | private final String fieldName; 27 | 28 | UniqueIdReader(Logger logger) { 29 | this(logger, "fUniqueId"); 30 | } 31 | 32 | // For tests only 33 | UniqueIdReader(Logger logger, String fieldName) { 34 | this.logger = logger; 35 | this.fieldName = fieldName; 36 | } 37 | 38 | @Override 39 | public Serializable apply(Description description) { 40 | Optional result = readFieldValue(Description.class, fieldName, description); 41 | return result.map(Serializable.class::cast).orElseGet(() -> { 42 | logger.warning(() -> format("Could not read unique id for Description, using display name instead: %s", 43 | description.toString())); 44 | return description.getDisplayName(); 45 | }); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/TestInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | 17 | /** 18 | * {@code TestInfo} is used to inject information about the current test 19 | * into to {@code @Test}, {@code @BeforeEach}, {@code @AfterEach}, 20 | * {@code @BeforeAll}, and {@code @AfterAll} methods. 21 | * 22 | *

If a method parameter is of type {@link TestInfo}, JUnit will supply 23 | * an instance of {@code TestInfo} corresponding to the current test as the 24 | * value for the parameter. 25 | * 26 | * @since 5.0 27 | * @see Test 28 | * @see DisplayName 29 | */ 30 | @API(Experimental) 31 | public interface TestInfo { 32 | 33 | /** 34 | * Get the name of the current test. 35 | * 36 | * @return the name of the test; never {@code null} 37 | * @see #getDisplayName() 38 | */ 39 | String getName(); 40 | 41 | /** 42 | * Get the display name of the current test. 43 | * 44 | *

The display name is either the canonical name of the test or a 45 | * custom name configured via {@link DisplayName @DisplayName}. 46 | * 47 | * @return the display name of the test; never {@code null} 48 | * @see #getName() 49 | */ 50 | String getDisplayName(); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/discovery/JUnit5Testable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.discovery; 12 | 13 | import java.lang.reflect.Method; 14 | 15 | abstract class JUnit5Testable { 16 | 17 | private static final JUnit5TestableFactory testableFactory = new JUnit5TestableFactory(); 18 | 19 | static JUnit5Testable fromUniqueId(String uniqueId, String engineId) { 20 | return testableFactory.fromUniqueId(uniqueId, engineId); 21 | } 22 | 23 | static JUnit5Testable fromClass(Class clazz, String engineId) { 24 | return testableFactory.fromClass(clazz, engineId); 25 | } 26 | 27 | static JUnit5Testable fromMethod(Method testMethod, Class clazz, String engineId) { 28 | return testableFactory.fromMethod(testMethod, clazz, engineId); 29 | } 30 | 31 | private final String uniqueId; 32 | 33 | JUnit5Testable(String uniqueId) { 34 | this.uniqueId = uniqueId; 35 | } 36 | 37 | String getUniqueId() { 38 | return this.uniqueId; 39 | } 40 | 41 | abstract void accept(Visitor visitor); 42 | 43 | interface Visitor { 44 | 45 | void visitClass(String uniqueId, Class testClass); 46 | 47 | void visitMethod(String uniqueId, Method method, Class container); 48 | 49 | void visitNestedClass(String uniqueId, Class javaClass, Class containerClass); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/console/tasks/XmlReportAssertions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.console.tasks; 12 | 13 | import java.io.StringReader; 14 | import java.net.URL; 15 | 16 | import javax.xml.XMLConstants; 17 | import javax.xml.transform.stream.StreamSource; 18 | import javax.xml.validation.SchemaFactory; 19 | import javax.xml.validation.Validator; 20 | 21 | import org.opentest4j.AssertionFailedError; 22 | import org.xml.sax.SAXException; 23 | 24 | public class XmlReportAssertions { 25 | 26 | private static Validator schemaValidator; 27 | 28 | static String ensureValidAccordingToJenkinsSchema(String content) throws Exception { 29 | try { 30 | getSchemaValidator().validate(new StreamSource(new StringReader(content))); 31 | return content; 32 | } 33 | catch (SAXException e) { 34 | throw new AssertionFailedError("Invalid XML document: " + content, e); 35 | } 36 | } 37 | 38 | private static Validator getSchemaValidator() throws SAXException { 39 | if (schemaValidator == null) { 40 | URL schemaFile = XmlReportsWritingListener.class.getResource("/jenkins-junit.xsd"); 41 | SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 42 | schemaValidator = schemaFactory.newSchema(schemaFile).newValidator(); 43 | } 44 | return schemaValidator; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/Tag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Maintained; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Repeatable; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | import org.junit.gen5.commons.meta.API; 23 | 24 | /** 25 | * {@code @Tag} is a {@linkplain Repeatable repeatable} annotation that is 26 | * used to declare a tag for the annotated test class or test method. 27 | * 28 | *

Tags are used to filter which tests are executed for a given test 29 | * plan. For example, a development team may tag tests with values such as 30 | * {@code "fast"}, {@code "slow"}, {@code "ci-server"}, etc. and then supply 31 | * a list of tags to be used for the current test plan, potentially 32 | * dependent on the current environment. 33 | * 34 | * @since 5.0 35 | * @see Tags 36 | * @see Test 37 | */ 38 | @Target({ ElementType.TYPE, ElementType.METHOD }) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Repeatable(Tags.class) 42 | @API(Maintained) 43 | public @interface Tag { 44 | 45 | /** 46 | * The tag. 47 | */ 48 | String value(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /junit5-api/src/main/java/org/junit/gen5/api/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.api; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Stable; 14 | 15 | import java.lang.annotation.Documented; 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | import org.junit.gen5.commons.meta.API; 22 | 23 | /** 24 | * {@code @Test} is used to signal that the annotated method is a 25 | * test method. 26 | * 27 | *

{@code @Test} may also be used as a meta-annotation in order to 28 | * create a custom composed annotation that inherits the semantics 29 | * of {@code @Test}. 30 | * 31 | *

{@code @Test} methods must not be {@code private} or {@code static}. 32 | * 33 | *

{@code @Test} methods may optionally declare parameters to be 34 | * resolved by {@link org.junit.gen5.api.extension.MethodParameterResolver 35 | * MethodParameterResolvers}. 36 | * 37 | * @since 5.0 38 | * @see TestInfo 39 | * @see DisplayName 40 | * @see BeforeEach 41 | * @see AfterEach 42 | * @see BeforeAll 43 | * @see AfterAll 44 | */ 45 | @Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD }) 46 | @Retention(RetentionPolicy.RUNTIME) 47 | @Documented 48 | @API(Stable) 49 | public @interface Test { 50 | } 51 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/support/hierarchical/DummyEngineDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.hierarchical; 12 | 13 | import static org.junit.gen5.engine.support.hierarchical.Node.SkipResult.dontSkip; 14 | import static org.junit.gen5.engine.support.hierarchical.Node.SkipResult.skip; 15 | 16 | import org.junit.gen5.engine.support.descriptor.EngineDescriptor; 17 | 18 | public class DummyEngineDescriptor extends EngineDescriptor implements Container { 19 | 20 | private String skippedReason; 21 | private boolean skipped; 22 | private Runnable beforeAllBehavior = () -> { 23 | }; 24 | 25 | public DummyEngineDescriptor(String engineId) { 26 | super(engineId, engineId); 27 | } 28 | 29 | public void markSkipped(String reason) { 30 | this.skipped = true; 31 | this.skippedReason = reason; 32 | } 33 | 34 | public void setBeforeAllBehavior(Runnable beforeAllBehavior) { 35 | this.beforeAllBehavior = beforeAllBehavior; 36 | } 37 | 38 | @Override 39 | public SkipResult shouldBeSkipped(DummyEngineExecutionContext context) { 40 | return skipped ? skip(skippedReason) : dontSkip(); 41 | } 42 | 43 | @Override 44 | public DummyEngineExecutionContext beforeAll(DummyEngineExecutionContext context) throws Exception { 45 | beforeAllBehavior.run(); 46 | return context; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /junit-launcher/src/main/java/org/junit/gen5/launcher/EngineIdFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.launcher; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Experimental; 14 | import static org.junit.gen5.engine.FilterResult.includedIf; 15 | 16 | import org.junit.gen5.commons.meta.API; 17 | import org.junit.gen5.engine.Filter; 18 | import org.junit.gen5.engine.FilterResult; 19 | import org.junit.gen5.engine.TestEngine; 20 | 21 | /** 22 | * A special filter that is applied before a {@link TestEngine} is executed. 23 | * It allows to include the given engine id within the test discovery and 24 | * execution. 25 | * 26 | * @since 5.0 27 | * @see TestDiscoveryRequest 28 | */ 29 | @API(Experimental) 30 | public class EngineIdFilter implements Filter { 31 | 32 | public static EngineIdFilter byEngineId(String engineId) { 33 | return new EngineIdFilter(engineId); 34 | } 35 | 36 | private final String engineId; 37 | 38 | private EngineIdFilter(String engineId) { 39 | this.engineId = engineId; 40 | } 41 | 42 | @Override 43 | public FilterResult filter(String engineId) { 44 | return includedIf(this.engineId.equals(engineId), // 45 | () -> "Engine ID matches", // 46 | () -> "Engine ID does not match"); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "Include engines with ID: " + engineId; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /junit-engine-api/src/main/java/org/junit/gen5/engine/support/hierarchical/BlacklistedExceptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.support.hierarchical; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | 16 | import org.junit.gen5.commons.util.ExceptionUtils; 17 | 18 | /** 19 | * Internal utilities for working with blacklisted exceptions. 20 | * 21 | *

Blacklisted exceptions are those that should always terminate 22 | * test plan execution immediately. 23 | * 24 | *

Currently Blacklisted Exceptions

25 | *
    26 | *
  • {@link OutOfMemoryError}
  • 27 | *
28 | * 29 | * @since 5.0 30 | */ 31 | final class BlacklistedExceptions { 32 | 33 | private static final List> blacklist = Collections.singletonList(OutOfMemoryError.class); 34 | 35 | private BlacklistedExceptions() { 36 | /* no-op */ 37 | } 38 | 39 | /** 40 | * Rethrow the supplied {@link Throwable exception} if it is 41 | * blacklisted. 42 | * 43 | *

If the supplied {@code exception} is not blacklisted, 44 | * this method does nothing. 45 | */ 46 | static void rethrowIfBlacklisted(Throwable exception) { 47 | if (blacklist.stream().anyMatch(exceptionType -> exceptionType.isInstance(exception))) { 48 | ExceptionUtils.throwAsUncheckedException(exception); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/descriptor/NestedClassTestDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.descriptor; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import org.junit.gen5.commons.meta.API; 16 | import org.junit.gen5.commons.util.ReflectionUtils; 17 | import org.junit.gen5.engine.TestDescriptor; 18 | import org.junit.gen5.engine.junit5.execution.JUnit5EngineExecutionContext; 19 | import org.junit.gen5.engine.junit5.execution.TestInstanceProvider; 20 | 21 | /** 22 | * {@link TestDescriptor} for tests based on nested (but not static) Java classes. 23 | * 24 | *

The pattern of the {@link #getUniqueId unique ID} takes the form of 25 | * {parent unique id}:{fully qualified class name of parent}@{simple class name}. 26 | * 27 | * @since 5.0 28 | */ 29 | @API(Internal) 30 | public class NestedClassTestDescriptor extends ClassTestDescriptor { 31 | 32 | public NestedClassTestDescriptor(String uniqueId, Class testClass) { 33 | super(uniqueId, testClass); 34 | } 35 | 36 | @Override 37 | protected TestInstanceProvider testInstanceProvider(JUnit5EngineExecutionContext context) { 38 | return () -> { 39 | Object outerInstance = context.getTestInstanceProvider().getTestInstance(); 40 | return ReflectionUtils.newInstance(getTestClass(), outerInstance); 41 | }; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /junit5-engine/src/main/java/org/junit/gen5/engine/junit5/execution/NamespaceAwareStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5.execution; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.util.function.Function; 16 | 17 | import org.junit.gen5.api.extension.ExtensionContext.Namespace; 18 | import org.junit.gen5.api.extension.ExtensionContext.Store; 19 | import org.junit.gen5.commons.meta.API; 20 | 21 | /** 22 | * @since 5.0 23 | */ 24 | @API(Internal) 25 | public class NamespaceAwareStore implements Store { 26 | 27 | private final ExtensionValuesStore valuesStore; 28 | private final Namespace namespace; 29 | 30 | public NamespaceAwareStore(ExtensionValuesStore valuesStore, Namespace namespace) { 31 | this.valuesStore = valuesStore; 32 | this.namespace = namespace; 33 | } 34 | 35 | @Override 36 | public Object get(Object key) { 37 | return valuesStore.get(namespace, key); 38 | } 39 | 40 | @Override 41 | public void put(Object key, Object value) { 42 | valuesStore.put(namespace, key, value); 43 | } 44 | 45 | @Override 46 | public Object getOrComputeIfAbsent(Object key, Function defaultCreator) { 47 | return valuesStore.getOrComputeIfAbsent(namespace, key, defaultCreator); 48 | } 49 | 50 | @Override 51 | public Object remove(Object key) { 52 | return valuesStore.remove(namespace, key); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /junit-tests/src/test/java/org/junit/gen5/engine/junit5/AbstractJUnit5TestEngineTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.engine.junit5; 12 | 13 | import static org.junit.gen5.engine.discovery.ClassSelector.forClass; 14 | import static org.junit.gen5.launcher.main.TestDiscoveryRequestBuilder.request; 15 | 16 | import org.junit.gen5.engine.ExecutionEventRecorder; 17 | import org.junit.gen5.engine.ExecutionRequest; 18 | import org.junit.gen5.engine.TestDescriptor; 19 | import org.junit.gen5.launcher.TestDiscoveryRequest; 20 | 21 | /** 22 | * Abstract base class for tests involving the {@link JUnit5TestEngine}. 23 | * 24 | * @since 5.0 25 | */ 26 | public abstract class AbstractJUnit5TestEngineTests { 27 | 28 | private final JUnit5TestEngine engine = new JUnit5TestEngine(); 29 | 30 | protected ExecutionEventRecorder executeTestsForClass(Class testClass) { 31 | return executeTests(request().select(forClass(testClass)).build()); 32 | } 33 | 34 | protected ExecutionEventRecorder executeTests(TestDiscoveryRequest request) { 35 | TestDescriptor testDescriptor = discoverTests(request); 36 | ExecutionEventRecorder eventRecorder = new ExecutionEventRecorder(); 37 | engine.execute(new ExecutionRequest(testDescriptor, eventRecorder)); 38 | return eventRecorder; 39 | } 40 | 41 | protected TestDescriptor discoverTests(TestDiscoveryRequest request) { 42 | return engine.discover(request); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /junit-commons/src/main/java/org/junit/gen5/commons/util/CollectionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.commons.util; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.util.Collection; 16 | 17 | import org.junit.gen5.commons.meta.API; 18 | 19 | /** 20 | * Collection of utilities for working with {@link Collection Collections}. 21 | * 22 | *

DISCLAIMER

23 | * 24 | *

These utilities are intended solely for usage within the JUnit framework 25 | * itself. Any usage by external parties is not supported. 26 | * Use at your own risk! 27 | * 28 | * @since 5.0 29 | */ 30 | @API(Internal) 31 | public final class CollectionUtils { 32 | 33 | private CollectionUtils() { 34 | /* no-op */ 35 | } 36 | 37 | /** 38 | * Read the only element of a collection of size 1. 39 | * 40 | * @param collection the collection to get the element from 41 | * @return the only element of the collection 42 | * @throws PreconditionViolationException if the collection is {@code null} 43 | * or does not contain exactly one element 44 | */ 45 | public static T getOnlyElement(Collection collection) { 46 | Preconditions.notNull(collection, "collection must not be null"); 47 | Preconditions.condition(collection.size() == 1, 48 | () -> "collection must contain exactly one element: " + collection); 49 | return collection.iterator().next(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /junit-console/src/main/java/org/junit/gen5/console/tasks/ConsoleTaskExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 the original author or authors. 3 | * 4 | * All rights reserved. This program and the accompanying materials are 5 | * made available under the terms of the Eclipse Public License v1.0 which 6 | * accompanies this distribution and is available at 7 | * 8 | * http://www.eclipse.org/legal/epl-v10.html 9 | */ 10 | 11 | package org.junit.gen5.console.tasks; 12 | 13 | import static org.junit.gen5.commons.meta.API.Usage.Internal; 14 | 15 | import java.io.PrintStream; 16 | import java.io.PrintWriter; 17 | import java.util.function.Consumer; 18 | 19 | import org.junit.gen5.commons.meta.API; 20 | 21 | @API(Internal) 22 | public class ConsoleTaskExecutor { 23 | 24 | private final PrintStream out; 25 | private final PrintStream err; 26 | 27 | public ConsoleTaskExecutor(PrintStream out, PrintStream err) { 28 | this.out = out; 29 | this.err = err; 30 | } 31 | 32 | public int executeTask(ConsoleTask task, Consumer helpPrinter) { 33 | PrintWriter outWriter = new PrintWriter(out); 34 | try { 35 | return task.execute(outWriter); 36 | } 37 | catch (Exception e) { 38 | printException(e); 39 | printHelp(helpPrinter, outWriter); 40 | return -1; 41 | } 42 | finally { 43 | outWriter.flush(); 44 | } 45 | } 46 | 47 | private void printHelp(Consumer helpPrinter, PrintWriter outWriter) { 48 | try { 49 | helpPrinter.accept(outWriter); 50 | } 51 | catch (Exception e) { 52 | err.print("Exception occurred while printing help: "); 53 | printException(e); 54 | } 55 | } 56 | 57 | private void printException(Exception exception) { 58 | exception.printStackTrace(err); 59 | err.println(); 60 | } 61 | } 62 | --------------------------------------------------------------------------------