mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-26 20:26:01 +01:00
#1162 New API class: implement ignored review remarks
This commit is contained in:
parent
bf38782790
commit
cbec5427f2
@ -118,7 +118,7 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Method used to obtain the v2 plugin's api instance
|
||||
* @deprecated Will be removed in 5.4!
|
||||
* @deprecated Will be removed in 5.4, use {@link fr.xephi.authme.api.v3.AuthMeApi} instead
|
||||
*
|
||||
* @return The plugin's api instance
|
||||
*/
|
||||
@ -264,7 +264,7 @@ public class AuthMe extends JavaPlugin {
|
||||
commandHandler = injector.getSingleton(CommandHandler.class);
|
||||
|
||||
// Trigger construction of API classes; they will keep track of the singleton
|
||||
injector.getSingleton(fr.xephi.authme.api.v3.AuthMeAPI.class);
|
||||
injector.getSingleton(fr.xephi.authme.api.v3.AuthMeApi.class);
|
||||
injector.getSingleton(NewAPI.class);
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,13 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* The v2 API of AuthMe.
|
||||
* @deprecated Will be removed in 5.4!
|
||||
*
|
||||
* Recommended method of retrieving the API object:
|
||||
* <code>
|
||||
* NewAPI authmeApi = NewAPI.getInstance();
|
||||
* </code>
|
||||
*
|
||||
* @deprecated Will be removed in 5.4! Use {@link fr.xephi.authme.api.v3.AuthMeApi} instead.
|
||||
*/
|
||||
@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore
|
||||
@Deprecated
|
||||
|
@ -20,17 +20,16 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The current AuthMeAPI of AuthMe.
|
||||
* The current AuthMeApi of AuthMe.
|
||||
*
|
||||
* Recommended method of retrieving the AuthMeAPI object:
|
||||
* Recommended method of retrieving the AuthMeApi object:
|
||||
* <code>
|
||||
* AuthMeAPI authmeApi = AuthMeAPI.getInstance();
|
||||
* AuthMeApi authmeApi = AuthMeApi.getInstance();
|
||||
* </code>
|
||||
*/
|
||||
@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore
|
||||
public class AuthMeAPI {
|
||||
public class AuthMeApi {
|
||||
|
||||
private static AuthMeAPI singleton;
|
||||
private static AuthMeApi singleton;
|
||||
private final AuthMe plugin;
|
||||
private final PluginHookService pluginHookService;
|
||||
private final DataSource dataSource;
|
||||
@ -40,10 +39,10 @@ public class AuthMeAPI {
|
||||
private final PlayerCache playerCache;
|
||||
|
||||
/*
|
||||
* Constructor for NewAPI.
|
||||
* Constructor for AuthMeApi.
|
||||
*/
|
||||
@Inject
|
||||
AuthMeAPI(AuthMe plugin, PluginHookService pluginHookService, DataSource dataSource, PasswordSecurity passwordSecurity,
|
||||
AuthMeApi(AuthMe plugin, PluginHookService pluginHookService, DataSource dataSource, PasswordSecurity passwordSecurity,
|
||||
Management management, ValidationService validationService, PlayerCache playerCache) {
|
||||
this.plugin = plugin;
|
||||
this.pluginHookService = pluginHookService;
|
||||
@ -52,19 +51,19 @@ public class AuthMeAPI {
|
||||
this.management = management;
|
||||
this.validationService = validationService;
|
||||
this.playerCache = playerCache;
|
||||
AuthMeAPI.singleton = this;
|
||||
AuthMeApi.singleton = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the AuthMeAPI object for AuthMe.
|
||||
* Get the AuthMeApi object for AuthMe.
|
||||
*
|
||||
* @return The AuthMeAPI object, or null if the AuthMe plugin is not enabled or not fully initialized yet
|
||||
* @return The AuthMeApi object, or null if the AuthMe plugin is not enabled or not fully initialized yet
|
||||
*/
|
||||
public static AuthMeAPI getInstance() {
|
||||
public static AuthMeApi getInstance() {
|
||||
if (singleton != null) {
|
||||
return singleton;
|
||||
}
|
||||
// NewAPI is initialized in AuthMe#onEnable -> if singleton is null,
|
||||
// AuthMeApi is initialized in AuthMe#onEnable -> if singleton is null,
|
||||
// it means AuthMe isn't initialized (yet)
|
||||
return null;
|
||||
}
|
||||
@ -80,7 +79,7 @@ public class AuthMeAPI {
|
||||
|
||||
/**
|
||||
* Gather the version number of the plugin.
|
||||
* This can be used to determine whether certain AuthMeAPI features are available or not.
|
||||
* This can be used to determine whether certain AuthMeApi features are available or not.
|
||||
*
|
||||
* @return Plugin version identifier as a string.
|
||||
*/
|
||||
@ -104,7 +103,7 @@ public class AuthMeAPI {
|
||||
* @param player The player to verify
|
||||
* @return true if the player is an npc
|
||||
*/
|
||||
public boolean isNPC(Player player) {
|
||||
public boolean isNpc(Player player) {
|
||||
return pluginHookService.isNpc(player);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package fr.xephi.authme.api.v3;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.api.v3.AuthMeAPI;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
@ -36,13 +35,13 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test for {@link fr.xephi.authme.api.v3.AuthMeAPI}.
|
||||
* Test for {@link AuthMeApi}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AuthMeAPITest {
|
||||
public class AuthMeApiTest {
|
||||
|
||||
@InjectMocks
|
||||
private AuthMeAPI api;
|
||||
private AuthMeApi api;
|
||||
|
||||
@Mock
|
||||
private AuthMe authMe;
|
||||
@ -61,11 +60,11 @@ public class AuthMeAPITest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnInstanceOrNull() {
|
||||
AuthMeAPI result = AuthMeAPI.getInstance();
|
||||
AuthMeApi result = AuthMeApi.getInstance();
|
||||
assertThat(result, sameInstance(api));
|
||||
|
||||
ReflectionTestUtils.setField(AuthMeAPI.class, null, "singleton", null);
|
||||
assertThat(AuthMeAPI.getInstance(), nullValue());
|
||||
ReflectionTestUtils.setField(AuthMeApi.class, null, "singleton", null);
|
||||
assertThat(AuthMeApi.getInstance(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -90,7 +89,7 @@ public class AuthMeAPITest {
|
||||
given(pluginHookService.isNpc(player)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = api.isNPC(player);
|
||||
boolean result = api.isNpc(player);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
Loading…
Reference in New Issue
Block a user