質問編集履歴

3

ご質問いただいた、バージョン情報、gradle.buildのソースを追記しました。

2020/05/26 03:03

投稿

Y.Takahashi
Y.Takahashi

スコア5

test CHANGED
File without changes
test CHANGED
@@ -121,3 +121,129 @@
121
121
 
122
122
 
123
123
  よろしくお願いいたします。
124
+
125
+
126
+
127
+ **追記**
128
+
129
+ Gradleのバージョンは6.3で、Junit5は5.6.0、PowerMockはpowermock-mockito2-2.0.2-full.jarを使用しております。
130
+
131
+ Mockitoにつきましてはgradle.buildを見た感じ2.xだと思われます。
132
+
133
+
134
+
135
+ 以下がgradle.buildになります。
136
+
137
+ 私自身はgradleに明るくなく他の方に書いてもらったもののため、説明はできません。
138
+
139
+
140
+
141
+ ```
142
+
143
+ plugins {
144
+
145
+ id 'org.springframework.boot' version '2.2.6.RELEASE'
146
+
147
+ id 'io.spring.dependency-management' version '1.0.9.RELEASE'
148
+
149
+ id 'java'
150
+
151
+ }
152
+
153
+
154
+
155
+
156
+
157
+ configurations {
158
+
159
+ developmentOnly
160
+
161
+ runtimeClasspath {
162
+
163
+ extendsFrom developmentOnly
164
+
165
+ }
166
+
167
+ compileOnly {
168
+
169
+ extendsFrom annotationProcessor
170
+
171
+ }
172
+
173
+ // SLF4Jを使わない設定
174
+
175
+ all*.exclude module : 'spring-boot-starter-logging'
176
+
177
+ }
178
+
179
+
180
+
181
+ repositories {
182
+
183
+ mavenCentral()
184
+
185
+ }
186
+
187
+
188
+
189
+ dependencies {
190
+
191
+ implementation 'org.springframework.boot:spring-boot-starter-activemq'
192
+
193
+ implementation 'org.springframework.boot:spring-boot-starter-web'
194
+
195
+ implementation 'org.springframework.boot:spring-boot-starter-web-services'
196
+
197
+ compileOnly 'org.projectlombok:lombok'
198
+
199
+ runtimeOnly 'org.postgresql:postgresql'
200
+
201
+ developmentOnly 'org.springframework.boot:spring-boot-devtools'
202
+
203
+ annotationProcessor 'org.projectlombok:lombok'
204
+
205
+ testImplementation('org.springframework.boot:spring-boot-starter-test') {
206
+
207
+ exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
208
+
209
+ }
210
+
211
+
212
+
213
+ // Log4J2を使うので追加
214
+
215
+ implementation 'org.springframework.boot:spring-boot-starter-log4j2'
216
+
217
+
218
+
219
+ // OpenAPI用
220
+
221
+ implementation 'io.springfox:springfox-swagger2:2.8.0'
222
+
223
+ implementation 'io.springfox:springfox-swagger-ui:2.8.0'
224
+
225
+ implementation 'org.openapitools:jackson-databind-nullable:0.1.0'
226
+
227
+
228
+
229
+ implementation 'org.apache.activemq:activemq-pool:5.9.0'
230
+
231
+
232
+
233
+ compile fileTree(dir: 'lib', include: '*.jar')
234
+
235
+ testCompile "org.mockito:mockito-core:2.+"
236
+
237
+ }
238
+
239
+
240
+
241
+ test {
242
+
243
+ useJUnitPlatform()
244
+
245
+ }
246
+
247
+
248
+
249
+ ```

2

Junitソースの誤記修正

2020/05/26 03:03

投稿

Y.Takahashi
Y.Takahashi

スコア5

test CHANGED
File without changes
test CHANGED
@@ -62,7 +62,7 @@
62
62
 
63
63
  @PrepareForTest({ URL.class })
64
64
 
65
- public class ReserveInformationTest {
65
+ public class SampleTest {
66
66
 
67
67
 
68
68
 

1

Junitソースを一部追記、修正しました。

2020/05/26 02:19

投稿

Y.Takahashi
Y.Takahashi

スコア5

test CHANGED
File without changes
test CHANGED
@@ -60,25 +60,55 @@
60
60
 
61
61
  ```
62
62
 
63
- @Test
63
+ @PrepareForTest({ URL.class })
64
64
 
65
- public void function() throws Exception{
65
+ public class ReserveInformationTest {
66
66
 
67
- ReserveInformation rsvinfo = new ReserveInformation();
68
67
 
69
- URL u = PowerMockito.mock(URL.class);
70
68
 
71
- PowerMockito.whenNew(URL.class).withArguments(anyString(), anyString(), anyInt(), anyString()).thenReturn(u);
69
+ @Mock
72
70
 
73
- HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
71
+ HttpURLConnection urlConn;
74
72
 
75
- PowerMockito.when(u.openConnection()).thenReturn(huc);
76
73
 
77
- PowerMockito.when(huc.getResponseCode()).thenReturn(200);
78
74
 
79
- Sample sample = new Sample();
75
+ @Mock
80
76
 
77
+ PrintStream ps;
78
+
79
+
80
+
81
+ @Mock
82
+
83
+ BufferedReader reader;
84
+
85
+
86
+
87
+ @InjectMocks
88
+
89
+ Sample sample = new Sample();
90
+
91
+
92
+
93
+ @Test
94
+
95
+ public void function() throws Exception{
96
+
97
+ ReserveInformation rsvinfo = new ReserveInformation();
98
+
99
+ URL u = PowerMockito.mock(URL.class);
100
+
101
+ PowerMockito.whenNew(URL.class).withArguments(anyString(), anyString(), anyInt(), anyString()).thenReturn(u);
102
+
103
+ HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
104
+
105
+ PowerMockito.when(u.openConnection()).thenReturn(huc);
106
+
107
+ PowerMockito.when(huc.getResponseCode()).thenReturn(200);
108
+
81
- sample.openConnection();
109
+ sample.openConnection();
110
+
111
+ }
82
112
 
83
113
  }
84
114