1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.krad.uif.component.Component;
21 import org.kuali.rice.krad.uif.element.Label;
22 import org.kuali.rice.krad.uif.element.Message;
23 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
24 import org.kuali.rice.krad.uif.service.ViewHelperService;
25 import org.kuali.rice.krad.uif.util.CopyUtils;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.mockito.Mockito;
28
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertTrue;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
33
34
35
36
37
38
39 public class FieldBaseTest {
40
41 View view = null;
42
43 @Before
44 public void setUp() {
45 view = Mockito.mock(View.class);
46 ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
47 when(view.getViewHelperService()).thenReturn(mockViewHelperService);
48 }
49
50 @Test
51
52
53
54
55
56 public void testRequiredMessageDisplay() throws Exception {
57
58
59
60
61
62
63
64
65 ViewLifecycle.encapsulateLifecycle(view, null, null, new Runnable() {
66 @Override
67 public void run() {
68 Object nullModel = null;
69 Component mockComponent = mock(Component.class);
70
71
72 Label mockLabel = new Label();
73 Message message = new Message();
74 message.setMessageText("*");
75 message.setRender(true);
76
77 FieldBase fieldBase = new FieldBase();
78 fieldBase.setFieldLabel(mockLabel);
79 fieldBase.setRequired(true);
80 fieldBase.setReadOnly(false);
81
82 FieldBase fieldBaseCopy = CopyUtils.copy(fieldBase);
83 fieldBaseCopy.performFinalize(nullModel, mockComponent);
84 assertTrue(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
85
86
87 fieldBaseCopy = CopyUtils.copy(fieldBase);
88 fieldBaseCopy.setReadOnly(true);
89 fieldBaseCopy.performFinalize(nullModel, mockComponent);
90 assertFalse(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
91 }
92 });
93
94 }
95 }