mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 11:03:43 +01:00 
			
		
		
		
	Fix FlatFile leaderboards not working in certain situations + added leaderboards unit test
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
package com.gmail.nossr50.database;
 | 
			
		||||
 | 
			
		||||
import com.gmail.nossr50.TestUtil;
 | 
			
		||||
import com.gmail.nossr50.database.flatfile.LeaderboardStatus;
 | 
			
		||||
import com.gmail.nossr50.datatypes.database.DatabaseType;
 | 
			
		||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
 | 
			
		||||
import com.gmail.nossr50.datatypes.player.UniqueDataType;
 | 
			
		||||
@@ -24,7 +25,6 @@ import java.util.logging.Logger;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
//TODO: Test update leaderboards
 | 
			
		||||
//This class uses JUnit5/Jupiter
 | 
			
		||||
public class FlatFileDatabaseManagerTest {
 | 
			
		||||
 | 
			
		||||
@@ -65,7 +65,11 @@ public class FlatFileDatabaseManagerTest {
 | 
			
		||||
        assertNull(db);
 | 
			
		||||
        //noinspection UnstableApiUsage
 | 
			
		||||
        tempDir = Files.createTempDir();
 | 
			
		||||
        db = new FlatFileDatabaseManager(new File(tempDir.getPath() + File.separator + TEST_FILE_NAME), logger, PURGE_TIME, 0, true);
 | 
			
		||||
        db = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private @NotNull String getTemporaryUserFilePath() {
 | 
			
		||||
        return tempDir.getPath() + File.separator + TEST_FILE_NAME;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @AfterEach
 | 
			
		||||
@@ -131,6 +135,17 @@ public class FlatFileDatabaseManagerTest {
 | 
			
		||||
            "mrfloris:2420:::0:2452:0:1983:1937:1790:3042:badvalue:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:631e3896-da2a-4077-974b-d047859d76bc:5:1600906906:"
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testDefaultInit() {
 | 
			
		||||
        db = new FlatFileDatabaseManager(getTemporaryUserFilePath(), logger, PURGE_TIME, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testUpdateLeaderboards() {
 | 
			
		||||
        assertNotNull(db);
 | 
			
		||||
        assertEquals(LeaderboardStatus.UPDATED, db.updateLeaderboards());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testSaveUser() {
 | 
			
		||||
        //Make a Profile to save and check to see if it worked
 | 
			
		||||
@@ -141,8 +156,6 @@ public class FlatFileDatabaseManagerTest {
 | 
			
		||||
 | 
			
		||||
        //Save the zero version and see if it looks correct
 | 
			
		||||
        assertNotNull(db);
 | 
			
		||||
        assertFalse(db.getUsersFile().exists());
 | 
			
		||||
        db.checkFileHealthAndStructure();
 | 
			
		||||
        assertTrue(db.getUsersFile().exists()); //Users file should have been created from the above com.gmail.nossr50.database.FlatFileDatabaseManager.checkFileHealthAndStructure
 | 
			
		||||
        assertNotNull(db.getUsersFile());
 | 
			
		||||
 | 
			
		||||
@@ -530,9 +543,7 @@ public class FlatFileDatabaseManagerTest {
 | 
			
		||||
    public void testDataNotFound() {
 | 
			
		||||
        //Save the zero version and see if it looks correct
 | 
			
		||||
        assertNotNull(db);
 | 
			
		||||
        assertFalse(db.getUsersFile().exists());
 | 
			
		||||
        db.checkFileHealthAndStructure();
 | 
			
		||||
        assertTrue(db.getUsersFile().exists()); //Users file should have been created from the above com.gmail.nossr50.database.FlatFileDatabaseManager.checkFileHealthAndStructure
 | 
			
		||||
        assertTrue(db.getUsersFile().exists());
 | 
			
		||||
        assertNotNull(db.getUsersFile());
 | 
			
		||||
 | 
			
		||||
        //Check for the "unloaded" profile
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,8 @@ package com.gmail.nossr50.util.text;
 | 
			
		||||
 | 
			
		||||
import net.kyori.adventure.text.TextComponent;
 | 
			
		||||
import net.kyori.adventure.text.format.NamedTextColor;
 | 
			
		||||
import org.junit.Assert;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.junit.jupiter.api.Assertions;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This Unit Test checks if Adventure was set up correctly and works as expected.
 | 
			
		||||
@@ -26,7 +26,6 @@ public class TextUtilsTest {
 | 
			
		||||
         */
 | 
			
		||||
        TextComponent component = TextUtils.colorizeText(inputText);
 | 
			
		||||
 | 
			
		||||
        Assert.assertEquals("Looks like Adventure is not working correctly.",
 | 
			
		||||
                NamedTextColor.DARK_RED, component.color());
 | 
			
		||||
        Assertions.assertEquals(NamedTextColor.DARK_RED, component.color(), "Looks like Adventure is not working correctly.");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user