-
Notifications
You must be signed in to change notification settings - Fork 32
fix: correction des tests unitaires et ajout de nouveau test #1170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iambibi
merged 10 commits into
ServerOpenMC:master
from
gtolontop:fix/tests-unitaires-spawner-extractor
Mar 20, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
38b8f1b
fix: déplacement du SpawnerExtractorListener dans le guard isUnitTest…
gtolontop 74b91e4
chore: logs verbeux pour diagnostiquer les tests unitaires
gtolontop a5e6a04
fix: ignorer TabList dans les tests unitaires
gtolontop 81ed6e9
fix: null check dans MultiBlockManager.save()
gtolontop 47a9669
fix: test MotdUtils flaky avec seulement 2 entrées MOTD
gtolontop fbae409
fix: attendre les tâches async dans le test transferBalance
gtolontop 813b7cf
test: ajout de tests unitaires pour les utilitaires et l'économie
gtolontop 5f5c6ec
fix: waitAsyncTasksFinished sur tous les tests de transactions
gtolontop ffeacbd
fix: déplacer le null check au début de MultiBlockManager.save()
gtolontop 257b2a6
fix: appliquer les retours de review PR #1170
gtolontop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/fr/openmc/core/features/economy/EconomyFormattingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package fr.openmc.core.features.economy; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| class EconomyFormattingTest { | ||
|
|
||
| @BeforeAll | ||
| static void setUpLocale() { | ||
| Locale.setDefault(Locale.US); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Format zero balance") | ||
| void testFormat_Zero() { | ||
iambibi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Assertions.assertEquals("0", EconomyManager.getFormattedSimplifiedNumber(0)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Format small number without suffix") | ||
| void testFormat_SmallNumber() { | ||
| Assertions.assertEquals("500", EconomyManager.getFormattedSimplifiedNumber(500)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Format thousands with k suffix") | ||
| void testFormat_Thousands() { | ||
| String result = EconomyManager.getFormattedSimplifiedNumber(1500); | ||
| Assertions.assertEquals("1.5k", result); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Format exact thousand") | ||
| void testFormat_ExactThousand() { | ||
| Assertions.assertEquals("1k", EconomyManager.getFormattedSimplifiedNumber(1000)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Format millions with M suffix") | ||
| void testFormat_Millions() { | ||
| Assertions.assertEquals("3M", EconomyManager.getFormattedSimplifiedNumber(3_000_000)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Format billions with B suffix") | ||
| void testFormat_Billions() { | ||
| Assertions.assertEquals("1B", EconomyManager.getFormattedSimplifiedNumber(1_000_000_000)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Format with decimal truncation") | ||
| void testFormat_Decimal() { | ||
| String result = EconomyManager.getFormattedSimplifiedNumber(2_500_000); | ||
| Assertions.assertEquals("2.5M", result); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Format number under 1000") | ||
| void testFormat_Under1000() { | ||
| Assertions.assertEquals("999", EconomyManager.getFormattedSimplifiedNumber(999)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package fr.openmc.core.utils; | ||
|
|
||
| import net.kyori.adventure.text.format.NamedTextColor; | ||
| import org.bukkit.Material; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ColorUtilsTest { | ||
|
|
||
| @Test | ||
| @DisplayName("getNamedTextColor valid color") | ||
| void testGetNamedTextColor_Valid() { | ||
| Assertions.assertEquals(NamedTextColor.RED, ColorUtils.getNamedTextColor("red")); | ||
| Assertions.assertEquals(NamedTextColor.BLUE, ColorUtils.getNamedTextColor("blue")); | ||
| Assertions.assertEquals(NamedTextColor.GREEN, ColorUtils.getNamedTextColor("green")); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("getNamedTextColor null returns WHITE") | ||
| void testGetNamedTextColor_Null() { | ||
| Assertions.assertEquals(NamedTextColor.WHITE, ColorUtils.getNamedTextColor(null)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("getNamedTextColor invalid returns WHITE") | ||
| void testGetNamedTextColor_Invalid() { | ||
| Assertions.assertEquals(NamedTextColor.WHITE, ColorUtils.getNamedTextColor("not_a_color")); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("getColorCode returns correct codes") | ||
| void testGetColorCode() { | ||
| Assertions.assertEquals("§c", ColorUtils.getColorCode(NamedTextColor.RED)); | ||
| Assertions.assertEquals("§a", ColorUtils.getColorCode(NamedTextColor.GREEN)); | ||
| Assertions.assertEquals("§9", ColorUtils.getColorCode(NamedTextColor.BLUE)); | ||
| Assertions.assertEquals("§f", ColorUtils.getColorCode(NamedTextColor.WHITE)); | ||
| Assertions.assertEquals("§0", ColorUtils.getColorCode(NamedTextColor.BLACK)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("getNameFromColor returns French names") | ||
| void testGetNameFromColor() { | ||
| Assertions.assertEquals("§cRouge", ColorUtils.getNameFromColor(NamedTextColor.RED)); | ||
| Assertions.assertEquals("§fBlanc", ColorUtils.getNameFromColor(NamedTextColor.WHITE)); | ||
| Assertions.assertEquals("§6Orange", ColorUtils.getNameFromColor(NamedTextColor.GOLD)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("getMaterialFromColor returns correct wool") | ||
| void testGetMaterialFromColor() { | ||
| Assertions.assertEquals(Material.RED_WOOL, ColorUtils.getMaterialFromColor(NamedTextColor.RED)); | ||
| Assertions.assertEquals(Material.WHITE_WOOL, ColorUtils.getMaterialFromColor(NamedTextColor.WHITE)); | ||
| Assertions.assertEquals(Material.BLACK_WOOL, ColorUtils.getMaterialFromColor(NamedTextColor.BLACK)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("getReadableColor maps correctly") | ||
| void testGetReadableColor() { | ||
| Assertions.assertEquals(NamedTextColor.DARK_GRAY, ColorUtils.getReadableColor(NamedTextColor.BLACK)); | ||
| Assertions.assertEquals(NamedTextColor.GRAY, ColorUtils.getReadableColor(NamedTextColor.WHITE)); | ||
| Assertions.assertEquals(NamedTextColor.GOLD, ColorUtils.getReadableColor(NamedTextColor.YELLOW)); | ||
| Assertions.assertEquals(NamedTextColor.RED, ColorUtils.getReadableColor(NamedTextColor.RED)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("getRGBFromNamedTextColor returns correct RGB") | ||
| void testGetRGBFromNamedTextColor() { | ||
| int[] red = ColorUtils.getRGBFromNamedTextColor(NamedTextColor.RED); | ||
| Assertions.assertArrayEquals(new int[]{255, 85, 85}, red); | ||
|
|
||
| int[] black = ColorUtils.getRGBFromNamedTextColor(NamedTextColor.BLACK); | ||
| Assertions.assertArrayEquals(new int[]{0, 0, 0}, black); | ||
|
|
||
| int[] white = ColorUtils.getRGBFromNamedTextColor(NamedTextColor.WHITE); | ||
| Assertions.assertArrayEquals(new int[]{255, 255, 255}, white); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package fr.openmc.core.utils; | ||
|
|
||
| import org.bukkit.Material; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class EnumUtilsTest { | ||
|
|
||
| @Test | ||
| @DisplayName("Match valid enum value") | ||
| void testMatch_Valid() { | ||
| Assertions.assertEquals(Material.STONE, EnumUtils.match("stone", Material.class)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Match valid enum value case insensitive") | ||
| void testMatch_CaseInsensitive() { | ||
| Assertions.assertEquals(Material.DIAMOND, EnumUtils.match("diamond", Material.class)); | ||
| Assertions.assertEquals(Material.DIAMOND, EnumUtils.match("DIAMOND", Material.class)); | ||
| Assertions.assertEquals(Material.DIAMOND, EnumUtils.match("Diamond", Material.class)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Match invalid key returns null") | ||
| void testMatch_InvalidReturnsNull() { | ||
| Assertions.assertNull(EnumUtils.match("not_a_material", Material.class)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Match invalid key returns default value") | ||
| void testMatch_InvalidReturnsDefault() { | ||
| Assertions.assertEquals(Material.AIR, EnumUtils.match("not_a_material", Material.class, Material.AIR)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Match null key returns default") | ||
| void testMatch_NullKey() { | ||
| Assertions.assertEquals(Material.STONE, EnumUtils.match(null, Material.class, Material.STONE)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Match null key returns null without default") | ||
| void testMatch_NullKeyNoDefault() { | ||
| Assertions.assertNull(EnumUtils.match(null, Material.class)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.