Skip to content

Instantly share code, notes, and snippets.

@AnnaBoro
Created February 21, 2016 20:34
Show Gist options
  • Save AnnaBoro/d685606ffdd6b7a87760 to your computer and use it in GitHub Desktop.
Save AnnaBoro/d685606ffdd6b7a87760 to your computer and use it in GitHub Desktop.
test initClass with consructor
package junittests;
import static org.junit.Assert.*;
import lesson7_10.reflection.Bird;
import lesson7_10.reflection.Reflection2;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@RunWith(JUnit4.class)
public class Reflection2Test {
@Test
public void testInitClass() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
Reflection2<Bird> reflection = new Reflection2<Bird>();
List<Object> list = new ArrayList<Object>();
list.add("YYY");
list.add(new Integer(23));
Bird o2 = reflection.initClass(Bird.class, list);
assertEquals(o2.getAge(), 23);
assertEquals(o2.getName(), "YYY");
}
@Test(expected = NoSuchMethodException.class)
public void testInitClass2() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
Reflection2<Bird> reflection = new Reflection2<Bird>();
List<Object> list = new ArrayList<Object>();
list.add("YYY");
list.add(new Integer(23));
list.add("TTT");
Bird o2 = reflection.initClass(Bird.class, list);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment