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.
Fixed \mockito#1967: Correctly handle mocks with limited life-cycle i…
…n listeners.
- Loading branch information
Showing
15 changed files
with
217 additions
and
43 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
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
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
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
49 changes: 49 additions & 0 deletions
49
src/test/java/org/mockito/internal/configuration/MockAnnotationProcessorTest.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,49 @@ | ||
/* | ||
* Copyright (c) 2020 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito.internal.configuration; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.exceptions.base.MockitoException; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class MockAnnotationProcessorTest { | ||
|
||
@SuppressWarnings("unused") | ||
private MockedStatic<Void> nonGeneric; | ||
|
||
@SuppressWarnings("unused") | ||
private MockedStatic<List<?>> generic; | ||
|
||
@SuppressWarnings({"raw", "unused"}) | ||
private MockedStatic raw; | ||
|
||
@Test | ||
public void testNonGeneric() throws Exception { | ||
Class<?> type = | ||
MockAnnotationProcessor.inferStaticMock( | ||
MockAnnotationProcessorTest.class | ||
.getDeclaredField("nonGeneric") | ||
.getGenericType(), | ||
"nonGeneric"); | ||
assertThat(type).isEqualTo(Void.class); | ||
} | ||
|
||
@Test(expected = MockitoException.class) | ||
public void testGeneric() throws Exception { | ||
MockAnnotationProcessor.inferStaticMock( | ||
MockAnnotationProcessorTest.class.getDeclaredField("generic").getGenericType(), | ||
"generic"); | ||
} | ||
|
||
@Test(expected = MockitoException.class) | ||
public void testRaw() throws Exception { | ||
MockAnnotationProcessor.inferStaticMock( | ||
MockAnnotationProcessorTest.class.getDeclaredField("raw").getGenericType(), "raw"); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
...itJupiterInlineMockMakerExtensionTest/junitJupiterInlineMockMakerExtensionTest.gradle.kts
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 @@ | ||
apply(from = "$rootDir/gradle/dependencies.gradle") | ||
|
||
plugins { | ||
java | ||
} | ||
|
||
description = "End-to-end tests for automatic registration of MockitoExtension with the inline mock maker." | ||
|
||
dependencies { | ||
testCompile(project(":junit-jupiter")) | ||
testCompile(library("assertj")) | ||
testCompile(library("junitPlatformLauncher")) | ||
testCompile(library("junitJupiterApi")) | ||
testRuntime(library("junitJupiterEngine")) | ||
} | ||
|
||
tasks.named<Test>("test") { | ||
useJUnitPlatform() | ||
} | ||
|
||
val Project.libraries | ||
get() = rootProject.extra["libraries"] as Map<String, Any> | ||
|
||
fun Project.library(name: String) = | ||
libraries[name]!! |
25 changes: 25 additions & 0 deletions
25
...unitJupiterInlineMockMakerExtensionTest/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.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockedStatic; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
class NoExtendsTest { | ||
|
||
@Mock | ||
private MockedStatic<UUID> mock; | ||
|
||
@Test | ||
void runs() { | ||
mock.when(UUID::randomUUID).thenReturn(new UUID(123, 456)); | ||
assertThat(UUID.randomUUID()).isEqualTo(new UUID(123, 456)); | ||
} | ||
} |
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
...cts/junitJupiterInlineMockMakerExtensionTest/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 |
1 change: 1 addition & 0 deletions
1
...ockMakerExtensionTest/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
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 @@ | ||
mock-maker-inline |