@@ -381,6 +381,43 @@ public void testSetIslandLevel() {
381381
382382 }
383383
384+ /**
385+ * Test method for
386+ * {@link world.bentobox.level.LevelsManager#getTopTen(org.bukkit.World, int)}.
387+ * Verifies that the top ten is sorted in descending order by level.
388+ */
389+ @ Test
390+ public void testGetTopTenSortOrder () {
391+ lm .createAndCleanRankings (world );
392+ Map <World , TopTenData > ttl = lm .getTopTenLists ();
393+ Map <String , Long > tt = ttl .get (world ).getTopTen ();
394+ // Add islands in non-sorted order, mimicking the reported issue
395+ String island65 = UUID .randomUUID ().toString ();
396+ String island1065 = UUID .randomUUID ().toString ();
397+ String island500 = UUID .randomUUID ().toString ();
398+ String island200 = UUID .randomUUID ().toString ();
399+ // Insert in arbitrary order
400+ tt .put (island65 , 65L );
401+ tt .put (island1065 , 1065L );
402+ tt .put (island500 , 500L );
403+ tt .put (island200 , 200L );
404+ when (im .getIslandById (island65 )).thenReturn (Optional .of (island ));
405+ when (im .getIslandById (island1065 )).thenReturn (Optional .of (island ));
406+ when (im .getIslandById (island500 )).thenReturn (Optional .of (island ));
407+ when (im .getIslandById (island200 )).thenReturn (Optional .of (island ));
408+
409+ Map <String , Long > topTen = lm .getTopTen (world , Level .TEN );
410+ // Verify descending order
411+ long previousLevel = Long .MAX_VALUE ;
412+ for (Long level : topTen .values ()) {
413+ assertTrue ("Top ten not in descending order: " + level + " should be <= " + previousLevel ,
414+ level <= previousLevel );
415+ previousLevel = level ;
416+ }
417+ // Verify highest is first
418+ assertEquals (1065L , topTen .values ().iterator ().next ().longValue ());
419+ }
420+
384421 /**
385422 * Test method for
386423 * {@link world.bentobox.level.LevelsManager#getRank(World, UUID)}
0 commit comments