package net.minecraftforge.test;

import java.lang.reflect.Constructor;

import net.minecraftforge.client.EnumHelperClient;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.util.EnumHelper;

import org.junit.Assert;
import org.junit.Test;

import net.minecraftforge.fml.relauncher.ReflectionHelper;

public class EnumHelperTest
{
    private boolean failed = false;

    @Test
    public void test()
    {
        System.out.println("Testing EnumHelper:");
        Object[][] types = (Object[][])ReflectionHelper.getPrivateValue(EnumHelper.class, null, "commonTypes");
        for (Object[] o : types)
            testType(o);

        System.out.println("Testing EnumHelperClient:");
        types = (Object[][])ReflectionHelper.getPrivateValue(EnumHelperClient.class, null, "clentTypes");
        for (Object[] o : types)
            testType(o);

        if (failed)
            throw new RuntimeException("Enum Helper test failed!");
        Assert.assertEquals(BiomeDictionary.Type.BEACH, BiomeDictionary.Type.getType("BEACH"));
        Assert.assertEquals(BiomeDictionary.Type.getType("NEWTYPE"), BiomeDictionary.Type.getType("NEWTYPE"));
    }
    private void testType(Object[] info)
    {
        Class<?> cls = (Class<?>)info[0];
        Class<?>[] parameterTypes = new Class[info.length + 2 - 1];
        parameterTypes[0] = String.class;
        parameterTypes[1] = int.class;
        System.arraycopy(info, 1, parameterTypes, 2, info.length - 1);
        try
        {
            cls.getDeclaredConstructor(parameterTypes);
            System.out.println("  " + cls.getName() + ": Success");
        }
        catch (Exception e)
        {
            System.out.println("  " + cls.getName() + ": Failed");
            for (Constructor<?> c : cls.getDeclaredConstructors())
            {
                System.out.println("      " + c.toString());
            }
            failed = true;
        }
    }
}

@@ -64,16 +64,49 @@
 tructor;
+%0Aimport java.lang.reflect.Method;
 %0A%0Aimport
@@ -457,16 +457,2614 @@
 oid test
+EnumHelperMethodsMatchEnumConstructors()%0A    %7B%0A        //Quick note to point out that Enum constructors start with (string name, int ordinal).%0A        //  EnumHelper methods by convention start with (string name), and the ordinal is calculated.%0A        for (Method method : EnumHelper.class.getDeclaredMethods())%0A        %7B%0A            String name = method.getName();%0A            if (!name.equals(%22addEnum%22) && name.startsWith(%22add%22))%0A            %7B%0A                System.out.println(%22  %22 + method);%0A%0A                Class%3C?%3E returnType = method.getReturnType();%0A                Constructor%3C?%3E%5B%5D declaredConstructors = returnType.getDeclaredConstructors();%0A                Class%3C?%3E%5B%5D actualParameters = method.getParameterTypes();%0A%0A                Assert.assertTrue(actualParameters.length %3E= 1);%0A                Assert.assertEquals(%22First parameter of add method should be String (name)%22,%0A                        String.class,%0A                        actualParameters%5B0%5D);%0A                Assert.assertEquals(String.class, actualParameters%5B0%5D);%0A%0A                for (Constructor%3C?%3E declaredConstructor : declaredConstructors)%0A                %7B%0A                    System.out.println(%22    %22 + declaredConstructor.toString());%0A%0A                    Class%3C?%3E%5B%5D expectedParameters = declaredConstructor.getParameterTypes();%0A%0A                    Assert.assertTrue(expectedParameters.length %3E= 2);%0A                    Assert.assertEquals(%22First parameter of enum constructor should be String (name)%22,%0A                            String.class,%0A                            expectedParameters%5B0%5D);%0A                    Assert.assertEquals(%22Second parameter of enum should be int (ordinal)%22,%0A                            int.class,%0A                            expectedParameters%5B1%5D);%0A%0A                    for (int i = 1, j = 2; i %3C actualParameters.length && j %3C expectedParameters.length; i++, j++)%0A                    %7B%0A                        Assert.assertEquals(%0A                                %22method Parameter %22 + i + %22 (%22 + actualParameters%5Bi%5D.getName() + %22) %22 +%0A                                        %22should match constructor parameter%22 + j + %22 (%22 + expectedParameters%5Bj%5D + %22)%22,%0A                                expectedParameters%5Bj%5D,%0A                                actualParameters%5Bi%5D);%0A                    %7D%0A%0A                    Assert.assertEquals(%22Length of parameters incorrect%22,%0A                            (expectedParameters.length - 2),%0A                            (actualParameters.length - 1));%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testEnumHelperTypes
 ()%0A    %7B
@@ -3437,16 +3437,17 @@
 ull, %22cl
+i
 entTypes
@@ -3804,22 +3804,23 @@
 YPE%22));%0A
-
     %7D%0A
+%0A
     priv

Add Unit Test to detect mismatches between EnumHelper and Enum ctor