source: java/main/src/test/java/com/framsticks/core/ListChangeTest.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1package com.framsticks.core;
2
3import java.util.Arrays;
4
5import org.testng.annotations.BeforeMethod;
6import org.testng.annotations.Test;
7
8import static com.framsticks.params.AccessOperations.*;
9import com.framsticks.params.FramsClass;
10import com.framsticks.params.ListSink;
11import com.framsticks.params.ListSource;
12import com.framsticks.params.ReflectionAccess;
13import com.framsticks.structure.messages.ListChange;
14import com.framsticks.structure.messages.ListChange.Action;
15import com.framsticks.test.TestConfiguration;
16
17import static org.fest.assertions.Assertions.*;
18
19@Test
20public class ListChangeTest extends TestConfiguration {
21
22        FramsClass framsClass;
23        ReflectionAccess access;
24        ListChange listChange;
25
26        @BeforeMethod
27        public void clearListChange() {
28                listChange = new ListChange();
29        }
30
31        // @Test
32        // public void testEnumBehaviour() {
33        //      for (Action a : Action.class.getEnumConstants()) {
34        //              // assertThat(Integer.class.cast(a)).isEqualTo(a.ordinal());
35        //              assertThat(Action.class.cast(a.ordinal())).isEqualTo(a);
36        //      }
37
38        // }
39
40        @Test
41        public void testFramsClass() {
42                framsClass = FramsClass.build().forClass(ListChange.class);
43                assertThat(framsClass.getParamCount()).isEqualTo(4);
44        }
45
46        @Test(dependsOnMethods = "testFramsClass")
47        public void createReflectionAccess() {
48                access = new ReflectionAccess(ListChange.class, framsClass);
49        }
50
51        @Test(dependsOnMethods = "createReflectionAccess")
52        public void manualAccess() {
53                access.select(listChange);
54
55                access.set("type", 2);
56                assertThat(listChange.action).isEqualTo(Action.Modify);
57
58                listChange.action = Action.Remove;
59                assertThat(access.get("type", Integer.class)).isEqualTo(1);
60        }
61
62        @Test(dependsOnMethods = "createReflectionAccess")
63        public void loading() throws Exception {
64                load(access.select(listChange), ListSource.createFrom("type:2", "pos:0", "id:test"));
65
66                assertThat(listChange.action).isEqualTo(Action.Modify);
67                assertThat(listChange.position).isEqualTo(0);
68                assertThat(listChange.identifier).isEqualTo("test");
69
70                ListSink sink = new ListSink();
71                save(access.select(listChange), sink);
72                assertThat(sink.getOut()).isEqualTo(Arrays.asList("ListChange:", "type:2", "pos:0", "id:test", ""));
73        }
74
75}
Note: See TracBrowser for help on using the repository browser.