2014-01-15 05:42:40 +01:00
package org.bukkit ;
import static org.hamcrest.Matchers.* ;
2019-04-23 06:54:36 +02:00
import static org.junit.Assert.* ;
import com.google.common.collect.HashMultiset ;
2018-07-15 02:00:00 +02:00
import net.minecraft.server.EntityTypes ;
2018-08-26 04:00:00 +02:00
import net.minecraft.server.IRegistry ;
2018-07-15 02:00:00 +02:00
import net.minecraft.server.StatisticWrapper ;
2014-01-15 05:42:40 +01:00
import org.bukkit.craftbukkit.CraftStatistic ;
2019-04-23 06:54:36 +02:00
import org.bukkit.entity.EntityType ;
2014-01-15 05:42:40 +01:00
import org.bukkit.support.AbstractTestingBase ;
import org.junit.Test ;
public class StatisticsAndAchievementsTest extends AbstractTestingBase {
2018-07-15 02:00:00 +02:00
@Test
@SuppressWarnings ( " unchecked " )
public void verifyEntityMapping ( ) throws Throwable {
for ( Statistic statistic : Statistic . values ( ) ) {
if ( statistic . getType ( ) = = Statistic . Type . ENTITY ) {
for ( EntityType entity : EntityType . values ( ) ) {
if ( entity . getName ( ) ! = null ) {
assertNotNull ( statistic + " missing for " + entity , CraftStatistic . getEntityStatistic ( statistic , entity ) ) ;
}
}
}
}
}
2014-01-15 05:42:40 +01:00
@Test
@SuppressWarnings ( " unchecked " )
public void verifyStatisticMapping ( ) throws Throwable {
HashMultiset < Statistic > statistics = HashMultiset . create ( ) ;
2019-04-23 04:00:00 +02:00
for ( StatisticWrapper wrapper : IRegistry . STATS ) {
2018-07-15 02:00:00 +02:00
for ( Object child : wrapper . a ( ) ) {
net . minecraft . server . Statistic < ? > statistic = wrapper . b ( child ) ;
String message = String . format ( " org.bukkit.Statistic is missing: '%s' " , statistic ) ;
Statistic subject = CraftStatistic . getBukkitStatistic ( statistic ) ;
assertThat ( message , subject , is ( not ( nullValue ( ) ) ) ) ;
2018-08-26 04:00:00 +02:00
if ( wrapper . a ( ) = = IRegistry . BLOCK | | wrapper . a ( ) = = IRegistry . ITEM ) {
2019-04-23 04:00:00 +02:00
assertNotNull ( " Material type map missing for " + wrapper . a ( ) . getKey ( child ) , CraftStatistic . getMaterialFromStatistic ( statistic ) ) ;
2018-08-26 04:00:00 +02:00
} else if ( wrapper . a ( ) = = IRegistry . ENTITY_TYPE ) {
2018-07-15 02:00:00 +02:00
assertNotNull ( " Entity type map missing for " + EntityTypes . getName ( ( EntityTypes < ? > ) child ) , CraftStatistic . getEntityTypeFromStatistic ( ( net . minecraft . server . Statistic < EntityTypes < ? > > ) statistic ) ) ;
}
statistics . add ( subject ) ;
}
2014-01-15 05:42:40 +01:00
}
for ( Statistic statistic : Statistic . values ( ) ) {
String message = String . format ( " org.bukkit.Statistic.%s does not have a corresponding minecraft statistic " , statistic . name ( ) ) ;
assertThat ( message , statistics . remove ( statistic , statistics . count ( statistic ) ) , is ( greaterThan ( 0 ) ) ) ;
}
}
}