@@ -13,40 +13,41 @@ import org.springframework.http.HttpStatus
1313import org.springframework.test.context.junit4.SpringRunner
1414
1515@RunWith(SpringRunner ::class )
16- @SpringBootTest(classes = arrayOf(KotlinDemoApplication ::class ), webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
16+ @SpringBootTest(
17+ classes = arrayOf(KotlinDemoApplication ::class ),
18+ webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
1719class KotlinDemoApplicationIntegrationTest {
1820
1921 @Autowired
20- val testRestTemplate: TestRestTemplate ? = null
22+ lateinit var testRestTemplate: TestRestTemplate
2123
2224 @Test
23- fun contextLoads () {
24- }
25-
26- @Test
27- fun testHelloController () {
28- val result = testRestTemplate?.getForEntity(" /hello" , String ::class .java)
25+ fun whenCalled_thenShouldReturnHello () {
26+ val result = testRestTemplate.withBasicAuth(" user" , " pass" )
27+ .getForEntity(" /hello" , String ::class .java)
2928
3029 assertNotNull(result)
31- assertEquals(result?.statusCode, HttpStatus . OK )
32- assertEquals(result?.body, " hello world" )
30+ assertEquals(HttpStatus . OK , result?.statusCode )
31+ assertEquals(" hello world" , result?.body )
3332 }
3433
3534 @Test
36- fun testHelloService () {
37- val result = testRestTemplate?.getForEntity(" /hello-service" , String ::class .java)
35+ fun whenCalled_thenShouldReturnHelloService () {
36+ val result = testRestTemplate.withBasicAuth(" user" , " pass" )
37+ .getForEntity(" /hello-service" , String ::class .java)
3838
3939 assertNotNull(result)
40- assertEquals(result?.statusCode, HttpStatus . OK )
40+ assertEquals(HttpStatus . OK , result?.statusCode )
4141 assertEquals(result?.body, " hello service" )
4242 }
4343
4444 @Test
45- fun testHelloDto () {
46- val result = testRestTemplate?.getForEntity(" /hello-dto" , HelloDto ::class .java)
45+ fun whenCalled_thenShouldReturnJson () {
46+ val result = testRestTemplate.withBasicAuth(" user" , " pass" )
47+ .getForEntity(" /hello-dto" , HelloDto ::class .java)
4748
4849 assertNotNull(result)
49- assertEquals(result?.statusCode, HttpStatus . OK )
50+ assertEquals(HttpStatus . OK , result?.statusCode )
5051 assertEquals(result?.body, HelloDto (" Hello from the dto" ))
5152 }
5253
0 commit comments