forked from mockito/mockito
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes mockito#3229: Resolve test generic arguments
- Loading branch information
1 parent
9972676
commit 00ae4c1
Showing
2 changed files
with
53 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
...-jupiter/src/test/java/org/mockitousage/annotation/CaptorAnnotationWithPrimitiveTest.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,52 @@ | ||
package org.mockitousage.annotation; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Captor; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.doNothing; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class CaptorAnnotationWithPrimitiveTest { | ||
@Mock | ||
private Foo foo; | ||
|
||
private AutoCloseable closeable; | ||
|
||
static class Foo { | ||
void doSomething(int value) { | ||
} | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
closeable = MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() throws Exception { | ||
if (closeable != null) { | ||
closeable.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldCaptorPrimitive(@Captor ArgumentCaptor<Integer> captor) { | ||
// Given | ||
int value = 1; | ||
|
||
// When | ||
doNothing().when(foo).doSomething(captor.capture()); | ||
|
||
// Then | ||
foo.doSomething(value); | ||
assertEquals(1, captor.getValue()); | ||
} | ||
} |