/**
 * Copyright 2010 55 Minutes (http://www.55minutes.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fiftyfive.util;

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

public class ReflectUtilsTest
{
    @Test
    public void testInvokeZeroArgMethod()
    {
        Bean bean = new Bean();
        
        Assert.assertNull(ReflectUtils.invokeZeroArgMethod(bean, "voidMethod"));
        Assert.assertEquals(
            "public",
            ReflectUtils.invokeZeroArgMethod(bean, "publicMethod")
        );
        Assert.assertEquals(
            "protected",
            ReflectUtils.invokeZeroArgMethod(bean, "protectedMethod")
        );
        Assert.assertEquals(
            "private",
            ReflectUtils.invokeZeroArgMethod(bean, "privateMethod")
        );
        Assert.assertEquals(
            "default",
            ReflectUtils.invokeZeroArgMethod(bean, "defaultMethod")
        );
    }

    @Test(expected=IllegalArgumentException.class)
    public void testInvokeZeroArgMethod_arg()
    {
        ReflectUtils.invokeZeroArgMethod(new Bean(), "methodWithArg");
    }
    
    @Test(expected=TestException.class)
    public void testInvokeZeroArgMethod_exception()
    {
        ReflectUtils.invokeZeroArgMethod(new Bean(), "exceptionalMethod");
    }

    private static class Bean
    {
        public void voidMethod()
        {
        }
    
        public String publicMethod()
        {
            return "public";
        }
    
        protected String protectedMethod()
        {
            return "protected";
        }
    
        private String privateMethod()
        {
            return "private";
        }
    
        String defaultMethod()
        {
            return "default";
        }
    
        public String methodWithArg(String arg)
        {
            return "arg";
        }
    
        public void exceptionalMethod()
        {
            throw new TestException();
        }
    }
    
    private static class TestException extends RuntimeException
    {
    }
}

@@ -1807,39 +1807,1282 @@
     
-private static class Bean%0A    %7B
+@Test(expected=IllegalArgumentException.class)%0A    public void testReadField_dne()%0A    %7B%0A        ReflectUtils.readField(new Bean(), %22doesnotexist%22);%0A    %7D%0A%0A    @Test%0A    public void testReadField_private()%0A    %7B%0A        Assert.assertEquals(%0A            %22private%22,%0A            ReflectUtils.readField(new Bean(), %22_field1%22)%0A        );%0A    %7D%0A%0A    @Test%0A    public void testReadField_default()%0A    %7B%0A        Assert.assertEquals(%0A            %22default%22,%0A            ReflectUtils.readField(new Bean(), %22_field2%22)%0A        );%0A    %7D%0A%0A    @Test%0A    public void testReadField_protected()%0A    %7B%0A        Assert.assertEquals(%0A            %22protected%22,%0A            ReflectUtils.readField(new Bean(), %22_field3%22)%0A        );%0A    %7D%0A%0A    @Test%0A    public void testReadField_public()%0A    %7B%0A        Assert.assertEquals(%0A            %22public%22,%0A            ReflectUtils.readField(new Bean(), %22_field4%22)%0A        );%0A    %7D%0A%0A    @Test%0A    public void testReadField_null()%0A    %7B%0A        Assert.assertNull(ReflectUtils.readField(new Bean(), %22_field5%22));%0A    %7D%0A%0A    private static class Bean%0A    %7B%0A        private String _field1 = %22private%22;%0A        String _field2 = %22default%22;%0A        protected String _field3 = %22protected%22;%0A        public String _field4 = %22public%22;%0A        private String _field5;%0A        
 %0A   

Add unit test coverage for field reflection.