source: java/main/src/test/java/com/framsticks/model/CreatureTest.java @ 86

Last change on this file since 86 was 86, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • use java annotations to mark classes and fields to be used when:
    • using java classes with ReflectionAccess? to represent remote objects with FramsClass? description found by "info ..." requests
    • to build up FramsClass? representation of objects not present at remote server
  • allow using primitive types (instead of wraping counterparts) in reflected classes
  • rework FramsClass? creation process (add FramsClassBuilder?)
  • add more tests

CHANGELOG:
Prepare model.World class.

Minor change.

Use primitive types for Genotype and Creature classes.

Use primitive types in model.Neuro* classes.

Use primitive types in model.Joint* classes.

Use primitive types in model.Part* classes.

Fix primitive values.

Extract FramsClassBuilder?.

Add tests of Model classes.

More fixes.

Refactorize out ParamCandidate?.

Several fixes.

Fix all regressions after introducing annotations.

Use annotations throughout the project.

Add exception classes.

Improve creation of FramsClass?.

More changes.

Many changes regarding annotations.

Annotate classes in com.framsticks.model package.

Remove manual FramsClass? constructor.

Construct FramsClass? for Creature. Add test.

Add default values to the ParamAnnotation?.

Add ParamBuilderTest? and ParamAnnotation?.

Add FramsClassAnnotation?.

File size: 1.8 KB
Line 
1package com.framsticks.model;
2
3import org.testng.annotations.Test;
4
5import com.framsticks.params.FramsClass;
6import com.framsticks.params.FramsClassBuilder;
7import com.framsticks.params.ReflectionAccess;
8import com.framsticks.params.types.ArrayListParam;
9import com.framsticks.params.types.DecimalParam;
10import com.framsticks.params.types.StringParam;
11import com.framsticks.test.TestConfiguration;
12
13import static org.fest.assertions.Assertions.*;
14
15@Test
16public class CreatureTest extends TestConfiguration {
17
18        FramsClass framsClass;
19        ArrayListParam partsParam;
20        ReflectionAccess access;
21        Creature creature;
22
23        @Test
24        public void testFramsClass() {
25                framsClass = FramsClassBuilder.buildForClass(Creature.class);
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);
30                partsParam = framsClass.getParamEntry("parts", ArrayListParam.class);
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
37        @Test
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}
Note: See TracBrowser for help on using the repository browser.