Skip to content

Commit 1b9f985

Browse files
danil-pavlovsdeleuze
authored andcommitted
Internal review
Signed-off-by: Danil Pavlov <danil.pavlov@jetbrains.com>
1 parent b3c996c commit 1b9f985

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

README.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ listing shows:
197197
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
198198
.Java
199199
----
200-
include::complete/src/test/java/com/example/testingweb/WebLayerTest.java[tags=test]
200+
include::complete/src/test/java/com/example/testingweb/WebLayerTest.java[]
201201
----
202202
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
203203
.Kotlin
204204
----
205-
include::complete-kotlin/src/test/kotlin/com/example/testingweb/WebLayerTest.kt[tags=test]
205+
include::complete-kotlin/src/test/kotlin/com/example/testingweb/WebLayerTest.kt[]
206206
----
207207

208208
The test assertion is the same as in the previous case. However, in this test, Spring Boot
@@ -247,7 +247,7 @@ with `@WebMvcTest`:
247247
----
248248
include::complete/src/test/java/com/example/testingweb/WebMockTest.java[]
249249
----
250-
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
250+
[source,kotlin,indent=0,subs="verbatim",role="secondary"]
251251
.Kotlin
252252
----
253253
include::complete-kotlin/src/test/kotlin/com/example/testingweb/WebMockTest.kt[]

complete-kotlin/src/test/kotlin/com/example/testingweb/HttpRequestTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired
66
import org.springframework.boot.test.context.SpringBootTest
77
import org.springframework.boot.test.web.client.TestRestTemplate
88
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
9+
import org.springframework.boot.test.web.client.getForObject
910
import org.springframework.boot.test.web.server.LocalServerPort
1011

1112
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@@ -19,7 +20,8 @@ class HttpRequestTest {
1920

2021
@Test
2122
fun greetingShouldReturnDefaultMessage() {
22-
assertThat(this.restTemplate.getForObject("http://localhost:$port/", String::class.java))
23+
// Import Kotlin .getForObject() extension that allows using reified type parameters
24+
assertThat(this.restTemplate.getForObject<String>("http://localhost:$port/"))
2325
.contains("Hello, World")
2426
}
25-
}
27+
}

complete-kotlin/src/test/kotlin/com/example/testingweb/WebLayerTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
1111
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
1212

1313
@WebMvcTest(HomeController::class)
14-
//tag::test[]
1514
class WebLayerTest {
1615

1716
@Autowired
@@ -25,4 +24,3 @@ class WebLayerTest {
2524
.andExpect(content().string(containsString("Hello, World")))
2625
}
2726
}
28-
//end::test[]

complete/src/test/java/com/example/testingweb/WebLayerTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
66
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
77
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
8-
98
import org.junit.jupiter.api.Test;
10-
119
import org.springframework.beans.factory.annotation.Autowired;
1210
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
1311
import org.springframework.test.web.servlet.MockMvc;
1412

1513
@WebMvcTest(HomeController.class)
16-
//tag::test[]
1714
class WebLayerTest {
1815

1916
@Autowired
@@ -25,4 +22,3 @@ void shouldReturnDefaultMessage() throws Exception {
2522
.andExpect(content().string(containsString("Hello, World")));
2623
}
2724
}
28-
//end::test[]

0 commit comments

Comments
 (0)