#1162 New API class: implement ignored review remarks

This commit is contained in:
ljacqu 2017-04-14 18:11:47 +02:00
parent bf38782790
commit cbec5427f2
4 changed files with 25 additions and 26 deletions

View File

@ -118,7 +118,7 @@ public class AuthMe extends JavaPlugin {
/** /**
* Method used to obtain the v2 plugin's api instance * 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 * @return The plugin's api instance
*/ */
@ -264,7 +264,7 @@ public class AuthMe extends JavaPlugin {
commandHandler = injector.getSingleton(CommandHandler.class); commandHandler = injector.getSingleton(CommandHandler.class);
// Trigger construction of API classes; they will keep track of the singleton // 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); injector.getSingleton(NewAPI.class);
} }

View File

@ -21,12 +21,13 @@ import java.util.List;
/** /**
* The v2 API of AuthMe. * The v2 API of AuthMe.
* @deprecated Will be removed in 5.4!
* *
* Recommended method of retrieving the API object: * Recommended method of retrieving the API object:
* <code> * <code>
* NewAPI authmeApi = NewAPI.getInstance(); * NewAPI authmeApi = NewAPI.getInstance();
* </code> * </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 @SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore
@Deprecated @Deprecated

View File

@ -20,17 +20,16 @@ import java.util.ArrayList;
import java.util.List; 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> * <code>
* AuthMeAPI authmeApi = AuthMeAPI.getInstance(); * AuthMeApi authmeApi = AuthMeApi.getInstance();
* </code> * </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 AuthMe plugin;
private final PluginHookService pluginHookService; private final PluginHookService pluginHookService;
private final DataSource dataSource; private final DataSource dataSource;
@ -40,10 +39,10 @@ public class AuthMeAPI {
private final PlayerCache playerCache; private final PlayerCache playerCache;
/* /*
* Constructor for NewAPI. * Constructor for AuthMeApi.
*/ */
@Inject @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) { Management management, ValidationService validationService, PlayerCache playerCache) {
this.plugin = plugin; this.plugin = plugin;
this.pluginHookService = pluginHookService; this.pluginHookService = pluginHookService;
@ -52,19 +51,19 @@ public class AuthMeAPI {
this.management = management; this.management = management;
this.validationService = validationService; this.validationService = validationService;
this.playerCache = playerCache; 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) { if (singleton != null) {
return singleton; 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) // it means AuthMe isn't initialized (yet)
return null; return null;
} }
@ -80,7 +79,7 @@ public class AuthMeAPI {
/** /**
* Gather the version number of the plugin. * 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. * @return Plugin version identifier as a string.
*/ */
@ -104,7 +103,7 @@ public class AuthMeAPI {
* @param player The player to verify * @param player The player to verify
* @return true if the player is an npc * @return true if the player is an npc
*/ */
public boolean isNPC(Player player) { public boolean isNpc(Player player) {
return pluginHookService.isNpc(player); return pluginHookService.isNpc(player);
} }

View File

@ -2,7 +2,6 @@ package fr.xephi.authme.api.v3;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ReflectionTestUtils; 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.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
@ -36,13 +35,13 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
* Test for {@link fr.xephi.authme.api.v3.AuthMeAPI}. * Test for {@link AuthMeApi}.
*/ */
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class AuthMeAPITest { public class AuthMeApiTest {
@InjectMocks @InjectMocks
private AuthMeAPI api; private AuthMeApi api;
@Mock @Mock
private AuthMe authMe; private AuthMe authMe;
@ -61,11 +60,11 @@ public class AuthMeAPITest {
@Test @Test
public void shouldReturnInstanceOrNull() { public void shouldReturnInstanceOrNull() {
AuthMeAPI result = AuthMeAPI.getInstance(); AuthMeApi result = AuthMeApi.getInstance();
assertThat(result, sameInstance(api)); assertThat(result, sameInstance(api));
ReflectionTestUtils.setField(AuthMeAPI.class, null, "singleton", null); ReflectionTestUtils.setField(AuthMeApi.class, null, "singleton", null);
assertThat(AuthMeAPI.getInstance(), nullValue()); assertThat(AuthMeApi.getInstance(), nullValue());
} }
@Test @Test
@ -90,7 +89,7 @@ public class AuthMeAPITest {
given(pluginHookService.isNpc(player)).willReturn(true); given(pluginHookService.isNpc(player)).willReturn(true);
// when // when
boolean result = api.isNPC(player); boolean result = api.isNpc(player);
// then // then
assertThat(result, equalTo(true)); assertThat(result, equalTo(true));