1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.minutefforts.aspects.property.support;
17
18 import static com.minutefforts.test.util.assertion.GoldenMasterFile.goldenMasterFile;
19 import static com.minutefforts.test.util.logging.UnitTestAppender.getDefaultTestAppender;
20 import static org.junit.Assert.assertEquals;
21
22 import org.junit.Before;
23 import org.junit.Test;
24
25 import com.minutefforts.test.util.logging.UnitTestAppender;
26
27
28
29
30
31
32 public class BoundPropertyBeanTest {
33
34 private SampleBoundPropertyBean sampleBoundPropertyBean;
35
36
37
38
39
40 @Test
41 public void boundProperties() {
42
43 PropertyChangeListenerMock generalChangeListener = new PropertyChangeListenerMock();
44 ((BoundPropertyObservable) this.sampleBoundPropertyBean).addPropertyChangeListener(generalChangeListener);
45
46 PropertyChangeListenerMock descriptionChangeListener = new PropertyChangeListenerMock();
47 ((BoundPropertyObservable) this.sampleBoundPropertyBean).addPropertyChangeListener("Description",
48 descriptionChangeListener);
49
50 this.sampleBoundPropertyBean.setId(99);
51 this.sampleBoundPropertyBean.setId(100);
52
53 this.sampleBoundPropertyBean.setAmount(10f);
54 assertEquals(this.sampleBoundPropertyBean.getAmount(), 10f);
55
56 this.sampleBoundPropertyBean.setDescription("Some arbitrary text.");
57 this.sampleBoundPropertyBean.setDescription("And another text.");
58
59 this.sampleBoundPropertyBean.setInternalValue("Setting this property must be ignored!");
60
61 this.sampleBoundPropertyBean.setValid(true);
62 this.sampleBoundPropertyBean.setIsSomeFlag(true);
63
64
65 assertEquals("Id: -1 => 99\n"
66 + "Id: 99 => 100\n"
67 + "Amount: null => 10.0\n"
68 + "Description: => Some arbitrary text.\n"
69 + "Description: Some arbitrary text. => And another text.\n"
70 + "Valid: false => true\n"
71 + "IsSomeFlag: false => true\n",
72 generalChangeListener.resultLog);
73 assertEquals("Description: => Some arbitrary text.\n"
74 + "Description: Some arbitrary text. => And another text.\n",
75 descriptionChangeListener.resultLog);
76
77
78 assertEquals(
79 goldenMasterFile(this, "GoldenMaster-logBoundProperties.txt"),
80 UnitTestAppender.getDefaultTestAppender().getLogAsString());
81
82
83 System.out.println(UnitTestAppender.getDefaultTestAppender().getLogAsString());
84 }
85
86
87
88
89
90 @Before
91 public void setUp() {
92
93
94 getDefaultTestAppender().clear();
95
96 this.sampleBoundPropertyBean = new SampleBoundPropertyBean();
97 }
98 }