Minor householding in tests

- Add missing test for injector
- Remove redundant Mock fields
This commit is contained in:
ljacqu 2016-06-15 21:24:57 +02:00
parent ac484345a2
commit acd4a772e8
6 changed files with 49 additions and 8 deletions

View File

@ -56,8 +56,6 @@ public class CommandHandlerTest {
@Mock
private AuthMeServiceInitializer initializer;
@Mock
private CommandInitializer commandInitializer;
@Mock
private CommandMapper commandMapper;
@Mock
private PermissionsManager permissionsManager;

View File

@ -36,8 +36,6 @@ public class AccountsCommandTest {
@InjectMocks
private AccountsCommand command;
@Mock
private CommandSender sender;
@Mock
private CommandService service;
@Mock
private DataSource dataSource;
@ -47,6 +45,7 @@ public class AccountsCommandTest {
@Test
public void shouldGetAccountsOfCurrentUser() {
// given
CommandSender sender = mock(CommandSender.class);
given(sender.getName()).willReturn("Tester");
List<String> arguments = Collections.emptyList();
given(dataSource.getAuth("tester")).willReturn(authWithIp("123.45.67.89"));
@ -65,6 +64,7 @@ public class AccountsCommandTest {
@Test
public void shouldReturnUnknownUserForNullAuth() {
// given
CommandSender sender = mock(CommandSender.class);
List<String> arguments = Collections.singletonList("SomeUser");
given(dataSource.getAuth("someuser")).willReturn(null);
@ -80,6 +80,7 @@ public class AccountsCommandTest {
@Test
public void shouldReturnUnregisteredMessageForEmptyAuthList() {
// given
CommandSender sender = mock(CommandSender.class);
List<String> arguments = Collections.singletonList("SomeUser");
given(dataSource.getAuth("someuser")).willReturn(mock(PlayerAuth.class));
given(dataSource.getAllAuthsByIp(anyString())).willReturn(Collections.<String>emptyList());
@ -96,6 +97,7 @@ public class AccountsCommandTest {
@Test
public void shouldReturnSingleAccountMessage() {
// given
CommandSender sender = mock(CommandSender.class);
List<String> arguments = Collections.singletonList("SomeUser");
given(dataSource.getAuth("someuser")).willReturn(authWithIp("56.78.90.123"));
given(dataSource.getAllAuthsByIp("56.78.90.123")).willReturn(Collections.singletonList("SomeUser"));
@ -115,6 +117,7 @@ public class AccountsCommandTest {
@Test
public void shouldReturnIpUnknown() {
// given
CommandSender sender = mock(CommandSender.class);
List<String> arguments = Collections.singletonList("123.45.67.89");
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Collections.<String>emptyList());
@ -130,6 +133,7 @@ public class AccountsCommandTest {
@Test
public void shouldReturnSingleAccountForIpQuery() {
// given
CommandSender sender = mock(CommandSender.class);
List<String> arguments = Collections.singletonList("24.24.48.48");
given(dataSource.getAllAuthsByIp("24.24.48.48")).willReturn(Collections.singletonList("SomeUser"));
@ -145,6 +149,7 @@ public class AccountsCommandTest {
@Test
public void shouldReturnAccountListForIpQuery() {
// given
CommandSender sender = mock(CommandSender.class);
List<String> arguments = Collections.singletonList("98.76.41.122");
given(dataSource.getAllAuthsByIp("98.76.41.122")).willReturn(Arrays.asList("Tester", "Lester", "Taster"));

View File

@ -316,6 +316,22 @@ public class AuthMeServiceInitializerTest {
initializer.performReloadOnServices();
}
@Test
public void shouldRetrieveExistingInstancesOnly() {
// given
initializer.get(GammaService.class);
// when
AlphaService alphaService = initializer.getIfAvailable(AlphaService.class);
BetaManager betaManager = initializer.getIfAvailable(BetaManager.class);
// then
// was initialized because is dependency of GammaService
assertThat(alphaService, not(nullValue()));
// nothing caused this to be initialized
assertThat(betaManager, nullValue());
}
private void expectRuntimeExceptionWith(String message) {
expectedException.expect(RuntimeException.class);
expectedException.expectMessage(containsString(message));

View File

@ -2,6 +2,8 @@ package fr.xephi.authme.process;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.AuthGroupHandler;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
@ -43,6 +45,9 @@ public class ProcessServiceTest {
@Mock
private PermissionsManager permissionsManager;
@Mock
private AuthGroupHandler authGroupHandler;
@Test
public void shouldGetProperty() {
// given
@ -166,4 +171,19 @@ public class ProcessServiceTest {
verify(permissionsManager).hasPermission(player, permission);
assertThat(result, equalTo(true));
}
@Test
public void shouldSetPermissionGroup() {
// given
Player player = mock(Player.class);
AuthGroupType type = AuthGroupType.LOGGED_IN;
given(authGroupHandler.setGroup(player, type)).willReturn(true);
// when
boolean result = processService.setGroup(player, type);
// then
verify(authGroupHandler).setGroup(player, type);
assertThat(result, equalTo(true));
}
}

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.util;
import fr.xephi.authme.TestHelper;
import org.junit.Test;
import java.io.File;
@ -145,4 +146,9 @@ public class StringUtilsTest {
// then
assertThat(result, equalTo("path" + File.separator + "to" + File.separator + "test-file.txt"));
}
@Test
public void shouldHaveHiddenConstructor() {
TestHelper.validateHasOnlyPrivateEmptyConstructor(StringUtils.class);
}
}

View File

@ -5,7 +5,6 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.events.FirstSpawnTeleportEvent;
import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.RestrictionSettings;
@ -48,9 +47,6 @@ public class TeleportationServiceTest {
@Mock
private NewSetting settings;
@Mock
private Messages messages;
@Mock
private BukkitService bukkitService;