[86] | 1 | package com.framsticks.model; |
---|
| 2 | |
---|
| 3 | import org.testng.annotations.Test; |
---|
| 4 | |
---|
| 5 | import com.framsticks.params.FramsClass; |
---|
| 6 | import com.framsticks.params.ReflectionAccess; |
---|
| 7 | import com.framsticks.params.types.ArrayListParam; |
---|
| 8 | import com.framsticks.params.types.DecimalParam; |
---|
| 9 | import com.framsticks.params.types.StringParam; |
---|
| 10 | import com.framsticks.test.TestConfiguration; |
---|
| 11 | |
---|
| 12 | import static org.fest.assertions.Assertions.*; |
---|
[105] | 13 | import static com.framsticks.params.ParamsUtil.getParam; |
---|
[86] | 14 | |
---|
| 15 | @Test |
---|
| 16 | public class CreatureTest extends TestConfiguration { |
---|
| 17 | |
---|
| 18 | FramsClass framsClass; |
---|
| 19 | ArrayListParam partsParam; |
---|
| 20 | ReflectionAccess access; |
---|
| 21 | Creature creature; |
---|
| 22 | |
---|
| 23 | @Test |
---|
| 24 | public void testFramsClass() { |
---|
[87] | 25 | framsClass = FramsClass.build().forClass(Creature.class); |
---|
[86] | 26 | |
---|
| 27 | assertThat(framsClass).describedAs("framsClass").isNotNull(); |
---|
| 28 | assertThat(framsClass.getParam("name")).describedAs("name").isInstanceOf(StringParam.class); |
---|
| 29 | assertThat(framsClass.getParam("parts")).describedAs("parts").isInstanceOf(ArrayListParam.class); |
---|
[105] | 30 | partsParam = getParam(framsClass, "parts", ArrayListParam.class); |
---|
[86] | 31 | assertThat(partsParam).describedAs("partsParam").isNotNull(); |
---|
| 32 | assertThat(partsParam).isInstanceOf(ArrayListParam.class); |
---|
| 33 | assertThat(partsParam.getContainedTypeName()).isEqualTo("Part"); |
---|
| 34 | assertThat(framsClass.getParam("gnum")).isInstanceOf(DecimalParam.class); |
---|
| 35 | } |
---|
| 36 | |
---|
[87] | 37 | @Test(dependsOnMethods = "testFramsClass") |
---|
[86] | 38 | public void testReflectionAccess() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { |
---|
| 39 | access = new ReflectionAccess(Creature.class, framsClass); |
---|
| 40 | Object object = access.createAccessee(); |
---|
| 41 | assertThat(object).isInstanceOf(Creature.class); |
---|
| 42 | access.select(object); |
---|
| 43 | |
---|
| 44 | creature = (Creature) object; |
---|
| 45 | access.set("gnum", new Integer(1)); |
---|
| 46 | // Creature.class.getField("generation").set(creature, 1); |
---|
| 47 | assertThat(creature.generation).isEqualTo(1); |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | } |
---|