Created
February 16, 2018 01:14
-
-
Save rastadrian/b5584f0d0b76daaf3a9aa7f325fb0f91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface PersonServiceClient { | |
| Person getPerson(String id); | |
| } | |
| @Component | |
| public class MyComponent { | |
| private final PersonServiceClient personServiceClient; | |
| public MyComponent(PersonServiceClient personServiceClient) { | |
| this.personServiceClient = personServiceClient; | |
| } | |
| public boolean isAdult(String personId) { | |
| Person person = personServiceClient.getPerson(personId); | |
| return person.getAge() > 18; | |
| } | |
| } | |
| public class MyComponentTest { | |
| private MyComponent myComponent; | |
| private PersonServiceClient personServiceClient; | |
| @Before | |
| public void setup() throws Exception { | |
| personServiceClient = Mockito.mock(PersonServiceClient.class); | |
| myComponent = new MyComponent(personServiceClient); | |
| } | |
| @Test | |
| public void isAdultWhileMinor() throws Exception { | |
| //Given | |
| String personId = "123"; | |
| Person person = new Person(); | |
| person.setId(personid); | |
| person.setAge(14); | |
| Mockito.when(personServiceClient.getPerson(eq(personId))).thenReturn(person); | |
| //When | |
| boolean isAdult = myComponent.isAdult(personId); | |
| //Then | |
| AssertJ.assertThat(isAdult).isFalse(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment