2016-01-19 06:12:11 -06:00
|
|
|
package com.baeldung;
|
2016-01-10 17:07:41 +02:00
|
|
|
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.mockito.Mockito;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-01-05 21:56:21 +02:00
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
2016-01-10 17:07:41 +02:00
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
|
|
|
|
|
@ActiveProfiles("test")
|
|
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
2018-01-05 21:56:21 +02:00
|
|
|
@SpringBootTest(classes = MocksApplication.class)
|
2016-10-18 13:29:59 +02:00
|
|
|
public class UserServiceIntegrationTest {
|
2016-01-10 17:07:41 +02:00
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserService userService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private NameService nameService;
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void whenUserIdIsProvided_thenRetrievedNameIsCorrect() {
|
2016-01-19 06:13:36 -06:00
|
|
|
Mockito.when(nameService.getUserName("SomeId")).thenReturn("Mock user name");
|
2016-01-10 17:07:41 +02:00
|
|
|
|
|
|
|
|
String testName = userService.getUserName("SomeId");
|
|
|
|
|
|
2016-01-19 06:13:36 -06:00
|
|
|
Assert.assertEquals("Mock user name", testName);
|
2016-01-10 17:07:41 +02:00
|
|
|
}
|
|
|
|
|
}
|