Skip to content

Instantly share code, notes, and snippets.

@rastadrian
Created February 16, 2018 01:14
Show Gist options
  • Select an option

  • Save rastadrian/b5584f0d0b76daaf3a9aa7f325fb0f91 to your computer and use it in GitHub Desktop.

Select an option

Save rastadrian/b5584f0d0b76daaf3a9aa7f325fb0f91 to your computer and use it in GitHub Desktop.
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