From d1b7c0ed991be9477d56eae9ebbc1f2f814fc4e6 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Fri, 16 Sep 2016 23:27:58 +0200 Subject: [PATCH] #942 #943 Unit test NewAPI registered names methods --- .../java/fr/xephi/authme/api/NewAPITest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/test/java/fr/xephi/authme/api/NewAPITest.java b/src/test/java/fr/xephi/authme/api/NewAPITest.java index 6ef096a2b..35cc7d308 100644 --- a/src/test/java/fr/xephi/authme/api/NewAPITest.java +++ b/src/test/java/fr/xephi/authme/api/NewAPITest.java @@ -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 auths = Arrays.stream(names) + .map(name -> PlayerAuth.builder().name(name).build()) + .collect(Collectors.toList()); + given(dataSource.getAllAuths()).willReturn(auths); + + // when + List result = api.getRegisteredNames(); + + // then + assertThat(result, contains(names)); + } + + @Test + public void shouldReturnAuthRealNames() { + // given + String[] names = {"Bobby", "peter", "Elisabeth", "CRAIG"}; + List auths = Arrays.stream(names) + .map(name -> PlayerAuth.builder().name(name).realName(name).build()) + .collect(Collectors.toList()); + given(dataSource.getAllAuths()).willReturn(auths); + + // when + List result = api.getRegisteredRealNames(); + + // then + assertThat(result, contains(names)); + } + private static Player mockPlayerWithName(String name) { Player player = mock(Player.class); given(player.getName()).willReturn(name);