Skip to content

Commit

Permalink
Fixes mockito#3229: Resolve test generic arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef3wi committed Feb 2, 2024
1 parent 9972676 commit 00ae4c1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Expand Up @@ -27,7 +27,7 @@ public Class<?> getGenericType(Field field) {
* @param parameter the parameter to inspect
*/
public Class<?> getGenericType(Parameter parameter) {
return getaClass(parameter.getType());
return getaClass(parameter.getParameterizedType());
}

private Class<?> getaClass(Type generic) {
Expand Down
@@ -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());
}
}

0 comments on commit 00ae4c1

Please sign in to comment.