Added Tests For the data objects
Along with fixing some bugs in them Woo!
This commit is contained in:
parent
ecaa9f2569
commit
6db97df7b8
|
@ -0,0 +1 @@
|
|||
{"players":{}}
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
public class PlayerData {
|
||||
|
||||
//TODO Write Tests
|
||||
public List<PlayerWorld> playerWorlds;
|
||||
private List<PlayerWorld> playerWorlds;
|
||||
|
||||
|
||||
public PlayerData() {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package de.butzlabben.world.data.objects;
|
||||
|
||||
public class PlayerWorld {
|
||||
public int worldNumber;
|
||||
public long lastLoaded;
|
||||
private int worldNumber;
|
||||
private long lastLoaded;
|
||||
|
||||
public PlayerWorld(String OWNER, String OWNERname, int worldNumber) {
|
||||
public PlayerWorld(int worldNumber) {
|
||||
this.worldNumber = worldNumber;
|
||||
this.lastLoaded = 0;
|
||||
this.lastLoaded = -1;
|
||||
}
|
||||
|
||||
public int getWorldNumber() {
|
||||
return worldNumber;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ public class WorldSystemData {
|
|||
return players.size();
|
||||
}
|
||||
|
||||
public PlayerData getPlayer(String uuid) {
|
||||
return players.get(uuid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package de.butzlabben.world.data;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
@ -17,11 +20,8 @@ public class TestWorldDatabase {
|
|||
* but then allows us to run the tests Fresh.
|
||||
*/
|
||||
@BeforeAll
|
||||
static void CleanLastTest() {
|
||||
File workingDir = new File("src\\TestFiles\\workingDir\\");
|
||||
for (File file : workingDir.listFiles()) {
|
||||
file.delete();
|
||||
}
|
||||
static void CleanLastTest() throws IOException {
|
||||
FileUtils.cleanDirectory(new File("TestFiles/workingDir/"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ public class TestWorldDatabase {
|
|||
*/
|
||||
@Test
|
||||
public void testDatabaseInitalizationFromNoFile() {
|
||||
final String path = "src\\TestFiles\\workingDir\\dataBaseInitTestFromNoFile.json";
|
||||
final String path = "TestFiles/workingDir/dataBaseInitTestFromNoFile.json";
|
||||
|
||||
WorldDatabase wb = new WorldDatabase(path);
|
||||
assertEquals(0, wb.getPlayerCount());
|
||||
|
@ -41,7 +41,7 @@ public class TestWorldDatabase {
|
|||
*/
|
||||
@Test
|
||||
public void testDatabaseInitalizationCreateValidFile() throws FileNotFoundException {
|
||||
final String path = "src\\TestFiles\\workingDir\\dataBaseInitTestCreateValidFile.json";
|
||||
final String path = "TestFiles/workingDir/dataBaseInitTestCreateValidFile.json";
|
||||
|
||||
WorldDatabase wb = new WorldDatabase(path);
|
||||
wb.addPlayer("BlankUUID");
|
||||
|
@ -57,7 +57,7 @@ public class TestWorldDatabase {
|
|||
*/
|
||||
@Test
|
||||
public void testDatabaseInitalizationWithExistingEmptyFile() {
|
||||
final String path = "src\\TestFiles\\ExistingEmptyFileInit.json";
|
||||
final String path = "TestFiles/workingDir/ExistingEmptyFileInit.json";
|
||||
|
||||
WorldDatabase wb = new WorldDatabase(path);
|
||||
assertEquals(0, wb.getPlayerCount());
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package de.butzlabben.world.data.objects;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestPlayerData {
|
||||
|
||||
@Test
|
||||
public void testPlayerDataInit() {
|
||||
PlayerData pd = new PlayerData();
|
||||
|
||||
assertEquals(0, pd.getWorldCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddWorld() {
|
||||
PlayerData pd = new PlayerData();
|
||||
|
||||
pd.addWorld(new PlayerWorld(pd.getWorldCount()));
|
||||
assertEquals(1, pd.getWorldCount());
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
pd.addWorld(new PlayerWorld(pd.getWorldCount()));
|
||||
}
|
||||
assertEquals(6, pd.getWorldCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWorldAtIndex() {
|
||||
PlayerData pd = new PlayerData();
|
||||
|
||||
pd.addWorld(new PlayerWorld(pd.getWorldCount()));
|
||||
|
||||
assertEquals(1, pd.getWorldCount());
|
||||
assertEquals(0, pd.getWorldAt(0).getWorldNumber());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package de.butzlabben.world.data.objects;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestPlayerWorld {
|
||||
|
||||
@Test
|
||||
public void testPlayerWorldInit() {
|
||||
PlayerWorld pw = new PlayerWorld(0);
|
||||
assertEquals(0,pw.getWorldNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerWorldInit2() {
|
||||
PlayerWorld pw = new PlayerWorld(6);
|
||||
assertEquals(6,pw.getWorldNumber());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package de.butzlabben.world.data.objects;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestWorldSystemData {
|
||||
|
||||
@Test
|
||||
public void testWorldSystemDataInit() {
|
||||
WorldSystemData wsd = new WorldSystemData();
|
||||
|
||||
assertEquals(0, wsd.getPlayers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddPlayer() {
|
||||
WorldSystemData wsd = new WorldSystemData();
|
||||
assertEquals(0, wsd.getPlayers());
|
||||
|
||||
wsd.addplayer("Blank_UUID");
|
||||
assertEquals(1, wsd.getPlayers());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddMultiplePlayers() {
|
||||
WorldSystemData wsd = new WorldSystemData();
|
||||
assertEquals(0, wsd.getPlayers());
|
||||
|
||||
wsd.addplayer("Blank_UUID");
|
||||
assertEquals(1, wsd.getPlayers());
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
wsd.addplayer("Blank_UUID" + i);
|
||||
}
|
||||
assertEquals(6, wsd.getPlayers());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddDulpicatePlayer() {
|
||||
WorldSystemData wsd = new WorldSystemData();
|
||||
assertEquals(0, wsd.getPlayers());
|
||||
|
||||
wsd.addplayer("Blank_UUID");
|
||||
assertEquals(1, wsd.getPlayers());
|
||||
|
||||
wsd.addplayer("Blank_UUID");
|
||||
assertEquals(1, wsd.getPlayers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddWorldToPlayer() {
|
||||
WorldSystemData wsd = new WorldSystemData();
|
||||
assertEquals(0, wsd.getPlayers());
|
||||
|
||||
wsd.addplayer("Blank_UUID");
|
||||
wsd.addWorldToPlayer("Blank_UUID", new PlayerWorld(wsd.getPlayer("Blank_UUID").getWorldCount()));
|
||||
|
||||
assertEquals(1, wsd.getPlayer("Blank_UUID").getWorldCount());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddMultipleWorldsToPlayer() {
|
||||
WorldSystemData wsd = new WorldSystemData();
|
||||
wsd.addplayer("Blank_UUID");
|
||||
assertEquals(1, wsd.getPlayers());
|
||||
|
||||
wsd.addWorldToPlayer("Blank_UUID", new PlayerWorld(wsd.getPlayer("Blank_UUID").getWorldCount()));
|
||||
assertEquals(1, wsd.getPlayer("Blank_UUID").getWorldCount());
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
wsd.addWorldToPlayer("Blank_UUID", new PlayerWorld(wsd.getPlayer("Blank_UUID").getWorldCount()));
|
||||
}
|
||||
assertEquals(6, wsd.getPlayer("Blank_UUID").getWorldCount());
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{"players":{"BlankUUID":{"playerWorlds":[]}}}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,7 @@
|
|||
name: 'WorldSystem'
|
||||
version: '2.4.20'
|
||||
main: de.bulzlabben.world.WorldSystem
|
||||
|
||||
description: The one world per player solution you have always dreamed of.
|
||||
|
||||
api-version: '1.17'
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue