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.*; |
---|
13 | |
---|
14 | @Test |
---|
15 | public class CreatureTest extends TestConfiguration { |
---|
16 | |
---|
17 | FramsClass framsClass; |
---|
18 | ArrayListParam partsParam; |
---|
19 | ReflectionAccess access; |
---|
20 | Creature creature; |
---|
21 | |
---|
22 | @Test |
---|
23 | public void testFramsClass() { |
---|
24 | framsClass = FramsClass.build().forClass(Creature.class); |
---|
25 | |
---|
26 | assertThat(framsClass).describedAs("framsClass").isNotNull(); |
---|
27 | assertThat(framsClass.getParam("name")).describedAs("name").isInstanceOf(StringParam.class); |
---|
28 | assertThat(framsClass.getParam("parts")).describedAs("parts").isInstanceOf(ArrayListParam.class); |
---|
29 | partsParam = framsClass.getParamEntry("parts", ArrayListParam.class); |
---|
30 | assertThat(partsParam).describedAs("partsParam").isNotNull(); |
---|
31 | assertThat(partsParam).isInstanceOf(ArrayListParam.class); |
---|
32 | assertThat(partsParam.getContainedTypeName()).isEqualTo("Part"); |
---|
33 | assertThat(framsClass.getParam("gnum")).isInstanceOf(DecimalParam.class); |
---|
34 | } |
---|
35 | |
---|
36 | @Test(dependsOnMethods = "testFramsClass") |
---|
37 | public void testReflectionAccess() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { |
---|
38 | access = new ReflectionAccess(Creature.class, framsClass); |
---|
39 | Object object = access.createAccessee(); |
---|
40 | assertThat(object).isInstanceOf(Creature.class); |
---|
41 | access.select(object); |
---|
42 | |
---|
43 | creature = (Creature) object; |
---|
44 | access.set("gnum", new Integer(1)); |
---|
45 | // Creature.class.getField("generation").set(creature, 1); |
---|
46 | assertThat(creature.generation).isEqualTo(1); |
---|
47 | |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | } |
---|