Minor householding in tests
- Add missing test for injector - Remove redundant Mock fields
This commit is contained in:
parent
ac484345a2
commit
acd4a772e8
@ -56,8 +56,6 @@ public class CommandHandlerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private AuthMeServiceInitializer initializer;
|
private AuthMeServiceInitializer initializer;
|
||||||
@Mock
|
@Mock
|
||||||
private CommandInitializer commandInitializer;
|
|
||||||
@Mock
|
|
||||||
private CommandMapper commandMapper;
|
private CommandMapper commandMapper;
|
||||||
@Mock
|
@Mock
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
|
|||||||
@ -36,8 +36,6 @@ public class AccountsCommandTest {
|
|||||||
@InjectMocks
|
@InjectMocks
|
||||||
private AccountsCommand command;
|
private AccountsCommand command;
|
||||||
@Mock
|
@Mock
|
||||||
private CommandSender sender;
|
|
||||||
@Mock
|
|
||||||
private CommandService service;
|
private CommandService service;
|
||||||
@Mock
|
@Mock
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
@ -47,6 +45,7 @@ public class AccountsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldGetAccountsOfCurrentUser() {
|
public void shouldGetAccountsOfCurrentUser() {
|
||||||
// given
|
// given
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
given(sender.getName()).willReturn("Tester");
|
given(sender.getName()).willReturn("Tester");
|
||||||
List<String> arguments = Collections.emptyList();
|
List<String> arguments = Collections.emptyList();
|
||||||
given(dataSource.getAuth("tester")).willReturn(authWithIp("123.45.67.89"));
|
given(dataSource.getAuth("tester")).willReturn(authWithIp("123.45.67.89"));
|
||||||
@ -65,6 +64,7 @@ public class AccountsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnUnknownUserForNullAuth() {
|
public void shouldReturnUnknownUserForNullAuth() {
|
||||||
// given
|
// given
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
List<String> arguments = Collections.singletonList("SomeUser");
|
List<String> arguments = Collections.singletonList("SomeUser");
|
||||||
given(dataSource.getAuth("someuser")).willReturn(null);
|
given(dataSource.getAuth("someuser")).willReturn(null);
|
||||||
|
|
||||||
@ -80,6 +80,7 @@ public class AccountsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnUnregisteredMessageForEmptyAuthList() {
|
public void shouldReturnUnregisteredMessageForEmptyAuthList() {
|
||||||
// given
|
// given
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
List<String> arguments = Collections.singletonList("SomeUser");
|
List<String> arguments = Collections.singletonList("SomeUser");
|
||||||
given(dataSource.getAuth("someuser")).willReturn(mock(PlayerAuth.class));
|
given(dataSource.getAuth("someuser")).willReturn(mock(PlayerAuth.class));
|
||||||
given(dataSource.getAllAuthsByIp(anyString())).willReturn(Collections.<String>emptyList());
|
given(dataSource.getAllAuthsByIp(anyString())).willReturn(Collections.<String>emptyList());
|
||||||
@ -96,6 +97,7 @@ public class AccountsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnSingleAccountMessage() {
|
public void shouldReturnSingleAccountMessage() {
|
||||||
// given
|
// given
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
List<String> arguments = Collections.singletonList("SomeUser");
|
List<String> arguments = Collections.singletonList("SomeUser");
|
||||||
given(dataSource.getAuth("someuser")).willReturn(authWithIp("56.78.90.123"));
|
given(dataSource.getAuth("someuser")).willReturn(authWithIp("56.78.90.123"));
|
||||||
given(dataSource.getAllAuthsByIp("56.78.90.123")).willReturn(Collections.singletonList("SomeUser"));
|
given(dataSource.getAllAuthsByIp("56.78.90.123")).willReturn(Collections.singletonList("SomeUser"));
|
||||||
@ -115,6 +117,7 @@ public class AccountsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnIpUnknown() {
|
public void shouldReturnIpUnknown() {
|
||||||
// given
|
// given
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
List<String> arguments = Collections.singletonList("123.45.67.89");
|
List<String> arguments = Collections.singletonList("123.45.67.89");
|
||||||
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Collections.<String>emptyList());
|
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Collections.<String>emptyList());
|
||||||
|
|
||||||
@ -130,6 +133,7 @@ public class AccountsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnSingleAccountForIpQuery() {
|
public void shouldReturnSingleAccountForIpQuery() {
|
||||||
// given
|
// given
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
List<String> arguments = Collections.singletonList("24.24.48.48");
|
List<String> arguments = Collections.singletonList("24.24.48.48");
|
||||||
given(dataSource.getAllAuthsByIp("24.24.48.48")).willReturn(Collections.singletonList("SomeUser"));
|
given(dataSource.getAllAuthsByIp("24.24.48.48")).willReturn(Collections.singletonList("SomeUser"));
|
||||||
|
|
||||||
@ -145,6 +149,7 @@ public class AccountsCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnAccountListForIpQuery() {
|
public void shouldReturnAccountListForIpQuery() {
|
||||||
// given
|
// given
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
List<String> arguments = Collections.singletonList("98.76.41.122");
|
List<String> arguments = Collections.singletonList("98.76.41.122");
|
||||||
given(dataSource.getAllAuthsByIp("98.76.41.122")).willReturn(Arrays.asList("Tester", "Lester", "Taster"));
|
given(dataSource.getAllAuthsByIp("98.76.41.122")).willReturn(Arrays.asList("Tester", "Lester", "Taster"));
|
||||||
|
|
||||||
|
|||||||
@ -316,6 +316,22 @@ public class AuthMeServiceInitializerTest {
|
|||||||
initializer.performReloadOnServices();
|
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) {
|
private void expectRuntimeExceptionWith(String message) {
|
||||||
expectedException.expect(RuntimeException.class);
|
expectedException.expect(RuntimeException.class);
|
||||||
expectedException.expectMessage(containsString(message));
|
expectedException.expectMessage(containsString(message));
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package fr.xephi.authme.process;
|
|||||||
|
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.output.Messages;
|
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.PermissionNode;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.permission.PlayerPermission;
|
import fr.xephi.authme.permission.PlayerPermission;
|
||||||
@ -43,6 +45,9 @@ public class ProcessServiceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AuthGroupHandler authGroupHandler;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetProperty() {
|
public void shouldGetProperty() {
|
||||||
// given
|
// given
|
||||||
@ -166,4 +171,19 @@ public class ProcessServiceTest {
|
|||||||
verify(permissionsManager).hasPermission(player, permission);
|
verify(permissionsManager).hasPermission(player, permission);
|
||||||
assertThat(result, equalTo(true));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
|
import fr.xephi.authme.TestHelper;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -145,4 +146,9 @@ public class StringUtilsTest {
|
|||||||
// then
|
// then
|
||||||
assertThat(result, equalTo("path" + File.separator + "to" + File.separator + "test-file.txt"));
|
assertThat(result, equalTo("path" + File.separator + "to" + File.separator + "test-file.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHaveHiddenConstructor() {
|
||||||
|
TestHelper.validateHasOnlyPrivateEmptyConstructor(StringUtils.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
import fr.xephi.authme.events.FirstSpawnTeleportEvent;
|
import fr.xephi.authme.events.FirstSpawnTeleportEvent;
|
||||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||||
import fr.xephi.authme.output.Messages;
|
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
@ -48,9 +47,6 @@ public class TeleportationServiceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private NewSetting settings;
|
private NewSetting settings;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Messages messages;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user