forked from mockito/mockito
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make MockitoExtension constructor public (mockito#1391)
* Make MockitoExtension constructor public It is possible to register an extension for automatic use using Java's `ServiceLoader` mechanism. https://junit.org/junit5/docs/current/user-guide/#extensions-registration-automatic Some projects may want to provide their own `META-INF` file to avoid tediously adding `MockitoExtension` to tests since it is very common. However, `ServiceLoader` requires the class to have a no-args *public* constructor, so the current extension cannot be used with the `ServiceLoader` mechanism. * Add test
- Loading branch information
1 parent
758ca37
commit 3f96f3b
Showing
6 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
subprojects/junitJupiterExtensionTest/junitJupiterExtensionTest.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apply from: "$rootDir/gradle/dependencies.gradle" | ||
|
||
apply plugin: 'java' | ||
description = "End-to-end tests for automatic registration of MockitoExtension." | ||
|
||
sourceCompatibility = 1.8 | ||
|
||
dependencies { | ||
testCompile project(":junit-jupiter") | ||
testCompile libraries.assertj | ||
testCompile libraries.junitPlatformLauncher | ||
testCompile libraries.junitJupiterApi | ||
testRuntime libraries.junitJupiterEngine | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
25 changes: 25 additions & 0 deletions
25
subprojects/junitJupiterExtensionTest/src/test/java/org/mockitousage/NoExtendsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2018 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockitousage; | ||
|
||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
class NoExtendsTest { | ||
|
||
@Mock | ||
private List<String> mock; | ||
|
||
@Test | ||
void runs() { | ||
when(mock.get(0)).thenReturn("foo"); | ||
assertThat(mock.get(0)).isEqualTo("foo"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ensionTest/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.mockito.junit.jupiter.MockitoExtension |
1 change: 1 addition & 0 deletions
1
subprojects/junitJupiterExtensionTest/src/test/resources/junit-platform.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
junit.jupiter.extensions.autodetection.enabled = true |