package com.capgemini.framework.common;

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

public class ReflectionHelperTest {
    private static final String DUMMY_BEAN_CLASSNAME = "com.capgemini.framework.common.DummyBean";
    private static final String WRONG_CLASSNAME = "com.capgemini.framework.common.WrongBean";

    @Test
    public void testGetClassForName() {
        Class<?> theClass = ReflectionHelper.getClassForName(DUMMY_BEAN_CLASSNAME);
        Assert.assertEquals("Compare classes", DummyBean.class, theClass);

        Class<?> theNullClass = ReflectionHelper.getClassForName(WRONG_CLASSNAME);
        Assert.assertNull("Unknown class", theNullClass);
    }

    @Test
    public void testNewFromClassForName() {
        Object theObj = ReflectionHelper.newFromClassForName(DUMMY_BEAN_CLASSNAME);
        boolean isInstance = theObj instanceof DummyBean;
        Assert.assertTrue("Compare classes", isInstance);

        Object theNullObj = ReflectionHelper.newFromClassForName(WRONG_CLASSNAME);
        Assert.assertNull("Unknown class name for newInstance", theNullObj);
    }
}
