/
MockAnnotationProcessorTest.java
69 lines (59 loc) · 2.44 KB
/
MockAnnotationProcessorTest.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) 2020 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.List;
import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.exceptions.base.MockitoException;
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.inferParameterizedType(
MockAnnotationProcessorTest.class
.getDeclaredField("nonGeneric")
.getGenericType(),
"nonGeneric",
"Sample");
assertThat(type).isEqualTo(Void.class);
}
@Test
public void testGeneric() {
assertThatThrownBy(
() -> {
MockAnnotationProcessor.inferParameterizedType(
MockAnnotationProcessorTest.class
.getDeclaredField("generic")
.getGenericType(),
"generic",
"Sample");
})
.isInstanceOf(MockitoException.class)
.hasMessageContaining(
"Mockito cannot infer a static mock from a raw type for generic");
}
@Test
public void testRaw() {
assertThatThrownBy(
() -> {
MockAnnotationProcessor.inferParameterizedType(
MockAnnotationProcessorTest.class
.getDeclaredField("raw")
.getGenericType(),
"raw",
"Sample");
})
.isInstanceOf(MockitoException.class)
.hasMessageContaining("Mockito cannot infer a static mock from a raw type for raw");
}
}