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

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

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

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.ReflectionAccess;
7import com.framsticks.params.types.ArrayListParam;
8import com.framsticks.params.types.DecimalParam;
9import com.framsticks.params.types.StringParam;
10import com.framsticks.test.TestConfiguration;
11
12import static org.fest.assertions.Assertions.*;
13
14@Test
15public 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}
Note: See TracBrowser for help on using the repository browser.