#942 #943 Unit test NewAPI registered names methods

This commit is contained in:
ljacqu 2016-09-16 23:27:58 +02:00
parent 25df3ce032
commit d1b7c0ed99

View File

@ -20,6 +20,11 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
@ -175,6 +180,38 @@ public class NewAPITest {
assertThat(result, equalTo(true));
}
@Test
public void shouldReturnAuthNames() {
// given
String[] names = {"bobby", "peter", "elisabeth", "craig"};
List<PlayerAuth> auths = Arrays.stream(names)
.map(name -> PlayerAuth.builder().name(name).build())
.collect(Collectors.toList());
given(dataSource.getAllAuths()).willReturn(auths);
// when
List<String> result = api.getRegisteredNames();
// then
assertThat(result, contains(names));
}
@Test
public void shouldReturnAuthRealNames() {
// given
String[] names = {"Bobby", "peter", "Elisabeth", "CRAIG"};
List<PlayerAuth> auths = Arrays.stream(names)
.map(name -> PlayerAuth.builder().name(name).realName(name).build())
.collect(Collectors.toList());
given(dataSource.getAllAuths()).willReturn(auths);
// when
List<String> result = api.getRegisteredRealNames();
// then
assertThat(result, contains(names));
}
private static Player mockPlayerWithName(String name) {
Player player = mock(Player.class);
given(player.getName()).willReturn(name);