質問編集履歴
3
ご質問いただいた、バージョン情報、gradle.buildのソースを追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -59,4 +59,67 @@
|
|
59
59
|
|
60
60
|
java初心者のため、細かい説明もいただけると助かります。
|
61
61
|
|
62
|
-
よろしくお願いいたします。
|
62
|
+
よろしくお願いいたします。
|
63
|
+
|
64
|
+
**追記**
|
65
|
+
Gradleのバージョンは6.3で、Junit5は5.6.0、PowerMockはpowermock-mockito2-2.0.2-full.jarを使用しております。
|
66
|
+
Mockitoにつきましてはgradle.buildを見た感じ2.xだと思われます。
|
67
|
+
|
68
|
+
以下がgradle.buildになります。
|
69
|
+
私自身はgradleに明るくなく他の方に書いてもらったもののため、説明はできません。
|
70
|
+
|
71
|
+
```
|
72
|
+
plugins {
|
73
|
+
id 'org.springframework.boot' version '2.2.6.RELEASE'
|
74
|
+
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
75
|
+
id 'java'
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
configurations {
|
80
|
+
developmentOnly
|
81
|
+
runtimeClasspath {
|
82
|
+
extendsFrom developmentOnly
|
83
|
+
}
|
84
|
+
compileOnly {
|
85
|
+
extendsFrom annotationProcessor
|
86
|
+
}
|
87
|
+
// SLF4Jを使わない設定
|
88
|
+
all*.exclude module : 'spring-boot-starter-logging'
|
89
|
+
}
|
90
|
+
|
91
|
+
repositories {
|
92
|
+
mavenCentral()
|
93
|
+
}
|
94
|
+
|
95
|
+
dependencies {
|
96
|
+
implementation 'org.springframework.boot:spring-boot-starter-activemq'
|
97
|
+
implementation 'org.springframework.boot:spring-boot-starter-web'
|
98
|
+
implementation 'org.springframework.boot:spring-boot-starter-web-services'
|
99
|
+
compileOnly 'org.projectlombok:lombok'
|
100
|
+
runtimeOnly 'org.postgresql:postgresql'
|
101
|
+
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
102
|
+
annotationProcessor 'org.projectlombok:lombok'
|
103
|
+
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
104
|
+
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
105
|
+
}
|
106
|
+
|
107
|
+
// Log4J2を使うので追加
|
108
|
+
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
|
109
|
+
|
110
|
+
// OpenAPI用
|
111
|
+
implementation 'io.springfox:springfox-swagger2:2.8.0'
|
112
|
+
implementation 'io.springfox:springfox-swagger-ui:2.8.0'
|
113
|
+
implementation 'org.openapitools:jackson-databind-nullable:0.1.0'
|
114
|
+
|
115
|
+
implementation 'org.apache.activemq:activemq-pool:5.9.0'
|
116
|
+
|
117
|
+
compile fileTree(dir: 'lib', include: '*.jar')
|
118
|
+
testCompile "org.mockito:mockito-core:2.+"
|
119
|
+
}
|
120
|
+
|
121
|
+
test {
|
122
|
+
useJUnitPlatform()
|
123
|
+
}
|
124
|
+
|
125
|
+
```
|
2
Junitソースの誤記修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
以下がJunitソースになります。
|
31
31
|
```
|
32
32
|
@PrepareForTest({ URL.class })
|
33
|
-
public class
|
33
|
+
public class SampleTest {
|
34
34
|
|
35
35
|
@Mock
|
36
36
|
HttpURLConnection urlConn;
|
1
Junitソースを一部追記、修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -29,16 +29,31 @@
|
|
29
29
|
|
30
30
|
以下がJunitソースになります。
|
31
31
|
```
|
32
|
+
@PrepareForTest({ URL.class })
|
33
|
+
public class ReserveInformationTest {
|
34
|
+
|
35
|
+
@Mock
|
36
|
+
HttpURLConnection urlConn;
|
37
|
+
|
38
|
+
@Mock
|
39
|
+
PrintStream ps;
|
40
|
+
|
41
|
+
@Mock
|
42
|
+
BufferedReader reader;
|
43
|
+
|
44
|
+
@InjectMocks
|
45
|
+
Sample sample = new Sample();
|
46
|
+
|
32
|
-
@Test
|
47
|
+
@Test
|
33
|
-
public void function() throws Exception{
|
48
|
+
public void function() throws Exception{
|
34
|
-
|
49
|
+
ReserveInformation rsvinfo = new ReserveInformation();
|
35
|
-
|
50
|
+
URL u = PowerMockito.mock(URL.class);
|
36
|
-
|
51
|
+
PowerMockito.whenNew(URL.class).withArguments(anyString(), anyString(), anyInt(), anyString()).thenReturn(u);
|
37
|
-
|
52
|
+
HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
|
38
|
-
|
53
|
+
PowerMockito.when(u.openConnection()).thenReturn(huc);
|
39
|
-
|
54
|
+
PowerMockito.when(huc.getResponseCode()).thenReturn(200);
|
40
|
-
Sample sample = new Sample();
|
41
|
-
|
55
|
+
sample.openConnection();
|
56
|
+
}
|
42
57
|
}
|
43
58
|
```
|
44
59
|
|