1 | package com.framsticks.core; |
---|
2 | |
---|
3 | import org.testng.annotations.BeforeMethod; |
---|
4 | import org.testng.annotations.Test; |
---|
5 | |
---|
6 | import com.framsticks.core.ListChange.Action; |
---|
7 | import com.framsticks.params.FramsClass; |
---|
8 | import com.framsticks.params.ListSource; |
---|
9 | import com.framsticks.params.ReflectionAccess; |
---|
10 | import com.framsticks.test.TestConfiguration; |
---|
11 | |
---|
12 | import static org.fest.assertions.Assertions.*; |
---|
13 | |
---|
14 | @Test |
---|
15 | public class ListChangeTest extends TestConfiguration { |
---|
16 | |
---|
17 | FramsClass framsClass; |
---|
18 | ReflectionAccess access; |
---|
19 | ListChange listChange; |
---|
20 | |
---|
21 | @BeforeMethod |
---|
22 | public void clearListChange() { |
---|
23 | listChange = new ListChange(); |
---|
24 | } |
---|
25 | |
---|
26 | // @Test |
---|
27 | // public void testEnumBehaviour() { |
---|
28 | // for (Action a : Action.class.getEnumConstants()) { |
---|
29 | // // assertThat(Integer.class.cast(a)).isEqualTo(a.ordinal()); |
---|
30 | // assertThat(Action.class.cast(a.ordinal())).isEqualTo(a); |
---|
31 | // } |
---|
32 | |
---|
33 | // } |
---|
34 | |
---|
35 | @Test |
---|
36 | public void testFramsClass() { |
---|
37 | framsClass = FramsClass.build().forClass(ListChange.class); |
---|
38 | assertThat(framsClass.getParamCount()).isEqualTo(3); |
---|
39 | } |
---|
40 | |
---|
41 | @Test(dependsOnMethods = "testFramsClass") |
---|
42 | public void createReflectionAccess() { |
---|
43 | access = new ReflectionAccess(ListChange.class, framsClass); |
---|
44 | } |
---|
45 | |
---|
46 | @Test(dependsOnMethods = "createReflectionAccess") |
---|
47 | public void manualAccess() { |
---|
48 | access.select(listChange); |
---|
49 | |
---|
50 | access.set("type", 2); |
---|
51 | assertThat(listChange.action).isEqualTo(Action.Modify); |
---|
52 | |
---|
53 | listChange.action = Action.Remove; |
---|
54 | assertThat(access.get("type", Integer.class)).isEqualTo(1); |
---|
55 | } |
---|
56 | |
---|
57 | @Test(dependsOnMethods = "createReflectionAccess") |
---|
58 | public void load() throws Exception { |
---|
59 | access.select(listChange).load(ListSource.createFrom("type:2", "pos:5", "id:test")); |
---|
60 | |
---|
61 | assertThat(listChange.action).isEqualTo(Action.Modify); |
---|
62 | assertThat(listChange.position).isEqualTo(5); |
---|
63 | assertThat(listChange.identifier).isEqualTo("test"); |
---|
64 | } |
---|
65 | |
---|
66 | } |
---|