-
Notifications
You must be signed in to change notification settings - Fork 508
/
Copy pathjava-tests.json
194 lines (194 loc) · 7.54 KB
/
java-tests.json
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
{
"JUnit 4 - Imports for Tests": {
"prefix": "imports_junit4",
"body": [
"import static org.hamcrest.Matchers.*;",
"import static org.junit.Assert.assertEquals;",
"import static org.junit.Assert.assertThat;",
"import static org.mockito.Mockito.*;",
"import org.hamcrest.CoreMatchers;",
"import org.junit.After;",
"import org.junit.Before;",
"import org.junit.Test;",
"import org.mockito.ArgumentCaptor;",
"import org.mockito.Mock;"
],
"description": "Imports to write tests with JUnit 4, Mockito and Hamcrest"
},
"JUnit 5 - Imports for Tests": {
"prefix": "imports_junit5",
"body": [
"import static org.hamcrest.Matchers.*;",
"import static org.hamcrest.MatcherAssert.assertThat;",
"import static org.junit.jupiter.api.Assertions.assertEquals;",
"import static org.mockito.Mockito.*;",
"import org.hamcrest.CoreMatchers;",
"import org.junit.jupiter.api.AfterEach;",
"import org.junit.jupiter.api.BeforeEach;",
"import org.junit.jupiter.api.DisplayName;",
"import org.junit.jupiter.api.Test;",
"import org.junit.jupiter.api.extension.ExtendWith;",
"import org.junit.jupiter.params.ParameterizedTest;",
"import org.junit.jupiter.params.provider.CsvSource;",
"import org.mockito.ArgumentCaptor;",
"import org.mockito.junit.jupiter.MockitoExtension;",
"import org.mockito.Mock;"
],
"description": "Imports to write tests with JUnit 4, Mockito and Hamcrest"
},
"Assert - equals": {
"prefix": "test_equals",
"body": ["assertEquals(${1:anObject}, ${2:anotherObject});"],
"description": "assert equals"
},
"Assert - is": {
"prefix": "test_is",
"body": [
"assertThat(${1:mockedService.executeMagic()}, is(${2:\"42\"}));"
],
"description": "assert that is"
},
"Assert - is null": {
"prefix": "test_null",
"body": ["assertThat(${1:mockedService.executeMagic()}, nullValue());"],
"description": "assert that is null"
},
"Assert - is not null": {
"prefix": "test_not_null",
"body": [
"assertThat(${1:mockedService.executeMagic()}, notNullValue());"
],
"description": "assert that is not null"
},
"Assert - string is null or empty": {
"prefix": "test_nullorempty",
"body": [
"assertThat(${1:mockedService.executeMagic()}, emptyOrNullString());"
],
"description": "assert that a string is null or empty"
},
"Assert - string is not null and not empty": {
"prefix": "test_not_nullorempty",
"body": [
"assertThat(${1:mockedService.executeMagic()}, not(emptyOrNullString()));"
],
"description": "assert that string is not null or empty"
},
"Assert - isOneOf": {
"prefix": "test_isOneOf",
"body": ["assertThat(${1:\"Test\"}, isOneOf(${2:\"Test\", \"TDD\"}));"],
"description": "assert that isOneOf"
},
"Assert - hasSize": {
"prefix": "test_hasSize",
"body": ["assertThat(List.of(\"Test\", \"TDD\"), hasSize(2));"],
"description": "assert that hasSize"
},
"Assert - hasItem": {
"prefix": "test_hasItem",
"body": [
"assertThat(${1:List.of(\"Test\", \"TDD\")}, hasItem(${2:\"Test\"}));"
],
"description": "assert that hasItem"
},
"Assert - hasItems": {
"prefix": "test_hasItems",
"body": [
"assertThat(${1:List.of(\"Test\", \"TDD\")}, hasItem(${2:List.of(\"Test\", \"TDD\")}));"
],
"description": "assert that hasItem"
},
"Assert - isIn": {
"prefix": "test_isIn",
"body": [
"assertThat(${1:\"test\"}, isIn(${2:List.of(\"test\", \"TDD\")}));"
],
"description": "assert that isIn"
},
"Mockito - Create mock": {
"prefix": "mock_class",
"body": [
"${1:MyService} ${2:mockedService} = mock(${1:MyService}.class);"
],
"description": "Create a mock object of a class"
},
"Mock - Method return": {
"prefix": "mock_method_return",
"body": [
"when(${1:mockedService.executeMagicWith(any())}).thenReturn(${2:\"42\"});"
],
"description": "Mock a method's return"
},
"Mock - Method throws": {
"prefix": "mock_method_throw",
"body": [
"when(${1:mockedService.executeMagic()}).thenThrow(new ${2:IllegalArgumentException()};"
],
"description": "Mock a method to throw exception"
},
"Mockito - Verify call only": {
"prefix": "mock_verify_only",
"body": ["verify(${1:mockedService}, only()).${2:executeMagic()};"],
"description": "Verify if a mocked method was the only one called"
},
"Mockito - Verify call once": {
"prefix": "mock_verify_once",
"body": ["verify(${1:mockedService}).${2:executeMagic()};"],
"description": "Verify if a mocked method was called only once"
},
"Mockito - Verify call N times": {
"prefix": "mock_verify_times",
"body": [
"verify(${1:mockedService}, times(${2:2})).${3:executeMagic()};"
],
"description": "Verify if a mocked method was called `n` times"
},
"Mockito - Verify never called": {
"prefix": "mock_verify_never",
"body": ["verify(${1:mockedService}, never()).${2:executeMagic()};"],
"description": "Verify if a mocked method was never called"
},
"Mock - Argument captor": {
"prefix": "mock_arg_capture",
"body": [
"ArgumentCaptor<${1:Object}> ${2:argCaptor} = ArgumentCaptor.forClass(${1:Object}.class);",
"verify(${3:mockedService}).${4:executeMagicWith}(${2:argCaptor}.capture());",
"${1:Object} ${5:actualArg} = ${2:argCaptor}.getValue();"
],
"description": "Capture an argument given to a mocked method"
},
"JUnit 4 - Before each": {
"prefix": "test_before_junit4",
"body": "@Before\npublic void setup() {\n\t${1}\n}",
"description": "Create setup method with `@Before`"
},
"JUnit 4 - After each": {
"prefix": "test_after_junit4",
"body": "@After\npublic void tearDown() {\n\t${1}\n}",
"description": "Create tear down method with `@After`"
},
"JUnit 5 - Before each": {
"prefix": "test_before",
"body": "@BeforeEach\npublic void setup() {\n\t${1}\n}",
"description": "Create setup method with `@BeforeEach`"
},
"JUnit 5 - After each": {
"prefix": "test_after",
"body": "@AfterEach\npublic void tearDown() {\n\t${1}\n}",
"description": "Create tear down method with `@AfterEach`"
},
"JUnit 5 - Assert Throws": {
"prefix": "test_exception",
"body": "Assertions.assertThrows(${1:Exception}.class, () -> {\n\t${0}\n});",
"description": "Assertion to verify if an exception was thrown"
},
"JUnit 5 - Parameterized Test": {
"prefix": "test_parameterized",
"description": "Create parameterized test",
"body": [
"@ParameterizedTest(name = \"${1:{0\\} plus {1\\} should be {2\\}}\"",
"@CsvSource({\n\t${2:\"0, 0, 0\",\n\t\"1, 0, 1\",\n\t\"1, 1, 2\"}\n})",
"public void shouldAddTwoNumbers(int x, int y, int expectedSum) {\n\t${0}\n}"
]
}
}