refactor: static imports
This commit is contained in:
parent
33504ff4e9
commit
e7bd920e92
3 changed files with 66 additions and 15 deletions
45
core/src/test/java/net/artelnatif/nicko/test/cache/CacheStorageTest.java
vendored
Normal file
45
core/src/test/java/net/artelnatif/nicko/test/cache/CacheStorageTest.java
vendored
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package net.artelnatif.nicko.test.cache;
|
||||||
|
|
||||||
|
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||||
|
import be.seeseemelk.mockbukkit.ServerMock;
|
||||||
|
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||||
|
import net.artelnatif.nicko.NickoBukkit;
|
||||||
|
import net.artelnatif.nicko.config.Configuration;
|
||||||
|
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
public class CacheStorageTest {
|
||||||
|
private static ServerMock server;
|
||||||
|
private static NickoBukkit plugin;
|
||||||
|
private static PlayerMock player;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void setup() {
|
||||||
|
final Configuration config = new Configuration(
|
||||||
|
"127.0.0.1",
|
||||||
|
"root",
|
||||||
|
"INVALID_PASSWORD",
|
||||||
|
"",
|
||||||
|
false,
|
||||||
|
false);
|
||||||
|
server = MockBukkit.mock();
|
||||||
|
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||||
|
player = server.addPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Cache Player Data")
|
||||||
|
public void cachePlayerData() {
|
||||||
|
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
|
assertTrue(optionalProfile.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public static void shutdown() {
|
||||||
|
MockBukkit.unmock();
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,9 @@ import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class BrokenSQLTest {
|
public class BrokenSQLTest {
|
||||||
private static ServerMock server;
|
private static ServerMock server;
|
||||||
private static NickoBukkit plugin;
|
private static NickoBukkit plugin;
|
||||||
|
@ -33,23 +36,23 @@ public class BrokenSQLTest {
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Fail to create Tables")
|
@DisplayName("Fail to create Tables")
|
||||||
public void createSQLTables() {
|
public void createSQLTables() {
|
||||||
Assertions.assertTrue(plugin.getDataStore().getStorage().isError());
|
assertTrue(plugin.getDataStore().getStorage().isError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Fail to Store Player Via SQL")
|
@DisplayName("Fail to Store Player Via SQL")
|
||||||
public void storePlayer() {
|
public void storePlayer() {
|
||||||
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
Assertions.assertFalse(optionalProfile.isPresent());
|
assertFalse(optionalProfile.isPresent());
|
||||||
ActionResult<Void> result = plugin.getDataStore().saveData(player);
|
ActionResult<Void> result = plugin.getDataStore().saveData(player);
|
||||||
Assertions.assertTrue(result.isError());
|
assertTrue(result.isError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Fail to Retrieve Player Via SQL")
|
@DisplayName("Fail to Retrieve Player Via SQL")
|
||||||
public void retrievePlayer() {
|
public void retrievePlayer() {
|
||||||
final Optional<NickoProfile> storeAction = plugin.getDataStore().getData(player.getUniqueId());
|
final Optional<NickoProfile> storeAction = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
Assertions.assertFalse(storeAction.isPresent());
|
assertFalse(storeAction.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
|
|
@ -12,6 +12,9 @@ import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class SQLStorageTest {
|
public class SQLStorageTest {
|
||||||
private static ServerMock server;
|
private static ServerMock server;
|
||||||
|
@ -36,7 +39,7 @@ public class SQLStorageTest {
|
||||||
@DisplayName("Create SQL Tables")
|
@DisplayName("Create SQL Tables")
|
||||||
@Order(1)
|
@Order(1)
|
||||||
public void createSQLTables() {
|
public void createSQLTables() {
|
||||||
Assertions.assertFalse(plugin.getDataStore().getStorage().isError());
|
assertFalse(plugin.getDataStore().getStorage().isError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -44,7 +47,7 @@ public class SQLStorageTest {
|
||||||
@Order(2)
|
@Order(2)
|
||||||
public void storePlayer() {
|
public void storePlayer() {
|
||||||
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
Assertions.assertTrue(optionalProfile.isPresent());
|
assertTrue(optionalProfile.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -52,7 +55,7 @@ public class SQLStorageTest {
|
||||||
@Order(3)
|
@Order(3)
|
||||||
public void retrievePlayer() {
|
public void retrievePlayer() {
|
||||||
final Optional<NickoProfile> storeAction = plugin.getDataStore().getData(player.getUniqueId());
|
final Optional<NickoProfile> storeAction = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
Assertions.assertTrue(storeAction.isPresent());
|
assertTrue(storeAction.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -60,13 +63,13 @@ public class SQLStorageTest {
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void updatePlayer() {
|
public void updatePlayer() {
|
||||||
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
Assertions.assertTrue(optionalProfile.isPresent());
|
assertTrue(optionalProfile.isPresent());
|
||||||
|
|
||||||
final NickoProfile profile = optionalProfile.get();
|
final NickoProfile profile = optionalProfile.get();
|
||||||
Assertions.assertNull(profile.getName());
|
Assertions.assertNull(profile.getName());
|
||||||
Assertions.assertNull(profile.getSkin());
|
Assertions.assertNull(profile.getSkin());
|
||||||
Assertions.assertEquals(profile.getLocale(), Locale.ENGLISH);
|
Assertions.assertEquals(profile.getLocale(), Locale.ENGLISH);
|
||||||
Assertions.assertTrue(profile.isBungeecordTransfer());
|
assertTrue(profile.isBungeecordTransfer());
|
||||||
|
|
||||||
profile.setName("Notch");
|
profile.setName("Notch");
|
||||||
profile.setSkin("Notch");
|
profile.setSkin("Notch");
|
||||||
|
@ -74,15 +77,15 @@ public class SQLStorageTest {
|
||||||
profile.setBungeecordTransfer(false);
|
profile.setBungeecordTransfer(false);
|
||||||
|
|
||||||
final ActionResult<Void> result = plugin.getDataStore().saveData(player);
|
final ActionResult<Void> result = plugin.getDataStore().saveData(player);
|
||||||
Assertions.assertFalse(result.isError());
|
assertFalse(result.isError());
|
||||||
|
|
||||||
final Optional<NickoProfile> optionalUpdatedProfile = plugin.getDataStore().getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalUpdatedProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
Assertions.assertTrue(optionalUpdatedProfile.isPresent());
|
assertTrue(optionalUpdatedProfile.isPresent());
|
||||||
final NickoProfile updatedProfile = optionalProfile.get();
|
final NickoProfile updatedProfile = optionalProfile.get();
|
||||||
Assertions.assertEquals(updatedProfile.getName(), "Notch");
|
Assertions.assertEquals(updatedProfile.getName(), "Notch");
|
||||||
Assertions.assertEquals(updatedProfile.getSkin(), "Notch");
|
Assertions.assertEquals(updatedProfile.getSkin(), "Notch");
|
||||||
Assertions.assertEquals(updatedProfile.getLocale(), Locale.FRENCH);
|
Assertions.assertEquals(updatedProfile.getLocale(), Locale.FRENCH);
|
||||||
Assertions.assertFalse(updatedProfile.isBungeecordTransfer());
|
assertFalse(updatedProfile.isBungeecordTransfer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -90,7 +93,7 @@ public class SQLStorageTest {
|
||||||
@Order(5)
|
@Order(5)
|
||||||
public void removePlayerDisguise() {
|
public void removePlayerDisguise() {
|
||||||
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
Assertions.assertTrue(optionalProfile.isPresent());
|
assertTrue(optionalProfile.isPresent());
|
||||||
|
|
||||||
final NickoProfile profile = optionalProfile.get();
|
final NickoProfile profile = optionalProfile.get();
|
||||||
|
|
||||||
|
@ -98,10 +101,10 @@ public class SQLStorageTest {
|
||||||
profile.setSkin(null);
|
profile.setSkin(null);
|
||||||
|
|
||||||
final ActionResult<Void> result = plugin.getDataStore().saveData(player);
|
final ActionResult<Void> result = plugin.getDataStore().saveData(player);
|
||||||
Assertions.assertFalse(result.isError());
|
assertFalse(result.isError());
|
||||||
|
|
||||||
final Optional<NickoProfile> optionalUpdatedProfile = plugin.getDataStore().getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalUpdatedProfile = plugin.getDataStore().getData(player.getUniqueId());
|
||||||
Assertions.assertTrue(optionalUpdatedProfile.isPresent());
|
assertTrue(optionalUpdatedProfile.isPresent());
|
||||||
final NickoProfile updatedProfile = optionalProfile.get();
|
final NickoProfile updatedProfile = optionalProfile.get();
|
||||||
Assertions.assertNull(updatedProfile.getName());
|
Assertions.assertNull(updatedProfile.getName());
|
||||||
Assertions.assertNull(updatedProfile.getSkin());
|
Assertions.assertNull(updatedProfile.getSkin());
|
||||||
|
|
Loading…
Reference in a new issue