Last active
February 21, 2016 21:08
-
-
Save AnnaBoro/81eaf865807ed89af704 to your computer and use it in GitHub Desktop.
setPrivatesTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package junittests; | |
import static org.junit.Assert.*; | |
import lesson7_10.reflection.Bird; | |
import lesson7_10.reflection.Reflection2; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.JUnit4; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.HashMap; | |
import java.util.Map; | |
@RunWith(JUnit4.class) | |
public class Reflection2Test { | |
Reflection2<Bird> reflection; | |
Bird bird; | |
Map<String, Object> map; | |
@Before | |
public void init(){ | |
reflection = new Reflection2<Bird>(); | |
map = new HashMap<String, Object>(); | |
bird = new Bird(); | |
} | |
@Test | |
public void testSetPrivates() throws NoSuchFieldException, IllegalAccessException { | |
assertEquals(bird.getName(), null); | |
assertEquals(bird.getAge(), 0); | |
map.put("name", "u2"); | |
map.put("age", 120); | |
reflection.setPrivates(bird, map); | |
assertEquals(bird.getName(), "u2"); | |
assertEquals(bird.getAge(), 120); | |
} | |
@Test(expected = NoSuchFieldException.class) | |
public void testSetPrivates2() throws NoSuchFieldException, IllegalAccessException { | |
assertEquals(bird.getName(), null); | |
assertEquals(bird.getAge(), 0); | |
map.put("name2", "u2"); | |
map.put("age", 120); | |
reflection.setPrivates(bird, map); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment