Update mock injection example to make the behavior clear
This commit is contained in:
parent
db1c78cb79
commit
a0ee0ccabc
|
@ -5,6 +5,6 @@ import org.springframework.stereotype.Service;
|
||||||
@Service
|
@Service
|
||||||
public class NameService {
|
public class NameService {
|
||||||
public String getUserName(String id) {
|
public String getUserName(String id) {
|
||||||
return "Baeldung";
|
return "Real user name";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ public class UserServiceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUserIdIsProvided_thenRetrievedNameIsCorrect() {
|
public void whenUserIdIsProvided_thenRetrievedNameIsCorrect() {
|
||||||
Mockito.when(nameService.getUserName("SomeId")).thenReturn("Baeldung");
|
Mockito.when(nameService.getUserName("SomeId")).thenReturn("Mock user name");
|
||||||
|
|
||||||
String testName = userService.getUserName("SomeId");
|
String testName = userService.getUserName("SomeId");
|
||||||
|
|
||||||
Assert.assertEquals("Baeldung", testName);
|
Assert.assertEquals("Mock user name", testName);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue